Skip to content

Commit d1d77aa

Browse files
Save crs_wkt on netCDF save, take 2 (#6519)
* Save crs_wkt, and update test outputs * Extra test fixes * What's new * Update tests. * What's New updates. * Correct use of mocking. --------- Co-authored-by: Will Benfold <[email protected]>
1 parent 3fe8169 commit d1d77aa

File tree

58 files changed

+229
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+229
-9
lines changed

docs/src/whatsnew/latest.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ This document explains the changes made to Iris for this release
3939
converted to :class:`~iris.coords.AuxCoord` if it is masked - the mask is
4040
now preserved when it was not previously.
4141

42+
#. `@wjbenfold`_ and `@trexfeathers`_ added ``crs_wkt`` to the attributes when
43+
saving a :class:`~iris.coord_systems.CoordSystem` to a NetCDF file. Note that
44+
``crs_wkt`` is considered *supplementary* by the CF conventions, with
45+
``grid_mapping`` being the primary source of information, and ``crs_wkt`` not
46+
expected to contain conflicting information. Because of this, Iris generates
47+
:class:`~iris.coord_systems.CoordSystem` exclusively from ``grid_mapping``
48+
when loading, and writes a fresh ``crs_wkt`` whenever a
49+
:class:`~iris.coord_systems.CoordSystem` is saved. If your use case goes
50+
beyond the CF conventions, you can modify the save and load process for your
51+
needs by using the `Ncdata`_ package.
52+
See `CRS WKT in the CF Conventions`_ for more. (:issue:`3796`, :pull:`6519`)
53+
4254

4355
🐛 Bugs Fixed
4456
=============
@@ -105,3 +117,6 @@ This document explains the changes made to Iris for this release
105117
106118
.. comment
107119
Whatsnew resources in alphabetical order:
120+
121+
.. _CRS WKT in the CF Conventions: https://cfconventions.org/Data/cf-conventions/cf-conventions-1.12/cf-conventions.html#use-of-the-crs-well-known-text-format
122+
.. _Ncdata: https://github.com/pp-mo/ncdata

lib/iris/fileformats/netcdf/saver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,8 @@ def add_ellipsoid(ellipsoid):
20812081
category=iris.warnings.IrisSaveWarning,
20822082
)
20832083

2084+
cf_var_grid.crs_wkt = cs.as_cartopy_crs().to_wkt()
2085+
20842086
self._coord_systems.append(cs)
20852087

20862088
# Refer to grid var

lib/iris/tests/results/integration/netcdf/aux_factories/TestAtmosphereSigma/save.cdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ variables:
1717
rotated_latitude_longitude:grid_north_pole_latitude = 37.5 ;
1818
rotated_latitude_longitude:grid_north_pole_longitude = 177.5 ;
1919
rotated_latitude_longitude:north_pole_grid_longitude = 0. ;
20+
rotated_latitude_longitude:crs_wkt = "GEOGCRS[\"unnamed\",BASEGEOGCRS[\"unknown\",DATUM[\"unknown\",ELLIPSOID[\"unknown\",6371229,0,LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8901]]],DERIVINGCONVERSION[\"unknown\",METHOD[\"PROJ ob_tran o_proj=latlon\"],PARAMETER[\"o_lon_p\",0,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],PARAMETER[\"o_lat_p\",37.5,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],PARAMETER[\"lon_0\",357.5,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]],CS[ellipsoidal,2],AXIS[\"longitude\",east,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],AXIS[\"latitude\",north,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]]" ;
2021
double time(time) ;
2122
time:axis = "T" ;
2223
time:units = "hours since 1970-01-01 00:00:00" ;

lib/iris/tests/results/integration/netcdf/aux_factories/TestHybridPressure/save.cdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ variables:
1717
rotated_latitude_longitude:grid_north_pole_latitude = 37.5 ;
1818
rotated_latitude_longitude:grid_north_pole_longitude = 177.5 ;
1919
rotated_latitude_longitude:north_pole_grid_longitude = 0. ;
20+
rotated_latitude_longitude:crs_wkt = "GEOGCRS[\"unnamed\",BASEGEOGCRS[\"unknown\",DATUM[\"unknown\",ELLIPSOID[\"unknown\",6371229,0,LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8901]]],DERIVINGCONVERSION[\"unknown\",METHOD[\"PROJ ob_tran o_proj=latlon\"],PARAMETER[\"o_lon_p\",0,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],PARAMETER[\"o_lat_p\",37.5,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],PARAMETER[\"lon_0\",357.5,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]],CS[ellipsoidal,2],AXIS[\"longitude\",east,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],AXIS[\"latitude\",north,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]]" ;
2021
double time(time) ;
2122
time:axis = "T" ;
2223
time:units = "hours since 1970-01-01 00:00:00" ;

