def test_load_tmerc_grid_with_projection_origin(self): # Test loading a single CF-netCDF file with a transverse Mercator # grid_mapping that uses longitude_of_projection_origin and # scale_factor_at_projection_origin instead of # longitude_of_central_meridian and scale_factor_at_central_meridian. cube = iris.load_cube( tests.get_data_path(( "NetCDF", "transverse_mercator", "projection_origin_attributes.nc", ))) expected = icoord_systems.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=icoord_systems.GeogCS(semi_major_axis=6377563.396, semi_minor_axis=6356256.91), ) self.assertEqual( cube.coord("projection_x_coordinate").coord_system, expected) self.assertEqual( cube.coord("projection_y_coordinate").coord_system, expected)
def different_projection(self, method, ancillary_data, additional_data, expected, **kwargs): """Test that the plugin copes with non-lat/lon grids.""" src_crs = ccrs.PlateCarree() trg_crs = ccrs.TransverseMercator(central_latitude=0, central_longitude=0) trg_crs_iris = coord_systems.TransverseMercator(0, 0, 0, 0, 1.0) lons = [-50, 50] lats = [-25, 25] x, y = [], [] for lon, lat in zip(lons, lats): x_trg, y_trg = trg_crs.transform_point(lon, lat, src_crs) x.append(x_trg) y.append(y_trg) new_x = DimCoord(np.linspace(x[0], x[1], 20), standard_name='projection_x_coordinate', units='m', coord_system=trg_crs_iris) new_y = DimCoord(np.linspace(y[0], y[1], 20), standard_name='projection_y_coordinate', units='m', coord_system=trg_crs_iris) new_cube = Cube(np.zeros(400).reshape(20, 20), long_name="air_temperature", dim_coords_and_dims=[(new_y, 0), (new_x, 1)], units="K") cube = self.cube.copy() cube = cube.regrid(new_cube, iris.analysis.Nearest()) if ancillary_data is not None: ancillary_data['orography'] = ancillary_data['orography'].regrid( new_cube, iris.analysis.Nearest()) if additional_data is not None: for ad in additional_data.keys(): additional_data[ad] = additional_data[ad].regrid( new_cube, iris.analysis.Nearest()) # Define neighbours on this new projection self.neighbour_list['i'] = 11 self.neighbour_list['j'] = 11 plugin = Plugin(method) with iris.FUTURE.context(cell_datetime_objects=True): cube = cube.extract(self.time_extract) result = plugin.process(cube, self.sites, self.neighbour_list, ancillary_data, additional_data, **kwargs) self.assertEqual(cube.coord_system(), trg_crs_iris) self.assertAlmostEqual(result.data, expected) self.assertEqual(result.coord(axis='y').name(), 'latitude') self.assertEqual(result.coord(axis='x').name(), 'longitude') self.assertAlmostEqual(result.coord(axis='y').points, 4.74) self.assertAlmostEqual(result.coord(axis='x').points, 9.47)