Skip to content

Route ocean variables in mixed tables to the ocean CMORiser - #795

Merged
rhaegar325 merged 2 commits into
mainfrom
fix-emon-ocean-routing
Oct 30, 2026
Merged

rhaegar325 merged 2 commits into
mainfrom
fix-emon-ocean-routing

Conversation

@rhaegar325

Copy link
Copy Markdown
Collaborator

Closes #794

Problem

The driver chose the component CMORiser from the CMIP6 table name alone. Emon, Eday, 3hr and the other mixed tables always went to Atmosphere_CMORiser.

Ocean variables in these tables (Emon.expcalc, Emon.osaltpsmadvect, Eday.mlotst, 3hr.tos, ...) therefore failed with KeyError: 'lev'. In CMIP7 they would also have been given the atmosphere grid label and cell measures.

Changes

  • utilities.py: add load_variable_component(cmor_name, model_id). It returns the mapping component ("ocean", "oceanBgchem", ...) of the entry that load_variable_entry returns.
    • Both functions now share one search, _find_variable_entry, so they always agree.
    • load_variable_entry behaves as before.
  • driver.py:
    • A variable in an atmosphere-routed table whose entry is under ocean or oceanBgchem now goes to Ocean_CMORiser_OM2 or Ocean_CMORiser_OM3.
    • _is_atmos is false for these variables, so the atmosphere grid label and cell-measures overrides are not applied. The ocean CMORiser resolves its own after infer_grid_type().
    • The routing block now reuses _is_atmos instead of repeating the atmosphere table list.
  • Tests (tests/unit/test_driver.py):
    • test_mixed_table_routes_by_mapping_component checks which CMORiser is chosen:
      • Emon.expcalc (ESM1-6), Emon.osaltpsmadvect (ESM1-5), Eday.mlotst (ESM1-6) and 3hr.tos (ESM1-6) → OM2;
      • Eday.mlotst (OM3) → OM3;
      • Emon.rls (ESM1-6) → still atmosphere.
    • test_cmip7_ocean_variable_in_mixed_table_skips_atmosphere_grid_label checks that the CMIP7 grid label stays as the g999 placeholder for the ocean CMORiser to resolve.

The approach relies on no variable name being in more than one mapping component. That holds today for ESM1-5, ESM1-6, CM3 and OM3.

Validation

  • On main, the 6 new ocean-routing tests fail and the atmosphere case passes.
  • With this change, test_driver.py and test_utilities.py pass (267 tests), and pre-commit is clean.
  • Real data: ESM1-6 piControl year 101, CMIP7, ocnBgchem.expcalc.tavg-ol-hxy-sea.mon.glb. This variable failed with KeyError: 'lev' in the moppy 1.8.4 pilot.
    • The job completes in about 1 minute with 2.6 GB peak memory.
    • The output has dimensions time × lev=50 × j=300 × i=360 and grid label g118 (ocean T point).
    • cell_measures is area: areacello volume: volcello.
    • The compliance check (cf:1.11 + wcrp_cmip7:1.0) passes, as do the QC range check and cmip7repack.

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.2%. Comparing base (e0f7be5) to head (4430957).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #795   +/-   ##
=====================================
  Coverage   81.2%   81.2%           
=====================================
  Files         44      44           
  Lines       9565    9576   +11     
  Branches    1779    1782    +3     
=====================================
+ Hits        7767    7780   +13     
+ Misses      1469    1468    -1     
+ Partials     329     328    -1     
Flag Coverage Δ
unit 81.2% <100.0%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rhaegar325
rhaegar325 merged commit f3601a6 into main Oct 30, 2026
4 checks passed
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.

[BUG] Ocean variables in Emon/Eday/3hr are sent to the atmosphere CMORiser and fail with KeyError: 'lev'

1 participant