Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix in resampling_in_space #1074

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-geographic
projection. (#1073)

## Changes in 1.7.0

Expand Down
22 changes: 22 additions & 0 deletions test/core/gridmapping/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions xcube/core/gridmapping/regular.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
)

Expand All @@ -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:
Expand Down
Loading