def test_extra_kwargs(self): longitude_of_projection_origin = 90.0 true_scale_lat = 14.0 false_easting = 13 false_northing = 12 ellipsoid = GeogCS(semi_major_axis=6377563.396, semi_minor_axis=6356256.909) merc_cs = Mercator( longitude_of_projection_origin, ellipsoid=ellipsoid, standard_parallel=true_scale_lat, false_easting=false_easting, false_northing=false_northing, ) expected = ccrs.Mercator( central_longitude=longitude_of_projection_origin, globe=ccrs.Globe( semimajor_axis=6377563.396, semiminor_axis=6356256.909, ellipse=None, ), latitude_true_scale=true_scale_lat, false_easting=false_easting, false_northing=false_northing, ) res = merc_cs.as_cartopy_projection() self.assertEqual(res, expected)
def test_simple(self): # Check that a projection set up with all the defaults is correctly # converted to a cartopy projection. merc_cs = Mercator() res = merc_cs.as_cartopy_projection() expected = ccrs.Mercator(globe=ccrs.Globe()) self.assertEqual(res, expected)
def test_extra_kwargs(self): # Check that a projection with non-default values is correctly # converted to a cartopy CRS. longitude_of_projection_origin = 90.0 true_scale_lat = 14.0 ellipsoid = GeogCS(semi_major_axis=6377563.396, semi_minor_axis=6356256.909) merc_cs = Mercator( longitude_of_projection_origin, ellipsoid=ellipsoid, standard_parallel=true_scale_lat, ) expected = ccrs.Mercator( central_longitude=longitude_of_projection_origin, globe=ccrs.Globe( semimajor_axis=6377563.396, semiminor_axis=6356256.909, ellipse=None, ), latitude_true_scale=true_scale_lat, ) res = merc_cs.as_cartopy_crs() self.assertEqual(res, expected)
def test_set_optional_args(self): # Check that setting the optional (non-ellipse) args works. crs = Mercator( longitude_of_projection_origin=27, standard_parallel=157.4 ) self.assertEqualAndKind(crs.longitude_of_projection_origin, 27.0) self.assertEqualAndKind(crs.standard_parallel, 157.4)
def test_simple(self): # Check that a projection set up with all the defaults is correctly # converted to a cartopy CRS. merc_cs = Mercator() res = merc_cs.as_cartopy_crs() # expected = ccrs.Mercator(globe=ccrs.Globe()) expected = ccrs.Mercator(globe=ccrs.Globe(), latitude_true_scale=0.0) self.assertEqual(res, expected)
def test_optional_args_None(self): # Check expected defaults with optional args=None. crs = Mercator( longitude_of_projection_origin=None, standard_parallel=None, false_easting=None, false_northing=None, ) self._check_crs_defaults(crs)
def test_grid_definition_template_10(self): # Mercator grid. x_points = np.arange(3) y_points = np.arange(3) coord_units = 'm' cs = Mercator(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', 10)
def test_longitude_missing(self): cf_grid_var = mock.Mock(spec=[], semi_major_axis=6377563.396, inverse_flattening=299.3249646) cs = build_mercator_coordinate_system(None, cf_grid_var) expected = Mercator(ellipsoid=iris.coord_systems.GeogCS( cf_grid_var.semi_major_axis, inverse_flattening=cf_grid_var.inverse_flattening)) self.assertEqual(cs, expected)
def _mercator_cube(self, ellipsoid=None): data = np.arange(12).reshape(3, 4) cube = Cube(data, 'air_pressure_anomaly') merc = Mercator(49.0, ellipsoid) coord = DimCoord(np.arange(3), 'projection_y_coordinate', units='m', coord_system=merc) cube.add_dim_coord(coord, 0) coord = DimCoord(np.arange(4), 'projection_x_coordinate', units='m', coord_system=merc) cube.add_dim_coord(coord, 1) return cube
def test_fail_unsupported_coord_system(self): # Test plotting vectors in a rotated latlon coord system. u_cube, v_cube = self._latlon_uv_cubes(sample_2d_latlons()) patch_coord_system = Mercator() for cube in u_cube, v_cube: for coord in cube.coords(): coord.coord_system = patch_coord_system re_msg = ('Can only plot .* lat-lon projection, .* ' 'This .* translates as Cartopy.*Mercator') with self.assertRaisesRegexp(ValueError, re_msg): self.plot('2d_rotated', u_cube, v_cube, coords=('longitude', 'latitude'))
def test_valid(self): cf_grid_var = mock.Mock(spec=[], longitude_of_projection_origin=-90, semi_major_axis=6377563.396, semi_minor_axis=6356256.909) cs = build_mercator_coordinate_system(None, cf_grid_var) expected = Mercator(longitude_of_projection_origin=( cf_grid_var.longitude_of_projection_origin), ellipsoid=iris.coord_systems.GeogCS( cf_grid_var.semi_major_axis, cf_grid_var.semi_minor_axis)) self.assertEqual(cs, expected)
def test_fail_unsupported_coord_system(self): # Test plotting vectors in a rotated latlon coord system. u_cube, v_cube = self._latlon_uv_cubes(sample_2d_latlons()) patch_coord_system = Mercator() for cube in u_cube, v_cube: for coord in cube.coords(): coord.coord_system = patch_coord_system re_msg = (r"Can only plot .* lat-lon projection, .* " r"This .* translates as Cartopy \+proj=merc .*") with self.assertRaisesRegex(ValueError, re_msg): self.plot("2d_rotated", u_cube, v_cube, coords=("longitude", "latitude"))
def test_inverse_flattening(self): cf_grid_var = mock.Mock( spec=[], longitude_of_projection_origin=-90, semi_major_axis=6377563.396, inverse_flattening=299.3249646, ) cs = build_mercator_coordinate_system(None, cf_grid_var) expected = Mercator( longitude_of_projection_origin=( cf_grid_var.longitude_of_projection_origin), ellipsoid=iris.coord_systems.GeogCS( cf_grid_var.semi_major_axis, inverse_flattening=cf_grid_var.inverse_flattening, ), ) self.assertEqual(cs, expected)
def _mercator_cube(self, ellipsoid=None): data = self.array_lib.arange(12).reshape(3, 4) cube = Cube(data, "air_pressure_anomaly") merc = Mercator(49.0, ellipsoid) coord = DimCoord( np.arange(3), "projection_y_coordinate", units="m", coord_system=merc, ) cube.add_dim_coord(coord, 0) coord = DimCoord( np.arange(4), "projection_x_coordinate", units="m", coord_system=merc, ) cube.add_dim_coord(coord, 1) return cube
def test_no_optional_args(self): # Check expected defaults with no optional args. crs = Mercator() self._check_crs_defaults(crs)
def setUp(self): self.tm = Mercator(longitude_of_projection_origin=90.0, ellipsoid=GeogCS(6377563.396, 6356256.909))
def _default_coord_system(self): return Mercator(standard_parallel=14., ellipsoid=self.default_ellipsoid)