pecan icon indicating copy to clipboard operation
pecan copied to clipboard

Replace manual unit conversions to consistently use `ud_convert()` helper function

Open divine7022 opened this issue 2 weeks ago • 2 comments

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 throughout
  • models/*/R/write.configs.*.R - various model configuration conversions

divine7022 avatar Dec 08 '25 13:12 divine7022

Hi @divine7022 i would like to work on this issue please asssign it to me if possible thanks !!

ayushman1210 avatar Dec 08 '25 19:12 ayushman1210

Thanks for your interest @ayushman1210! You are welcome to pick this up

divine7022 avatar Dec 08 '25 19:12 divine7022