lib/iris/tests/results/integration/netcdf/aux_factories/TestSaveMultipleAuxFactories/hybrid_height_and_pressure.cdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ variables:
1717
rotated_latitude_longitude:grid_north_pole_latitude = 37.5 ;
1818
rotated_latitude_longitude:grid_north_pole_longitude = 177.5 ;
1919
rotated_latitude_longitude:north_pole_grid_longitude = 0. ;
20+
rotated_latitude_longitude:crs_wkt = "GEOGCRS[\"unnamed\",BASEGEOGCRS[\"unknown\",DATUM[\"unknown\",ELLIPSOID[\"unknown\",6371229,0,LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8901]]],DERIVINGCONVERSION[\"unknown\",METHOD[\"PROJ ob_tran o_proj=latlon\"],PARAMETER[\"o_lon_p\",0,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],PARAMETER[\"o_lat_p\",37.5,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],PARAMETER[\"lon_0\",357.5,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]],CS[ellipsoidal,2],AXIS[\"longitude\",east,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],AXIS[\"latitude\",north,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]]" ;
2021
double time(time) ;
2122
time:axis = "T" ;
2223
time:units = "hours since 1970-01-01 00:00:00" ;

lib/iris/tests/results/integration/netcdf/general/TestPackedData/multi_packed_multi_dtype.cdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ variables:
1717
latitude_longitude:grid_mapping_name = "latitude_longitude" ;
1818
latitude_longitude:longitude_of_prime_meridian = 0. ;
1919
latitude_longitude:earth_radius = 6371229. ;
20+
latitude_longitude:crs_wkt = "GEOGCRS[\"unknown\",DATUM[\"unknown\",ELLIPSOID[\"unknown\",6371229,0,LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8901]],CS[ellipsoidal,2],AXIS[\"longitude\",east,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],AXIS[\"latitude\",north,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]]" ;
2021
double time(time) ;
2122
time:axis = "T" ;
2223
time:bounds = "time_bnds" ;

lib/iris/tests/results/integration/netcdf/general/TestPackedData/multi_packed_single_dtype.cdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ variables:
1717
latitude_longitude:grid_mapping_name = "latitude_longitude" ;
1818
latitude_longitude:longitude_of_prime_meridian = 0. ;
1919
latitude_longitude:earth_radius = 6371229. ;
20+
latitude_longitude:crs_wkt = "GEOGCRS[\"unknown\",DATUM[\"unknown\",ELLIPSOID[\"unknown\",6371229,0,LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8901]],CS[ellipsoidal,2],AXIS[\"longitude\",east,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],AXIS[\"latitude\",north,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]]" ;
2021
double time(time) ;
2122
time:axis = "T" ;
2223
time:bounds = "time_bnds" ;

lib/iris/tests/results/integration/netcdf/general/TestPackedData/single_packed_manual.cdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ variables:
1616
latitude_longitude:grid_mapping_name = "latitude_longitude" ;
1717
latitude_longitude:longitude_of_prime_meridian = 0. ;
1818
latitude_longitude:earth_radius = 6371229. ;
19+
latitude_longitude:crs_wkt = "GEOGCRS[\"unknown\",DATUM[\"unknown\",ELLIPSOID[\"unknown\",6371229,0,LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8901]],CS[ellipsoidal,2],AXIS[\"longitude\",east,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],AXIS[\"latitude\",north,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]]" ;
1920
float latitude(latitude) ;
2021
latitude:axis = "Y" ;
2122
latitude:units = "degrees_north" ;

lib/iris/tests/results/integration/netcdf/general/TestPackedData/single_packed_signed.cdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ variables:
1616
latitude_longitude:grid_mapping_name = "latitude_longitude" ;
1717
latitude_longitude:longitude_of_prime_meridian = 0. ;
1818
latitude_longitude:earth_radius = 6371229. ;
19+
latitude_longitude:crs_wkt = "GEOGCRS[\"unknown\",DATUM[\"unknown\",ELLIPSOID[\"unknown\",6371229,0,LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8901]],CS[ellipsoidal,2],AXIS[\"longitude\",east,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],AXIS[\"latitude\",north,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]]" ;
1920
float latitude(latitude) ;
2021
latitude:axis = "Y" ;
2122
latitude:units = "degrees_north" ;

lib/iris/tests/results/integration/netcdf/general/TestPackedData/single_packed_unsigned.cdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ variables:
1616
latitude_longitude:grid_mapping_name = "latitude_longitude" ;
1717
latitude_longitude:longitude_of_prime_meridian = 0. ;
1818
latitude_longitude:earth_radius = 6371229. ;
19+
latitude_longitude:crs_wkt = "GEOGCRS[\"unknown\",DATUM[\"unknown\",ELLIPSOID[\"unknown\",6371229,0,LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8901]],CS[ellipsoidal,2],AXIS[\"longitude\",east,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]],AXIS[\"latitude\",north,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]]" ;
1920
float latitude(latitude) ;
2021
latitude:axis = "Y" ;
2122
latitude:units = "degrees_north" ;

0 commit comments

Comments
 (0)