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 resample_in_space #1115

Merged
merged 3 commits into from
Jan 27, 2025
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
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Changes in 1.8.1 (in development)

### Fixes

* Bug fix in `resample_in_space`: Resolved an issue where the `resample_in_space`
function no longer worked with irregular grid mappings, such as Sentinel-3 data,
due to changes introduced in version 1.8.0. (#1114)


## Changes in 1.8.0

### Enhancements
Expand Down
120 changes: 49 additions & 71 deletions examples/notebooks/resampling/affine.ipynb

Large diffs are not rendered by default.

89 changes: 48 additions & 41 deletions examples/notebooks/resampling/coords.ipynb

Large diffs are not rendered by default.

1,041 changes: 776 additions & 265 deletions examples/notebooks/resampling/rectify_dataset.ipynb

Large diffs are not rendered by default.

565 changes: 309 additions & 256 deletions examples/notebooks/resampling/resample_in_space.ipynb

Large diffs are not rendered by default.

147 changes: 81 additions & 66 deletions examples/notebooks/resampling/resample_ndimage.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/core/gridmapping/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_transform_xy_res(self):
self.assertEqual(
pyproj.CRS.from_string("EPSG:32633"), transformed_gm_regular.crs
)
self.assertEqual((266, 248), transformed_gm_regular.size)
self.assertEqual((267, 249), transformed_gm_regular.size)
self.assertEqual((200, 200), transformed_gm_regular.tile_size)
self.assertEqual((1000, 1000), transformed_gm_regular.xy_res)
self.assertEqual(False, transformed_gm_regular.is_j_axis_up)
Expand Down
39 changes: 5 additions & 34 deletions xcube/core/gridmapping/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,14 @@ def _transform(block: np.ndarray) -> np.ndarray:
dask="parallelized",
)
if xy_res is not None:
if grid_mapping.is_j_axis_up:
gm_ymin = grid_mapping.y_coords[0].values
gm_ymax = grid_mapping.y_coords[-1].values
else:
gm_ymin = grid_mapping.y_coords[-1].values
gm_ymax = grid_mapping.y_coords[0].values
y_min = np.min(
transformer.transform(
grid_mapping.x_coords.values,
np.repeat(gm_ymin, grid_mapping.size[0]),
)[1]
)
y_max = np.max(
transformer.transform(
grid_mapping.x_coords.values,
np.repeat(gm_ymax, grid_mapping.size[0]),
)[1]
)
x_min = np.min(
transformer.transform(
np.repeat(grid_mapping.x_coords[0].values, grid_mapping.size[1]),
grid_mapping.y_coords.values,
)[0]
)
x_max = np.max(
transformer.transform(
np.repeat(grid_mapping.x_coords[-1].values, grid_mapping.size[1]),
grid_mapping.y_coords.values,
)[0]
)
xy_bbox = transformer.transform_bounds(*grid_mapping.xy_bbox, densify_pts=101)
x_res, y_res = _normalize_number_pair(xy_res)
x_res_05, y_res_05 = x_res / 2, y_res / 2
xy_bbox = (
x_min - x_res_05,
y_min - y_res_05,
x_max + x_res_05,
y_max + y_res_05,
xy_bbox[0] - x_res_05,
xy_bbox[1] - y_res_05,
xy_bbox[2] + x_res_05,
xy_bbox[3] + y_res_05,
)
else:
xy_bbox = None
Expand Down
4 changes: 3 additions & 1 deletion xcube/core/resampling/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dask import array as da

from xcube.core.gridmapping import GridMapping
from xcube.core.gridmapping.coords import Coords2DGridMapping
from xcube.core.gridmapping.helpers import scale_xy_res_and_size
from .affine import affine_transform_dataset
from .affine import resample_dataset
Expand Down Expand Up @@ -208,7 +209,8 @@ def resample_in_space(
# If CRSes are not both geographic and their CRSes are different
# transform the source_gm so its CRS matches the target CRS:
transformed_source_gm = source_gm.transform(target_gm.crs, xy_res=target_gm.xy_res)
source_ds = source_ds.drop_vars(source_gm.xy_dim_names)
if not isinstance(source_gm, Coords2DGridMapping):
source_ds = source_ds.drop_vars(source_gm.xy_dim_names)
list_grid_mapping = []
for var in source_ds.data_vars:
if "grid_mapping" in source_ds[var].attrs:
Expand Down
2 changes: 1 addition & 1 deletion xcube/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Permissions are hereby granted under the terms of the MIT License:
# https://opensource.org/licenses/MIT.

version = "1.8.0"
version = "1.8.1.dev0"
Loading