Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iris writes non-CF-compliant polar stereographic netCDF files (wrongly named grid mapping attribute) #5238

Open
TonyP-BAS opened this issue Apr 5, 2023 · 2 comments
Labels
Good First Issue A good issue to take on if you're just getting started with Iris development Type: Bug

Comments

@TonyP-BAS
Copy link

🐛 Bug Report

When loading a polar stereographic netCDF file, Iris correctly interprets the "standard_parallel" attribute of the polar stereographic grid mapping variable, storing this in the "true_scale_lat" attribute of the PolarStereographic coordinate system (line 456 of iris/fileformats/_nc_load_rules/helpers.py).

But when saving such a cube to netCDF, Iris writes this value to an attribute of the grid mapping variable called "true_scale_lat", not "standard_parallel", as required by the CF convention (https://cfconventions.org/Data/cf-conventions/cf-conventions-1.10/cf-conventions.html#polar-stereographic).

This looks to be a defect in line 2150 of iris/fileformats/netcdf/saver.py, which reads:

                    cf_var_grid.true_scale_lat = cs.true_scale_lat

Where I would have expected:

                    cf_var_grid.standard_parallel = cs.true_scale_lat

The consequence is that the netCDF written by Iris is not CF-compliant, and cannot even be read back correctly by Iris due to the lack of the required "standard_parallel" or "scale_factor_at_projection_origin" grid mapping attributes, meaning that the cube ends up lacking horizontal coordinates or a coordinate system.

Happy to provide example data file and code to reproduce the bug, or any other information that might be useful.

Environment

  • Iris Version: 3.3 or later (i.e. one with polar stereographic support)
@pp-mo
Copy link
Member

pp-mo commented Apr 6, 2023

Thanks @TonyP-BAS
I don't know how it slipped through exactly, but clearly you are right.
From the recently-added coverage scan, these lines are not exercised by any tests whatever, so no wonder.
( I would link, but it seems the CodeCov site is currently down ☹️ )

Do you feel able to submit a PR for this yourself ?
I think the code change is probably just as simple as you suggest, but we should definitely add a test.
The simplest I can think of is an integration test to check that Iris can save and re-load one of these and retrieve a coord-system with all the same parameters.
Obviously, it's a shame that tests don't exist for other coord-system types ... but I don't think there is any obligation to fix that here+now.

@pp-mo
Copy link
Member

pp-mo commented Apr 6, 2023

I don't know how it slipped through

But it appears that I merged it #4773.
😳

@ESadek-MO ESadek-MO added the Good First Issue A good issue to take on if you're just getting started with Iris development label Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue A good issue to take on if you're just getting started with Iris development Type: Bug
Projects
Status: No status
Development

No branches or pull requests

3 participants