Skip to content

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

@divine7022

Description

@divine7022

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions