Skip to content

Check quantity units in match() - #716

Open
ecomodeller wants to merge 2 commits into
mainfrom
fix-quantity-is-compatible
Open

ecomodeller wants to merge 2 commits into
mainfrom
fix-quantity-is-compatible

Conversation

@ecomodeller

@ecomodeller ecomodeller commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Closes #697.

Impact

Existing match() calls behave exactly as before. The new unit check is off by default.

What changes for users:

  1. New opt-in check in match(). check_quantity="error" raises when a model result's unit differs from the observation's. The default is "ignore": units are compared exactly, and CF unit strings (e.g. ERA5 "Degree true") never equal mikeio's ("degree"), so a strict default would reject ordinary netCDF-vs-MIKE comparisons.

  2. Quantity.is_compatible returns different results. It compares units only, as written; names are ignored. An empty, "undefined" or "Undefined" unit is compatible with anything.

    before after
    Quantity("Water Level", "m") vs Quantity("Surface Elevation", "m") False True
    Quantity("Water Level", "m") vs Quantity.undefined() False True
    Quantity("Water Level", "m") vs Quantity("Water Level", "meter") False False
    Quantity("Undefined", "m") vs Quantity("Discharge", "m^3/s") True False

    Names are not compared because the same quantity is named differently on the two sides; a name check rejected 36 matches in the existing test suite, all of them this case. Nothing in modelskill called is_compatible before this PR.

  3. Quantity.from_mikeio_eum_name returns short unit names, the form from_mikeio_iteminfo already uses: "m" instead of "meter", "m^3/s" instead of "meter_pow_3_per_sec". Code that compares against the old strings will need updating.

🤖 Generated with Claude Code

Quantity.is_compatible now compares units only, as written. Names differ
for the same quantity ("Water Level" vs "Surface Elevation"), so they are
not compared. An empty, "undefined" or "Undefined" unit is compatible
with anything.

match() raises when a model result's unit differs from the observation's,
unless check_quantity="ignore".

Quantity.from_mikeio_eum_name stores the unit's short name ("m"), the
same form from_mikeio_iteminfo already uses, so both constructors agree.

Closes #697
Unit strings from CF netCDF (e.g. ERA5 'Degree true') never equal the
mikeio short names, so a strict default rejected ordinary netCDF-vs-MIKE
comparisons.

This branch has not been deployed

No deployments
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.

Quantity.is_compatible reports undefined quantities as incompatible

1 participant