-
Notifications
You must be signed in to change notification settings - Fork 287
Replace manual unit conversions with ud_convert() for consistency across models #3719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
infotroph
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Can you describe how you tested these changes? I ask because I see a few issues here that should have produced obvious error messages in a test run. The issues themselves are minor and will be easy to fix, but since unit conversions can be surprisingly tricky it's important to know at review time that someone has actually run the code and looked at its output.
|
hi @infotroph Thanks for the review and for pointing this out.
Thanks for the reminder !! |
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
|
Hi @infotroph |
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
|
hey @infotroph sorry for the late response i have exams and college related work. |
models/gday/R/model2netcdf.GDAY.R
Outdated
| # GDAY outputs in Mg/ha/year, convert directly to kgC/m2/s (ud_convert returns per-second) | ||
| output[[1]] <- PEcAn.utils::ud_convert(sub.GDAY.output[, "auto_resp"], "Mg/ha/yr", "kg/m2/s") | ||
| output[[2]] <- PEcAn.utils::ud_convert(sub.GDAY.output[, "hetero_resp"], "Mg/ha/yr", "kg/m2/s") | ||
| output[[3]] <- PEcAn.utils::ud_convert(sub.GDAY.output[, "auto_resp"] + sub.GDAY.output[, "hetero_resp"], "Mg/ha/yr", "kg/m2/s") | ||
| output[[4]] <- PEcAn.utils::ud_convert(sub.GDAY.output[, "gpp"], "Mg/ha/yr", "kg/m2/s") | ||
| output[[5]] <- PEcAn.utils::ud_convert(sub.GDAY.output[, "nep"] * -1, "Mg/ha/yr", "kg/m2/s") | ||
| output[[6]] <- PEcAn.utils::ud_convert(sub.GDAY.output[, "npp"], "Mg/ha/yr", "kg/m2/s") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing code here is using a timestep.s of 86400 (and not the 86400/out_day used in model2netcdf.SIPNET below), so I'm pretty sure these should all be converting from Mg/ha/day rather than Mg/ha/yr. Sorry I didn't catch this on my last review!
I recommend constructing a test to make sure the outputs are identical before and after these unit changes -- consider checking it with a subset of the example output in https://github.com/mdekauwe/GDAY/blob/master/example/outputs/D1GDAYDUKEAMB.csv
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
Co-authored-by: Chris Black <[email protected]>
Description
This PR standardizes dimensional unit conversions by replacing manual arithmetic with the centralized helper function PEcAn.utils::ud_convert() where appropriate. This reduces maintenance burden, improves readability, and minimizes the risk of unit conversion errors.
The changes focus strictly on dimensional unit conversions (mass, time, energy, area) and intentionally exclude model-specific scaling, biological constants, and timestep-dependent logic, per project guidance.
Summary of Changes
NOT CHANGED
Fixes - #3712