From 6f2e3e76616c8e801fab91c39b2a2b56a5b7279e Mon Sep 17 00:00:00 2001 From: konstntokas Date: Fri, 20 Sep 2024 10:18:27 +0200 Subject: [PATCH 1/2] bug fix in resampling_in_space --- CHANGES.md | 2 ++ test/core/gridmapping/test_base.py | 22 ++++++++++++++++++++++ xcube/core/gridmapping/regular.py | 6 +++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d4c356333..f1d8214d3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ * The `/statistics` endpoint now supports datasets using non-WGS84 grid systems, expanding its compatibility with a wider range of geospatial datasets. (#1069) +* Bug fix in `resampling_in_space` when projecting from geographic to non-geografic + projection. (#1073) ## Changes in 1.7.0 diff --git a/test/core/gridmapping/test_base.py b/test/core/gridmapping/test_base.py index a102429be..2d2efe0d2 100644 --- a/test/core/gridmapping/test_base.py +++ b/test/core/gridmapping/test_base.py @@ -318,6 +318,28 @@ def test_transform(self): ) self.assertEqual(("lon", "lat"), transformed_gm.xy_dim_names) + def test_to_regular(self): + gm = _TestGridMapping( + **self.kwargs( + xy_min=(9.6, 47.6), + size=(1000, 1000), + tile_size=(1000, 1000), + xy_res=(0.0002, 0.0002), + ) + ) + transformed_gm = gm.transform("EPSG:32633") + transformed_gm_regular = transformed_gm.to_regular() + + self.assertIsNot(gm, transformed_gm_regular) + self.assertIsInstance(transformed_gm_regular, RegularGridMapping) + self.assertEqual( + pyproj.CRS.from_string("EPSG:32633"), transformed_gm_regular.crs + ) + self.assertEqual((827, 1163), transformed_gm_regular.size) + self.assertEqual((827, 1163), transformed_gm_regular.tile_size) + self.assertEqual(False, transformed_gm_regular.is_j_axis_up) + self.assertEqual(False, transformed_gm_regular.is_lon_360) + def test_is_close(self): gm1 = _TestGridMapping( **self.kwargs(xy_min=(0, 0), size=(400, 200), xy_res=(0.01, 0.01)) diff --git a/xcube/core/gridmapping/regular.py b/xcube/core/gridmapping/regular.py index 0755b7371..a65bd8037 100644 --- a/xcube/core/gridmapping/regular.py +++ b/xcube/core/gridmapping/regular.py @@ -66,7 +66,7 @@ def new_regular_grid_mapping( crs: Union[str, pyproj.crs.CRS], *, tile_size: Union[int, tuple[int, int]] = None, - is_j_axis_up: bool = False + is_j_axis_up: bool = False, ) -> GridMapping: width, height = _normalize_int_pair(size, name="size") assert_true(width > 1 and height > 1, "invalid size") @@ -99,7 +99,7 @@ def new_regular_grid_mapping( xy_res=(x_res, y_res), xy_var_names=_default_xy_var_names(crs), xy_dim_names=_default_xy_dim_names(crs), - is_lon_360=x_max > 180, + is_lon_360=(x_max > 180) and crs.is_geographic, is_j_axis_up=is_j_axis_up, ) @@ -108,7 +108,7 @@ def to_regular_grid_mapping( grid_mapping: GridMapping, *, tile_size: Union[int, tuple[int, int]] = None, - is_j_axis_up: bool = False + is_j_axis_up: bool = False, ) -> GridMapping: if grid_mapping.is_regular: if tile_size is not None or is_j_axis_up != grid_mapping.is_j_axis_up: From 0842cdb0398fd107967849348ef2d549ae8dd1c6 Mon Sep 17 00:00:00 2001 From: Konstantin Ntokas <38956538+konstntokas@users.noreply.github.com> Date: Fri, 20 Sep 2024 10:58:24 +0200 Subject: [PATCH 2/2] Update CHANGES.md Co-authored-by: yogeshkumar94 --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f1d8214d3..def0bce7e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,7 +7,7 @@ * The `/statistics` endpoint now supports datasets using non-WGS84 grid systems, expanding its compatibility with a wider range of geospatial datasets. (#1069) -* Bug fix in `resampling_in_space` when projecting from geographic to non-geografic +* Bug fix in `resampling_in_space` when projecting from geographic to non-geographic projection. (#1073) ## Changes in 1.7.0