Replace manual unit conversions to consistently use `ud_convert()` helper function
Context
Some functions have inconsistent unit conversion practices. Some parts use the standardized PEcAn.utils::ud_convert() helper function from base/utils/R/ud_convert.R, while others perform manual arithmetic conversions. This creates maintenance burden and increases risk of conversion errors.
Example
Model configuration files (write.configs.*) and output processing files (model2netcdf.*) contain numerous manual unit conversions using arithmetic operations instead of the standardized ud_convert() helper function.
Common patterns include: time: * 86400, / 365, * 3600 (seconds/day, days/year, seconds/hour) mass: * 1000, * 0.001 (g <--> kg, mm <--> m) energy: * 1000 (kJ <--> J) area: * 10000 (m2 <--> ha)
Scope
Focus on dimensional unit conversions only. Do NOT force conversions that involve:
- Biological/stoichiometric constants (e.g. * 0.48 for carbon fraction, * 2 for C to biomass)
- Model-specific scaling (e.g. plot area conversions, model calendar conventions)
- Physical constants mixed with unit conversions
Tasks
- [ ] Audit files for manual unit conversion patterns
- [ ] Replace with
PEcAn.utils::ud_convert()where applicable - [ ] Document when manual conversions are kept; means conversions that CANNOT use
ud_convert()(biological constants, model conventions)
Some of the key files:
- models/sipnet/R/model2netcdf.SIPNET.R - multiple conversions with * 0.001, / 86400
- models/dalec/R/model2netcdf.DALEC.R - carbon flux conversions * 0.001 / timestep.s
models/*/R/met2model.*.R- time conversions with 86400 throughoutmodels/*/R/write.configs.*.R- various model configuration conversions
Hi @divine7022 i would like to work on this issue please asssign it to me if possible thanks !!
Thanks for your interest @ayushman1210! You are welcome to pick this up