unit conversion error changes#52
Merged
cmaynard-ngwpc merged 1 commit intodevelopmentfrom Sep 29, 2025
Merged
Conversation
PhilMiller
reviewed
Sep 29, 2025
| auto const& nested_module = data_provider_iter->second; | ||
| long nested_module_time = nested_module->get_data_start_time() + ( this->get_model_current_time() - this->get_model_start_time() ); | ||
| auto selector = CatchmentAggrDataSelector(this->get_catchment_id(),var_name,nested_module_time,this->record_duration(),"1"); | ||
| auto selector = CatchmentAggrDataSelector(this->get_catchment_id(),var_name,nested_module_time,this->record_duration(),""); |
There was a problem hiding this comment.
Whitespace got messed up here. This was fixed in #40, but this branch apparently was a cherry-pick rather than a rebase?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The UDUNITS package can’t parse "none", which caused warnings like “Unable to parse out_units value none.” Normalizing to "1" matches ngen's convention and avoids spurious conversion errors. This ensures variables defined with “no-units” in realization metadata are recorded as dimensionless from the start, preventing downstream unit-conversion attempts and warnings.
Changes
Bmi_Module_Formulation::get_value / get_values:
Switched the throw site to data_access::unit_conversion_exception and populated it with the producer’s model name, BMI variable name, native units, and the unconverted value(s).
Why: lets upstream callers (and logs) precisely identify the producer/consumer pair that disagrees on units.
Bmi_Module_Formulation::set_model_inputs_prior_to_update:
Wrapped provider calls in a catch (data_access::unit_conversion_exception&), log a single descriptive warning including consumer (requester) details and producer details, then use the unconverted value to avoid aborting the run.
Why: avoids hard failures while still surfacing exactly what needs fixing.
De-duplicated warnings (shared set in data_access)
Used data_access::unit_errors_reported to ensure each unique {requester, variable, provider, variable, message} is logged once.
Why: prevents log spam across timesteps/nodes.
UnitsHelper.cpp:
Treated "", "none", "unitless", "dimensionless", "-" as dimensionless "1" and short-circuited conversions when either side is effectively "1" or when in/out match (including case/spacing).
Why: eliminates spurious “Unable to parse … none” and “mm → 1” attempts that UDUNITS can’t (and shouldn’t) do.
Bmi_Multi_Formulation get_var_value_as_double (where present)
Catch data_access::unit_conversion_exception, log once that output is emitted without conversion, and return the unconverted value.
Why: multi-module outputs shouldn’t crash the run; this keeps results flowing while highlighting misconfigured units.
Net effect:
“none”/empty units no longer trigger parser warnings.
We don’t attempt impossible conversions (e.g., m ↔ 1).
When a producer/consumer truly disagree (science/metadata issue), the log clearly names both sides and execution continues with unconverted data so you can fix the source units (e.g., adjust SLOTH/SMP/SFT or realization JSON) rather than chase generic warnings.
Testing
Ngen run shows results as expected