Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/iris/fileformats/_nc_load_rules/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
)

Expand Down
8 changes: 4 additions & 4 deletions lib/iris/tests/results/netcdf/netcdf_stereo.cml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
10.449, 10.5996]]" shape="(160, 256)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="lon"/>
</coord>
<coord datadims="[1]">
<dimCoord id="3aaada22" points="[-2.28188e+06, -2.24639e+06, -2.21091e+06, ...,
<dimCoord id="9fba0c21" points="[-2.28188e+06, -2.24639e+06, -2.21091e+06, ...,
6.69544e+06, 6.73092e+06, 6.7664e+06]" shape="(256,)" standard_name="projection_x_coordinate" units="Unit('m')" value_type="float32" var_name="x">
<stereographic central_lat="90.0" central_lon="-35.0" ellipsoid="GeogCS(6378169.0)" false_easting="0.0" false_northing="0.0" scale_factor_at_projection_origin="None" true_scale_lat="None"/>
<stereographic central_lat="90.0" central_lon="-35.0" ellipsoid="GeogCS(6378169.0)" false_easting="0.0" false_northing="0.0" scale_factor_at_projection_origin="1.0" true_scale_lat="None"/>
</dimCoord>
</coord>
<coord datadims="[0]">
<dimCoord id="27f71466" points="[-981693.0, -1.01719e+06, -1.05269e+06, ...,
<dimCoord id="f10e9ab3" points="[-981693.0, -1.01719e+06, -1.05269e+06, ...,
-6.55525e+06, -6.59075e+06, -6.62625e+06]" shape="(160,)" standard_name="projection_y_coordinate" units="Unit('m')" value_type="float32" var_name="y">
<stereographic central_lat="90.0" central_lon="-35.0" ellipsoid="GeogCS(6378169.0)" false_easting="0.0" false_northing="0.0" scale_factor_at_projection_origin="None" true_scale_lat="None"/>
<stereographic central_lat="90.0" central_lon="-35.0" ellipsoid="GeogCS(6378169.0)" false_easting="0.0" false_northing="0.0" scale_factor_at_projection_origin="1.0" true_scale_lat="None"/>
</dimCoord>
</coord>
<coord>
Expand Down
Original file line number Diff line number Diff line change
@@ -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" ;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down
18 changes: 16 additions & 2 deletions lib/iris/tests/unit/fileformats/netcdf/test_Saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down