Skip to content

Align ocean CMOR output with published reference (vertices, time_bnds, lev axis)#465

Open
rhaegar325 wants to merge 6 commits into
mainfrom
fix_attrs_and_coordinates_mismatch_in_ocean_variables
Open

Align ocean CMOR output with published reference (vertices, time_bnds, lev axis)#465
rhaegar325 wants to merge 6 commits into
mainfrom
fix_attrs_and_coordinates_mismatch_in_ocean_variables

Conversation

@rhaegar325

Copy link
Copy Markdown
Collaborator

Overview

Four small write-time fixes in Ocean_CMORiser.update_attributes bring the CMORised ocean
output in line with the published CMIP6 reference file and clear the corresponding CF / WCRP
compliance-checker findings. Verified by re-running the WCRP cf:1.7 + wcrp_cmip6:1.0
checker on both the produced file and the published reference.

Scope: only the findings that the compliance-checker actually reports are addressed.
Differences from the reference that the checker does not flag (missing lev_bnds,
vertices_* fill values, the rest of the lev metadata) are intentionally left untouched.

Changes — src/access_moppy/ocean.py

All in Ocean_CMORiser.update_attributes.

1. vertices_latitude / vertices_longitude — drop standard_name

# before
self.ds["vertices_latitude"].attrs.update(
    {"standard_name": "latitude", "units": "degrees_north"}
)
self.ds["vertices_longitude"].attrs.update(
    {"standard_name": "longitude", "units": "degrees_east"}
)
# after — keep only units (CF §7.1; matches the published reference)
self.ds["vertices_latitude"].attrs.update({"units": "degrees_north"})
self.ds["vertices_longitude"].attrs.update({"units": "degrees_east"})

2–4. Three guarded blocks added after the existing bnds drop

# Keep `vertices` as a pure dimension (no int64 coordinate variable).
if "vertices" in self.ds.coords:
    self.ds = self.ds.drop_vars("vertices")

# Bounds variables inherit units/calendar from their parent (CF §7.1).
if "time_bnds" in self.ds:
    self.ds["time_bnds"].attrs = {}

# The vertical coordinate needs a CF axis attribute (WCRP ATTR001).
if "lev" in self.ds.coords:
    self.ds["lev"].attrs["axis"] = "Z"

Findings cleared

Change Compliance finding cleared
drop standard_name from vertices_* CF §7.1 (standard_name on bounds)
drop vertices coordinate CF §2.2 (vertices int64) + CF §3.3 (no name)
empty time_bnds attrs CF §7.1 (time_bnds units/calendar/long_name)
set lev:axis = 'Z' WCRP [ATTR001] (lev missing axis)

Verification

End-to-end on real ESM1-5 ocean output (Oyr.no3):

vertices in coords : False   (pure dimension)
time_bnds.attrs    : {}
vertices_latitude  : {'units': 'degrees_north'}
lev.attrs['axis']  : 'Z'

Compliance-checker, produced file vs published reference:

  • The four targeted findings (vertices int64, time_bnds attrs, lev:axis) are gone.
  • The residual vertices_* findings (“should define standard_name…”, CF §7.1 units) are
    also present on the official published file — checker over-strictness that applies to
    the gold-standard CMIP6 file too, so it cannot be cleared without diverging from the
    reference. The produced file is in fact slightly cleaner: its vertices_* §7.1 list is
    ['units'] vs the published ['units', 'missing_value', '_FillValue'].

Tests — tests/unit/test_ocean.py

Added to TestUpdateAttributes (all 4 new lines of executable code are covered):

  • test_vertices_is_pure_dimension_not_coordinate
  • test_time_bnds_has_no_attributes
  • test_vertices_bounds_have_no_standard_name
  • test_lev_gets_cf_axis

tests/unit/test_ocean.py: 47 passed.

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.77419% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.2%. Comparing base (7142b03) to head (b8612e1).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/access_moppy/ocean.py 87.5% 0 Missing and 1 partial ⚠️
src/access_moppy/utilities.py 97.2% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #465     +/-   ##
=======================================
+ Coverage   76.9%   77.2%   +0.3%     
=======================================
  Files         31      31             
  Lines       5974    6030     +56     
  Branches    1107    1122     +15     
=======================================
+ Hits        4594    4653     +59     
+ Misses      1131    1126      -5     
- Partials     249     251      +2     
Flag Coverage Δ
unit 77.2% <96.8%> (+0.3%) ⬆️

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.

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.

1 participant