def test_xy_names(self): gm = GridMapping.regular((1000, 1000), (10, 53), 0.01, GEO_CRS).derive(tile_size=500) self.assertEqual(('lon', 'lat'), gm.xy_var_names) self.assertEqual(('lon', 'lat'), gm.xy_dim_names) gm = GridMapping.regular((1000, 1000), (10, 53), 0.01, NOT_A_GEO_CRS).derive(tile_size=500) self.assertEqual(('x', 'y'), gm.xy_var_names) self.assertEqual(('x', 'y'), gm.xy_dim_names)
def test_rectify_2x2_to_13x13_none(self): source_ds = self.new_2x2_dataset_with_irregular_coords() target_gm = GridMapping.regular(size=(13, 13), xy_min=(10.0, 50.0), xy_res=0.5, crs=CRS_WGS84) target_ds = rectify_dataset(source_ds, target_gm=target_gm) self.assertIsNone(target_ds) target_gm = GridMapping.regular(size=(13, 13), xy_min=(-10.0, 50.0), xy_res=0.5, crs=CRS_WGS84) target_ds = rectify_dataset(source_ds, target_gm=target_gm) self.assertIsNone(target_ds) target_gm = GridMapping.regular(size=(13, 13), xy_min=(0.0, 58.0), xy_res=0.5, crs=CRS_WGS84) target_ds = rectify_dataset(source_ds, target_gm=target_gm) self.assertIsNone(target_ds) target_gm = GridMapping.regular(size=(13, 13), xy_min=(0.0, 42.0), xy_res=0.5, crs=CRS_WGS84) target_ds = rectify_dataset(source_ds, target_gm=target_gm) self.assertIsNone(target_ds)
def test_shift(self): target_gm = GridMapping.regular((8, 6), (50.2, 10.1), res, source_gm.crs) target_ds = affine_transform_dataset(source_ds, source_gm, target_gm) self.assertIsInstance(target_ds, xr.Dataset) self.assertEqual(set(target_ds.variables), set(source_ds.variables)) self.assertEqual((6, 8), target_ds.refl.shape) print(repr(target_ds.refl.values)) np.testing.assert_almost_equal( target_ds.refl.values, np.array([[nan, nan, nan, nan, nan, nan, nan, nan], [0.0, 2.0, 0.0, 3.0, 0.0, 4.0, nan, nan], [3.0, 0.0, 4.0, 0.0, 1.0, 0.0, nan, nan], [0.0, 1.0, 0.0, 2.0, 0.0, 3.0, nan, nan], [2.0, 0.0, 3.0, 0.0, 4.0, 0.0, nan, nan], [0.0, 4.0, 0.0, 1.0, 0.0, 2.0, nan, nan]])) target_gm = GridMapping.regular((8, 6), (49.8, 9.9), res, source_gm.crs) target_ds = affine_transform_dataset(source_ds, source_gm, target_gm) self.assertIsInstance(target_ds, xr.Dataset) self.assertEqual(set(target_ds.variables), set(source_ds.variables)) self.assertEqual((6, 8), target_ds.refl.shape) print(repr(target_ds.refl.values)) np.testing.assert_almost_equal( target_ds.refl.values, np.array([[nan, nan, 2.0, 0.0, 3.0, 0.0, 4.0, 0.0], [nan, nan, 0.0, 4.0, 0.0, 1.0, 0.0, 2.0], [nan, nan, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0], [nan, nan, 0.0, 3.0, 0.0, 4.0, 0.0, 1.0], [nan, nan, 4.0, 0.0, 1.0, 0.0, 2.0, 0.0], [nan, nan, nan, nan, nan, nan, nan, nan]]))
def test_xy_bboxes_is_j_axis_up(self): gm = GridMapping.regular(size=(2000, 1000), xy_min=(10.0, 20.0), xy_res=0.1, crs=NOT_A_GEO_CRS).derive(is_j_axis_up=True) np.testing.assert_almost_equal(gm.xy_bboxes, np.array([[10., 20., 210., 120.]], dtype=np.float64)) gm = GridMapping.regular(size=(2000, 1000), xy_min=(10.0, 20.0), xy_res=0.1, crs=NOT_A_GEO_CRS, ).derive(tile_size=500, is_j_axis_up=True) np.testing.assert_almost_equal(gm.xy_bboxes, np.array([ [10., 20., 60., 70.], [60., 20., 110., 70.], [110., 20., 160., 70.], [160., 20., 210., 70.], [10., 70., 60., 120.], [60., 70., 110., 120.], [110., 70., 160., 120.], [160., 70., 210., 120.] ], dtype=np.float64))
def test_invalid_y(self): with self.assertRaises(ValueError) as cm: GridMapping.regular((1000, 1000), (10, -90.5), 0.01, CRS_WGS84) self.assertEqual('invalid y_min', f'{cm.exception}') with self.assertRaises(ValueError) as cm: GridMapping.regular((1000, 1000), (10, 53), 0.1, CRS_WGS84) self.assertEqual('invalid size, y_min combination', f'{cm.exception}')
def test_tile_grid(self): gm = GridMapping.regular((7200, 3600), (-180, -90), 360 / 7200, 'epsg:4326', tile_size=(720, 360), is_j_axis_up=True) tile_grid = gm.tile_grid self.assertIsInstance(tile_grid, TileGrid) self.assertEqual([(1, 1), (2, 2), (3, 3), (5, 5), (10, 10)], [tile_grid.get_num_tiles(i) for i in range(tile_grid.num_levels)]) self.assertEqual([(450, 225), (900, 450), (1800, 900), (3600, 1800), (7200, 3600)], [tile_grid.get_image_size(i) for i in range(tile_grid.num_levels)]) self.assertEqual([0.8, 0.4, 0.2, 0.1, 0.05], [tile_grid.get_resolution(i) for i in range(tile_grid.num_levels)])
def _new_xy_coords(self) -> xr.DataArray: return GridMapping.regular(size=self.size, tile_size=self.tile_size, is_j_axis_up=self.is_j_axis_up, xy_res=self.xy_res, xy_min=(self.xy_bbox[0], self.xy_bbox[1]), crs=self.crs).xy_coords
def test_rectify_2x2_to_7x7_subset(self): source_ds = self.new_2x2_dataset_with_irregular_coords() target_gm = GridMapping.regular(size=(7, 7), xy_min=(1.5, 50.5), xy_res=1.0, crs=CRS_WGS84) target_ds = rectify_dataset(source_ds, target_gm=target_gm) lon, lat, rad = self._assert_shape_and_dim(target_ds, (7, 7)) np.testing.assert_almost_equal( lon.values, np.array([2.0, 3.0, 4.0, 5., 6., 7., 8.], dtype=lon.dtype)) np.testing.assert_almost_equal( lat.values, np.array([57., 56., 55., 54., 53., 52., 51.], dtype=lat.dtype)) np.testing.assert_almost_equal( rad.values, np.array([ [nan, nan, nan, nan, nan, nan, nan], [nan, nan, nan, nan, nan, nan, nan], [1.0, nan, nan, nan, nan, nan, nan], [1.0, 1.0, 2.0, nan, nan, nan, nan], [3.0, 1.0, 2.0, 2.0, 2.0, nan, nan], [3.0, 4.0, 2.0, nan, nan, nan, nan], [4.0, 4.0, nan, nan, nan, nan, nan], ], dtype=rad.dtype))
def test_rectify_2x2_to_13x13_output_ij_names(self): source_ds = self.new_2x2_dataset_with_irregular_coords() target_gm = GridMapping.regular(size=(13, 13), xy_min=(-0.25, 49.75), xy_res=0.5, crs=CRS_WGS84) target_ds = rectify_dataset(source_ds, target_gm=target_gm, output_ij_names=('source_i', 'source_j')) lon, lat, rad, source_i, source_j = self._assert_shape_and_dim( target_ds, (13, 13), var_names=('rad', 'source_i', 'source_j')) np.testing.assert_almost_equal( lon.values, np.array([ 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5., 5.5, 6. ], dtype=lon.dtype)) np.testing.assert_almost_equal( lat.values, np.array([ 56., 55.5, 55., 54.5, 54., 53.5, 53., 52.5, 52., 51.5, 51., 50.5, 50. ], dtype=lat.dtype)) np.testing.assert_almost_equal(rad.values, self.expected_rad_13x13(rad.dtype)) np.testing.assert_almost_equal(np.floor(source_i.values + 0.5), self.expected_i_13x13()) np.testing.assert_almost_equal(np.floor(source_j.values + 0.5), self.expected_j_13x13())
def test_rectify_2x2_to_13x13_antimeridian(self): source_ds = self.new_2x2_dataset_with_irregular_coords_antimeridian() target_gm = GridMapping.regular(size=(13, 13), xy_min=(177.75, 49.75), xy_res=0.5, crs=CRS_WGS84) self.assertEqual(True, target_gm.is_lon_360) target_ds = rectify_dataset(source_ds, target_gm=target_gm) self.assertIsNotNone(target_ds) lon, lat, rad = self._assert_shape_and_dim(target_ds, (13, 13)) np.testing.assert_almost_equal( lon.values, np.array([ 178., 178.5, 179., 179.5, 180., -179.5, -179., -178.5, -178., -177.5, -177., -176.5, -176. ], dtype=lon.dtype)) np.testing.assert_almost_equal( lat.values, np.array([ 56., 55.5, 55., 54.5, 54., 53.5, 53., 52.5, 52., 51.5, 51., 50.5, 50. ], dtype=lat.dtype)) np.testing.assert_almost_equal(rad.values, self.expected_rad_13x13(rad.dtype))
def test_rectify_2x2_to_13x13_dask_13x3(self): source_ds = self.new_2x2_dataset_with_irregular_coords() target_gm = GridMapping.regular(size=(13, 13), xy_min=(-0.25, 49.75), xy_res=0.5, crs=CRS_WGS84, tile_size=(13, 3)) target_ds = rectify_dataset(source_ds, target_gm=target_gm) lon, lat, rad = self._assert_shape_and_dim(target_ds, (13, 13), chunks=((3, 3, 3, 3, 1), (13, ))) np.testing.assert_almost_equal( lon.values, np.array([ 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5., 5.5, 6. ], dtype=lon.dtype)) np.testing.assert_almost_equal( lat.values, np.array([ 56., 55.5, 55., 54.5, 54., 53.5, 53., 52.5, 52., 51.5, 51., 50.5, 50. ], dtype=lat.dtype)) np.testing.assert_almost_equal(rad.values, self.expected_rad_13x13(rad.dtype))
def test_xy_coords(self): gm = GridMapping.regular((8, 4), (10, 53), 0.1, CRS_WGS84).derive(tile_size=(4, 2)) xy_coords = gm.xy_coords self.assertIsInstance(xy_coords, xr.DataArray) self.assertIs(gm.xy_coords, xy_coords) self.assertEqual(('coord', 'lat', 'lon'), xy_coords.dims) self.assertEqual((2, 4, 8), xy_coords.shape) self.assertEqual(((2,), (2, 2), (4, 4)), xy_coords.chunks) np.testing.assert_almost_equal( np.array([ [10.05, 10.15, 10.25, 10.35, 10.45, 10.55, 10.65, 10.75], [10.05, 10.15, 10.25, 10.35, 10.45, 10.55, 10.65, 10.75], [10.05, 10.15, 10.25, 10.35, 10.45, 10.55, 10.65, 10.75], [10.05, 10.15, 10.25, 10.35, 10.45, 10.55, 10.65, 10.75] ]), xy_coords.values[0] ) np.testing.assert_almost_equal( np.array([ [53.35, 53.35, 53.35, 53.35, 53.35, 53.35, 53.35, 53.35], [53.25, 53.25, 53.25, 53.25, 53.25, 53.25, 53.25, 53.25], [53.15, 53.15, 53.15, 53.15, 53.15, 53.15, 53.15, 53.15], [53.05, 53.05, 53.05, 53.05, 53.05, 53.05, 53.05, 53.05] ]), xy_coords.values[1] )
def test_default_props(self): gm = GridMapping.regular((1000, 1000), (10, 53), 0.01, CRS_WGS84) self.assertEqual((1000, 1000), gm.size) self.assertEqual((1000, 1000), gm.tile_size) self.assertEqual(10, gm.x_min) self.assertEqual(53, gm.y_min) self.assertEqual((0.01, 0.01), gm.xy_res) self.assertEqual(True, gm.is_regular) self.assertEqual(False, gm.is_j_axis_up)
def test_affine_transform_dataset(self): source_ds = new_cube() source_gm = GridMapping.from_dataset(source_ds) target_gm = GridMapping.regular(size=(8, 4), xy_min=(0, 0), xy_res=2, crs=CRS_WGS84) # TODO: assert stuff resample_in_space(source_ds, source_gm, target_gm)
def test_derive(self): gm = GridMapping.regular((1000, 1000), (10, 53), 0.01, CRS_WGS84) self.assertEqual((1000, 1000), gm.size) self.assertEqual((1000, 1000), gm.tile_size) self.assertEqual(False, gm.is_j_axis_up) derived_gm = gm.derive(tile_size=500, is_j_axis_up=True) self.assertIsNot(gm, derived_gm) self.assertIsInstance(derived_gm, RegularGridMapping) self.assertEqual((1000, 1000), derived_gm.size) self.assertEqual((500, 500), derived_gm.tile_size) self.assertEqual(True, derived_gm.is_j_axis_up)
def test_subset(self): target_gm = GridMapping.regular((3, 3), (50.0, 10.0), res, source_gm.crs) target_ds = affine_transform_dataset(source_ds, source_gm, target_gm) self.assertIsInstance(target_ds, xr.Dataset) self.assertEqual(set(target_ds.variables), set(source_ds.variables)) self.assertEqual((3, 3), target_ds.refl.shape) np.testing.assert_almost_equal( target_ds.refl.values, np.array([ [1, 0, 2], [0, 3, 0], [4, 0, 1], ])) target_gm = GridMapping.regular((3, 3), (50.1, 10.1), res, source_gm.crs) target_ds = affine_transform_dataset(source_ds, source_gm, target_gm) self.assertIsInstance(target_ds, xr.Dataset) self.assertEqual(set(target_ds.variables), set(source_ds.variables)) self.assertEqual((3, 3), target_ds.refl.shape) np.testing.assert_almost_equal( target_ds.refl.values, np.array([ [4, 0, 1], [0, 2, 0], [3, 0, 4], ])) target_gm = GridMapping.regular((3, 3), (50.05, 10.05), res, source_gm.crs) target_ds = affine_transform_dataset(source_ds, source_gm, target_gm) self.assertIsInstance(target_ds, xr.Dataset) self.assertEqual(set(target_ds.variables), set(source_ds.variables)) self.assertEqual((3, 3), target_ds.refl.shape) np.testing.assert_almost_equal( target_ds.refl.values, np.array([[1.25, 1.5, 0.75], [1., 1.25, 1.5], [1.75, 1., 1.25]]))
def test_ij_bboxes(self): gm = GridMapping.regular(size=(2000, 1000), xy_min=(10.0, 20.0), xy_res=0.1, crs=NOT_A_GEO_CRS) np.testing.assert_almost_equal(gm.ij_bboxes, np.array([[0, 0, 2000, 1000]], dtype=np.int64)) gm = GridMapping.regular(size=(2000, 1000), xy_min=(10.0, 20.0), xy_res=0.1, crs=NOT_A_GEO_CRS).derive(tile_size=500) np.testing.assert_almost_equal(gm.ij_bboxes, np.array([ [0, 0, 500, 500], [500, 0, 1000, 500], [1000, 0, 1500, 500], [1500, 0, 2000, 500], [0, 500, 500, 1000], [500, 500, 1000, 1000], [1000, 500, 1500, 1000], [1500, 500, 2000, 1000] ], dtype=np.int64))
def test_transform_no_op(self): dataset = create_s2plus_dataset() gm = GridMapping.from_dataset(dataset, prefer_is_regular=True) # Assert we've picked the projected one which is regular self.assertEqual("Projected CRS", gm.crs.type_name) self.assertEqual(True, gm.is_regular) gm_t = gm.transform(gm.crs) self.assertIs(gm, gm_t) # Almost no op gm = GridMapping.regular(size=(3, 3), xy_min=(10, 53), xy_res=0.1, crs=CRS_CRS84) gm_t = gm.transform(crs=gm.crs, xy_var_names=('x', 'y')) self.assertEqual(('x', 'y'), gm_t.xy_var_names)
def test_to_regular(self): lon = xr.DataArray([[1.0, 6.0], [0.0, 2.0]], dims=('y', 'x')) lat = xr.DataArray([[56.0, 53.0], [52.0, 50.0]], dims=('y', 'x')) gm_irr = GridMapping.from_coords(lon, lat, GEO_CRS) gm_reg_actual = gm_irr.to_regular() gm_reg_expected = GridMapping.regular(size=(4, 4), xy_min=(-2, 48), xy_res=4.0, crs=GEO_CRS) self.assertEqual(gm_reg_expected.size, gm_reg_actual.size) self.assertEqual(gm_reg_expected.tile_size, gm_reg_actual.tile_size) self.assertEqual(gm_reg_expected.xy_res, gm_reg_actual.xy_res) self.assertEqual(gm_reg_expected.xy_bbox, gm_reg_actual.xy_bbox) self.assertEqual(gm_reg_expected.crs, gm_reg_actual.crs)
def test_upscale_x2(self): target_gm = GridMapping.regular((8, 6), (50, 10), res / 2, source_gm.crs) target_ds = affine_transform_dataset(source_ds, source_gm, target_gm) self.assertIsInstance(target_ds, xr.Dataset) self.assertEqual(set(target_ds.variables), set(source_ds.variables)) self.assertEqual((6, 8), target_ds.refl.shape) print(repr(target_ds.refl.values)) np.testing.assert_almost_equal( target_ds.refl.values, np.array([[1.0, 0.5, 0.0, 1.0, 2.0, 1.0, 0.0, 1.5], [0.5, 1.0, 1.5, 1.25, 1.0, 1.5, 2.0, 1.75], [0.0, 1.5, 3.0, 1.5, 0.0, 2.0, 4.0, 2.0], [2.0, 1.75, 1.5, 1.0, 0.5, 1.25, 2.0, 1.5], [4.0, 2.0, 0.0, 0.5, 1.0, 0.5, 0.0, 1.0], [nan, nan, nan, nan, nan, nan, nan, nan]]))
def test_downscale_x2_and_shift(self): target_gm = GridMapping.regular((8, 6), (49.8, 9.8), 2 * res, source_gm.crs) target_ds = affine_transform_dataset(source_ds, source_gm, target_gm) self.assertIsInstance(target_ds, xr.Dataset) self.assertEqual(set(target_ds.variables), set(source_ds.variables)) self.assertEqual((6, 8), target_ds.refl.shape) print(repr(target_ds.refl.values)) np.testing.assert_almost_equal( target_ds.refl.values, np.array([[nan, nan, nan, nan, nan, nan, nan, nan], [nan, nan, nan, nan, nan, nan, nan, nan], [nan, 0.75, 1.25, 1.75, 1.25, nan, nan, nan], [nan, 1.25, 0.75, 1.25, 1.75, nan, nan, nan], [nan, 1.75, 1.25, 0.75, 1.25, nan, nan, nan], [nan, nan, nan, nan, nan, nan, nan, nan]]))
def test_coord_vars_antimeridian(self): gm = GridMapping.regular(size=(10, 10), xy_min=(172.0, 53.0), xy_res=2.0, crs=GEO_CRS) cv = gm.to_coords(xy_var_names=('lon', 'lat')) self._assert_coord_vars(cv, (10, 10), ('lon', 'lat'), (173.0, -169.0), (72.0, 54.0), ('lon_bnds', 'lat_bnds'), ( (172., 174.), (-170., -168.), ), ( (73., 71.), (55., 53.), ))
def test_coord_vars_j_axis_up(self): gm = GridMapping.regular(size=(10, 6), xy_min=(-2600.0, 1200.0), xy_res=10.0, crs=NOT_A_GEO_CRS).derive(is_j_axis_up=True) cv = gm.to_coords(xy_var_names=('x', 'y')) self._assert_coord_vars(cv, (10, 6), ('x', 'y'), (-2595., -2505.), (1205., 1255.), ('x_bnds', 'y_bnds'), ( (-2600., -2590.), (-2510., -2500.), ), ( (1200., 1210.), (1250., 1260.), ))
def _compute_target_grid_mapping(cube_config: CubeConfig, source_gm: GridMapping) -> GridMapping: # assert_true(source_gm.is_regular, 'source_gm must be regular') target_crs = cube_config.crs target_bbox = cube_config.bbox target_spatial_res = cube_config.spatial_res if target_crs is None \ and target_bbox is None \ and target_spatial_res is None: # Nothing to do if source_gm.is_regular: return source_gm return source_gm.to_regular(tile_size=cube_config.tile_size) if target_spatial_res is not None: xy_res = (target_spatial_res, target_spatial_res) else: xy_res = source_gm.xy_res if target_bbox is not None: x_res, y_res = xy_res x_min, y_min, x_max, y_max = target_bbox xy_min = x_min, y_min size = round((x_max - x_min) / x_res), round((y_max - y_min) / y_res) else: xy_min = source_gm.x_min, source_gm.y_min size = source_gm.size if target_crs is not None: crs = pyproj.crs.CRS.from_string(target_crs) else: crs = source_gm.crs target_gm = GridMapping.regular(size=size, xy_min=xy_min, xy_res=xy_res, crs=crs, tile_size=source_gm.tile_size, is_j_axis_up=source_gm.is_j_axis_up) return target_gm.derive(xy_var_names=source_gm.xy_var_names, xy_dim_names=source_gm.xy_dim_names)
def test_transform(self): gm = GridMapping.regular(size=(3, 3), xy_min=(10, 53), xy_res=0.1, crs=CRS_CRS84) gm_t = gm.transform(crs=CRS_UTM_32N) self.assertEqual(CRS_UTM_32N, gm_t.crs) self.assertEqual(False, gm_t.is_regular) self.assertEqual(('transformed_x', 'transformed_y'), gm_t.xy_var_names) self.assertEqual(('lon', 'lat'), gm_t.xy_dim_names) np.testing.assert_almost_equal( np.array([ [570057.076286, 576728.9360228, 583400.7295284], [570220.3304187, 576907.7404859, 583595.0849538], [570383.3684844, 577086.3083212, 583789.1831954] ]), gm_t.xy_coords[0]) np.testing.assert_almost_equal( np.array([ [5900595.928991, 5900698.5746648, 5900810.5532744], [5889471.9033896, 5889574.6540572, 5889686.7472201], [5878348.0594403, 5878450.9138481, 5878563.1201969] ]), gm_t.xy_coords[1])
def test_rectify_2x2_to_default(self): source_ds = self.new_2x2_dataset_with_irregular_coords() target_gm = GridMapping.regular(size=(4, 4), xy_min=(-1, 49), xy_res=2, crs=CRS_WGS84) target_ds = rectify_dataset(source_ds, target_gm=target_gm) # target_ds = rectify_dataset(source_ds) rad = target_ds.rad # lon, lat, rad = self._assert_shape_and_dim(target_ds, (4, 4)) # np.testing.assert_almost_equal(lon.values, # np.array([0., 2., 4., 6.], # dtype=lon.dtype)) # np.testing.assert_almost_equal(lat.values, # np.array([56., 54., 52., 50.], # dtype=lat.dtype)) np.testing.assert_almost_equal( rad.values, np.array([[nan, nan, nan, nan], [nan, 1.0, 2.0, nan], [3.0, 3.0, 2.0, nan], [nan, 4.0, nan, nan]], dtype=rad.dtype))
def _rectify(input_path: str, xy_names: Optional[Tuple[str, str]], var_names: Optional[Sequence[str]], output_path: str, output_format: Optional[str], output_size: Optional[Tuple[int, int]], output_tile_size: Optional[Tuple[int, int]], output_point: Optional[Tuple[float, float]], output_res: Optional[float], output_crs: Optional[str], delta: float, dry_run: bool, monitor): import pyproj.crs from xcube.core.dsio import guess_dataset_format from xcube.core.dsio import open_dataset from xcube.core.dsio import write_dataset from xcube.core.gridmapping import GridMapping from xcube.core.resampling import rectify_dataset from xcube.core.sentinel3 import is_sentinel3_product from xcube.core.sentinel3 import open_sentinel3_product if not output_format: output_format = guess_dataset_format(output_path) output_gm = None output_gm_given = (output_size is not None, output_point is not None, output_res is not None, output_crs is not None) if all(output_gm_given): output_gm = GridMapping.regular(size=output_size, xy_min=output_point, xy_res=output_res, crs=pyproj.crs.CRS.from_user_input(output_crs)) elif any(output_gm_given): raise click.ClickException('SIZE, POINT, RES, and CRS must all be given or none of them.') monitor(f'Opening dataset from {input_path!r}...') if is_sentinel3_product(input_path): src_ds = open_sentinel3_product(input_path) else: src_ds = open_dataset(input_path) monitor('Rectifying...') rectified_ds = rectify_dataset(src_ds, xy_var_names=xy_names, var_names=var_names, target_gm=output_gm, tile_size=output_tile_size, uv_delta=delta) if rectified_ds is None: monitor(f'Dataset {input_path} does not seem to have an intersection with bounding box') return monitor(f'Writing rectified dataset to {output_path!r}...') if not dry_run: write_dataset(rectified_ds, output_path, output_format) monitor(f'Done.')
def test_xy_bbox(self): gm = GridMapping.regular((1000, 1000), (10, 53), 0.01, CRS_WGS84) self.assertEqual((10, 53, 20, 63), gm.xy_bbox) self.assertEqual(False, gm.is_lon_360)
def test_transform_xy_var_names(self): gm = GridMapping.regular(size=(3, 3), xy_min=(10, 53), xy_res=0.1, crs=CRS_CRS84) gm_t = gm.transform(crs=CRS_UTM_32N, xy_var_names=('x', 'y')) self.assertEqual(CRS_UTM_32N, gm_t.crs) self.assertEqual(('x', 'y'), gm_t.xy_var_names) self.assertEqual(('lon', 'lat'), gm_t.xy_dim_names)
def test_xy_bbox_anti_meridian(self): gm = GridMapping.regular((2000, 1000), (174.0, -30.0), 0.005, CRS_WGS84) self.assertEqual((174.0, -30.0, 184.0, -25.0), gm.xy_bbox) self.assertEqual(True, gm.is_lon_360)