Skip to content

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

@TonyP-BAS

Description

@TonyP-BAS

🐛 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueA good issue to take on if you're just getting started with Iris developmentType: Bug

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions