fix: validate values that could cause divide by 0#54
fix: validate values that could cause divide by 0#54hellkite500 merged 4 commits intoNOAA-OWP:masterfrom
Conversation
aaraney
left a comment
There was a problem hiding this comment.
One comment to look at but i'll go ahead and approve this. Thanks, @hellkite500!
src/pet.c
Outdated
| if (model->pet_params.wind_speed_measurement_height_m <= model->pet_params.zero_plane_displacement_height_m){ | ||
| // Must be <=, if == then log(1)=0 and divide by 0 occurs | ||
| fprintf(stderr, "ERROR: wind_speed_measurement_height_m must be > zero_plane_displacement_height_m. Current values: %lf and %lf\n", | ||
| model->pet_params.wind_speed_measurement_height_m, | ||
| model->pet_params.zero_plane_displacement_height_m); | ||
| exit(EXIT_FAILURE); | ||
| } |
There was a problem hiding this comment.
I think this needs to be removed. If we look at
zm=wind_speed_measurement_height_m; // is set to 2 m
zh=humidity_measurement_height_m; // is set to 2 m
d= zero_plane_displacement_height_m; // = d = 2/3 * veg_height
Technically, d can be greater than 2.0 for most of the case, if that happens, it is reset based on zh (below)
if (d >= zh) {
d = 2.0/3.0 * zh;
}
so (zm-d) will always be positive, and so is (zh-d) in the log terms of Ra
let's talk about it if you believe I am missing something
|
I have relaxed the strict displacement and measurement height checks, and instead implemented the assumption that when This check also would have caused a failure that was indirectly accounted for in at least one method where humidity measurement height was used to compute a new displacement and transform, so the |
Closes #52 by validating several config and/or forcing values which could lead to divide by zero situations.
Changes
Prints to stderr and exists in most cases, but a default small wind_speed is used with a warning printed instead of a hard stop.
PR has an informative and human-readable title
Changes are limited to a single goal (no scope creep)
Code can be automatically merged (no conflicts)
Code follows project standards (link if applicable)
Passes all existing automated tests
Any change in functionality is tested
New functions are documented (with a description, list of inputs, and expected output)
Placeholder code is flagged / future todos are captured in comments
Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
Reviewers requested with the Reviewers tool ➡️