diff --git a/lib/iris/fileformats/_nc_load_rules/helpers.py b/lib/iris/fileformats/_nc_load_rules/helpers.py index e94fe99185..d50d3f324a 100644 --- a/lib/iris/fileformats/_nc_load_rules/helpers.py +++ b/lib/iris/fileformats/_nc_load_rules/helpers.py @@ -417,6 +417,10 @@ def build_stereographic_coordinate_system(engine, cf_grid_var): longitude_of_projection_origin = getattr( cf_grid_var, CF_ATTR_GRID_LON_OF_PROJ_ORIGIN, None ) + scale_factor_at_projection_origin = getattr( + cf_grid_var, CF_ATTR_GRID_SCALE_FACTOR_AT_PROJ_ORIGIN, None + ) + false_easting = getattr(cf_grid_var, CF_ATTR_GRID_FALSE_EASTING, None) false_northing = getattr(cf_grid_var, CF_ATTR_GRID_FALSE_NORTHING, None) @@ -426,6 +430,7 @@ def build_stereographic_coordinate_system(engine, cf_grid_var): false_easting, false_northing, true_scale_lat=None, + scale_factor_at_projection_origin=scale_factor_at_projection_origin, ellipsoid=ellipsoid, ) diff --git a/lib/iris/tests/results/netcdf/netcdf_stereo.cml b/lib/iris/tests/results/netcdf/netcdf_stereo.cml index c2d0bab03f..092cf337b6 100644 --- a/lib/iris/tests/results/netcdf/netcdf_stereo.cml +++ b/lib/iris/tests/results/netcdf/netcdf_stereo.cml @@ -54,15 +54,15 @@ 10.449, 10.5996]]" shape="(160, 256)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="lon"/> - - + - - + diff --git a/lib/iris/tests/results/unit/fileformats/netcdf/Saver/write/stereographic_scale_factor.cdl b/lib/iris/tests/results/unit/fileformats/netcdf/Saver/write/stereographic_scale_factor.cdl new file mode 100644 index 0000000000..a11dc60c30 --- /dev/null +++ b/lib/iris/tests/results/unit/fileformats/netcdf/Saver/write/stereographic_scale_factor.cdl @@ -0,0 +1,23 @@ +dimensions: + projection_x_coordinate = 4 ; + projection_y_coordinate = 3 ; +variables: + int64 air_pressure_anomaly(projection_y_coordinate, projection_x_coordinate) ; + air_pressure_anomaly:standard_name = "air_pressure_anomaly" ; + air_pressure_anomaly:grid_mapping = "stereographic" ; + int stereographic ; + stereographic:grid_mapping_name = "stereographic" ; + stereographic:longitude_of_projection_origin = 20. ; + stereographic:latitude_of_projection_origin = -10. ; + stereographic:false_easting = 500000. ; + stereographic:false_northing = -200000. ; + stereographic:scale_factor_at_projection_origin = 1.3 ; + int64 projection_y_coordinate(projection_y_coordinate) ; + projection_y_coordinate:axis = "Y" ; + projection_y_coordinate:units = "m" ; + projection_y_coordinate:standard_name = "projection_y_coordinate" ; + int64 projection_x_coordinate(projection_x_coordinate) ; + projection_x_coordinate:axis = "X" ; + projection_x_coordinate:units = "m" ; + projection_x_coordinate:standard_name = "projection_x_coordinate" ; +} diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_stereographic_coordinate_system.py b/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_stereographic_coordinate_system.py index 5058e4d7d3..3796aeebab 100644 --- a/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_stereographic_coordinate_system.py +++ b/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_stereographic_coordinate_system.py @@ -26,12 +26,13 @@ class TestBuildStereographicCoordinateSystem(tests.IrisTest): def _test(self, inverse_flattening=False, no_offsets=False): test_easting = -100 test_northing = 200 + test_scale_factor = 1.2 gridvar_props = dict( latitude_of_projection_origin=0, longitude_of_projection_origin=0, false_easting=test_easting, false_northing=test_northing, - scale_factor_at_projection_origin=1, + scale_factor_at_projection_origin=test_scale_factor, semi_major_axis=6377563.396, ) @@ -61,6 +62,7 @@ def _test(self, inverse_flattening=False, no_offsets=False): central_lon=cf_grid_var.longitude_of_projection_origin, false_easting=test_easting, false_northing=test_northing, + scale_factor_at_projection_origin=test_scale_factor, ellipsoid=expected_ellipsoid, ) diff --git a/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py b/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py index 61b37fe477..37bcee7da2 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py +++ b/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py @@ -87,11 +87,17 @@ def _mercator_cube(self, ellipsoid=None): cube.add_dim_coord(coord, 1) return cube - def _stereo_cube(self, ellipsoid=None): + def _stereo_cube(self, ellipsoid=None, scale_factor=None): data = self.array_lib.arange(12).reshape(3, 4) cube = Cube(data, "air_pressure_anomaly") stereo = Stereographic( - -10.0, 20.0, 500000.0, -200000.0, None, ellipsoid + -10.0, + 20.0, + 500000.0, + -200000.0, + None, + ellipsoid, + scale_factor_at_projection_origin=scale_factor, ) coord = DimCoord( np.arange(3), @@ -160,6 +166,14 @@ def test_stereographic_no_ellipsoid(self): saver.write(cube) self.assertCDL(nc_path) + def test_stereographic_scale_factor(self): + # Create a Cube with a stereographic coordinate system. + cube = self._stereo_cube(scale_factor=1.3) + with self.temp_filename(".nc") as nc_path: + with Saver(nc_path, "NETCDF4") as saver: + saver.write(cube) + self.assertCDL(nc_path) + def _simple_cube(self, dtype): data = self.array_lib.arange(12, dtype=dtype).reshape(3, 4) points = np.arange(3, dtype=dtype)