def test_as_cartopy_projection(self): latitude_of_projection_origin = 49.0 longitude_of_central_meridian = -2.0 false_easting = -40000.0 false_northing = 10000.0 scale_factor_at_central_meridian = 0.9996012717 ellipsoid = GeogCS(semi_major_axis=6377563.396, semi_minor_axis=6356256.909) tmerc_cs = TransverseMercator( latitude_of_projection_origin, longitude_of_central_meridian, false_easting, false_northing, scale_factor_at_central_meridian, ellipsoid=ellipsoid, ) expected = ccrs.TransverseMercator( central_longitude=longitude_of_central_meridian, central_latitude=latitude_of_projection_origin, false_easting=false_easting, false_northing=false_northing, scale_factor=scale_factor_at_central_meridian, globe=ccrs.Globe( semimajor_axis=6377563.396, semiminor_axis=6356256.909, ellipse=None, ), ) res = tmerc_cs.as_cartopy_projection() self.assertEqual(res, expected)
def test_as_cartopy_projection(self): latitude_of_projection_origin = 49.0 longitude_of_central_meridian = -2.0 false_easting = -40000.0 false_northing = 10000.0 scale_factor_at_central_meridian = 0.9996012717 ellipsoid = GeogCS(semi_major_axis=6377563.396, semi_minor_axis=6356256.909) tmerc_cs = TransverseMercator( latitude_of_projection_origin, longitude_of_central_meridian, false_easting, false_northing, scale_factor_at_central_meridian, ellipsoid=ellipsoid) expected = ccrs.TransverseMercator( central_longitude=longitude_of_central_meridian, central_latitude=latitude_of_projection_origin, false_easting=false_easting, false_northing=false_northing, scale_factor=scale_factor_at_central_meridian, globe=ccrs.Globe(semimajor_axis=6377563.396, semiminor_axis=6356256.909, ellipse=None)) res = tmerc_cs.as_cartopy_projection() self.assertEqual(res, expected)
def osgb(): return TransverseMercator(latitude_of_projection_origin=49, longitude_of_central_meridian=-2, false_easting=-400, false_northing=100, scale_factor_at_central_meridian=0.9996012717, ellipsoid=GeogCS(6377563.396, 6356256.909))
def test_grid_definition_template_12(self): # Transverse Mercator grid. x_points = np.arange(3) y_points = np.arange(3) coord_units = 'm' cs = TransverseMercator(0, 0, 0, 0, 1, ellipsoid=self.ellipsoid) test_cube = self._make_test_cube(cs, x_points, y_points, coord_units) grid_definition_section(test_cube, self.mock_grib) self._check_key('gridDefinitionTemplateNumber', 12)
def _default_coord_system(self): # This defines an OSGB coord system. cs = TransverseMercator(latitude_of_projection_origin=49.0, longitude_of_central_meridian=-2.0, false_easting=400000.0, false_northing=-100000.0, scale_factor_at_central_meridian=0.9996012717, ellipsoid=self.default_ellipsoid) return cs
def test_optional_args_None(self): # Check expected defaults with optional args=None. crs = TransverseMercator( 0, 50, false_easting=None, false_northing=None, scale_factor_at_central_meridian=None, ) self._check_crs_defaults(crs)
def _transverse_mercator_cube(self, ellipsoid=None): data = np.arange(12).reshape(3, 4) cube = Cube(data, 'air_pressure_anomaly') trans_merc = TransverseMercator(49.0, -2.0, -400000.0, 100000.0, 0.9996012717, ellipsoid) coord = DimCoord(range(3), 'projection_y_coordinate', units='m', coord_system=trans_merc) cube.add_dim_coord(coord, 0) coord = DimCoord(range(4), 'projection_x_coordinate', units='m', coord_system=trans_merc) cube.add_dim_coord(coord, 1) return cube
def test_set_optional_args(self): # Check that setting the optional (non-ellipse) args works. crs = TransverseMercator( 0, 50, false_easting=100, false_northing=-203.7, scale_factor_at_central_meridian=1.057, ) self.assertEqualAndKind(crs.false_easting, 100.0) self.assertEqualAndKind(crs.false_northing, -203.7) self.assertEqualAndKind(crs.scale_factor_at_central_meridian, 1.057)
def _test(self, inverse_flattening=False, no_options=False): test_easting = -100 test_northing = 200 test_scale_factor = 1.234 gridvar_props = dict( latitude_of_projection_origin=35.3, longitude_of_central_meridian=-75, false_easting=test_easting, false_northing=test_northing, scale_factor_at_central_meridian=test_scale_factor, semi_major_axis=6377563.396, ) if inverse_flattening: gridvar_props["inverse_flattening"] = 299.3249646 expected_ellipsoid = iris.coord_systems.GeogCS( 6377563.396, inverse_flattening=299.3249646 ) else: gridvar_props["semi_minor_axis"] = 6356256.909 expected_ellipsoid = iris.coord_systems.GeogCS( 6377563.396, 6356256.909 ) if no_options: del gridvar_props["false_easting"] del gridvar_props["false_northing"] del gridvar_props["scale_factor_at_central_meridian"] test_easting = 0 test_northing = 0 test_scale_factor = 1.0 cf_grid_var = mock.Mock(spec=[], **gridvar_props) cs = build_transverse_mercator_coordinate_system(None, cf_grid_var) expected = TransverseMercator( latitude_of_projection_origin=( cf_grid_var.latitude_of_projection_origin ), longitude_of_central_meridian=( cf_grid_var.longitude_of_central_meridian ), false_easting=test_easting, false_northing=test_northing, scale_factor_at_central_meridian=test_scale_factor, ellipsoid=expected_ellipsoid, ) self.assertEqual(cs, expected)
def _transverse_mercator_cube(self, ellipsoid=None): data = self.array_lib.arange(12).reshape(3, 4) cube = Cube(data, "air_pressure_anomaly") trans_merc = TransverseMercator(49.0, -2.0, -400000.0, 100000.0, 0.9996012717, ellipsoid) coord = DimCoord( np.arange(3), "projection_y_coordinate", units="m", coord_system=trans_merc, ) cube.add_dim_coord(coord, 0) coord = DimCoord( np.arange(4), "projection_x_coordinate", units="m", coord_system=trans_merc, ) cube.add_dim_coord(coord, 1) return cube
import numpy as np from iris.coord_systems import GeogCS, TransverseMercator from iris.coords import DimCoord from iris.tests import IrisTest from improver.metadata.constants.attributes import MANDATORY_ATTRIBUTE_DEFAULTS from improver.metadata.constants.mo_attributes import MOSG_GRID_ATTRIBUTES from improver.orographic_enhancement import OrographicEnhancement from improver.synthetic_data.set_up_test_cubes import construct_scalar_time_coords from improver.utilities.cube_manipulation import sort_coord_in_cube # UKPP projection TMercCS = TransverseMercator( latitude_of_projection_origin=49.0, longitude_of_central_meridian=-2.0, false_easting=400000.0, false_northing=-100000.0, scale_factor_at_central_meridian=0.9996013045310974, ellipsoid=GeogCS(semi_major_axis=6377563.396, semi_minor_axis=6356256.91), ) def set_up_variable_cube(data, name="temperature", units="degC", xo=400000.0, yo=0.0, attributes=None): """ Set up cube containing diagnostic variable data for regridding tests. Data are on a 2 km Transverse Mercator grid with an inverted y-axis, located in the UK.
def test_no_optional_args(self): # Check expected defaults with no optional args. crs = TransverseMercator(0, 50) self._check_crs_defaults(crs)