Skip to content

Conversation

@rhaegar325
Copy link
Collaborator

@rhaegar325 rhaegar325 commented Jan 20, 2026

Fix: Properly handle string coordinates with CF-compliant encoding

Summary

This PR fixes the incorrect handling of string/character coordinates during NetCDF file writing. String coordinates (e.g., type in land variables) are now written with proper CF-compliant encoding and remain as coordinates rather than being converted to data variables.

Problem

The current write() method incorrectly handles string coordinates:

  1. Coordinates become variables: String coordinates like type are written as data variables instead of remaining in ds.coords
  2. Wrong dtype: String dtype changes from |S11 (byte string) to <U11 (Unicode), which is not CMIP6 compliant
  3. Missing CF compliance: String coordinates are not encoded using the CF-standard character array format (S1 + strlen dimension)

Impact: Land variables with type coordinate (e.g., baresoilFrac, grassFrac, treeFrac) produce non-compliant CMIP6 output files.

#166 #172 solved

@rhaegar325 rhaegar325 requested a review from rbeucher January 23, 2026 00:32
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.52%. Comparing base (1bc3063) to head (48d17bf).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/access_moppy/base.py 90.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #174      +/-   ##
==========================================
+ Coverage   60.60%   62.52%   +1.91%     
==========================================
  Files          18       19       +1     
  Lines        2848     2959     +111     
==========================================
+ Hits         1726     1850     +124     
+ Misses       1122     1109      -13     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Member

@rbeucher rbeucher left a comment

Choose a reason for hiding this comment

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

Tested with baresoilFrac. Works fine. Should we have some simple tests?

@rhaegar325
Copy link
Collaborator Author

Hi, @rbeucher, after some test and fix, this pr is ready to be merged

@rbeucher rbeucher merged commit 3808bd9 into main Jan 28, 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.

3 participants