Skip to content

Comments

unit conversion error changes#52

Merged
cmaynard-ngwpc merged 1 commit intodevelopmentfrom
Unit_Conversion_Mohammed_dev
Sep 29, 2025
Merged

unit conversion error changes#52
cmaynard-ngwpc merged 1 commit intodevelopmentfrom
Unit_Conversion_Mohammed_dev

Conversation

@mkarim-rtx
Copy link

@mkarim-rtx mkarim-rtx commented Sep 26, 2025

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

@cmaynard-ngwpc cmaynard-ngwpc merged commit bc05269 into development Sep 29, 2025
9 of 10 checks passed
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(),"");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace got messed up here. This was fixed in #40, but this branch apparently was a cherry-pick rather than a rebase?

@cmaynard-ngwpc cmaynard-ngwpc deleted the Unit_Conversion_Mohammed_dev branch September 30, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants