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

resample_(cube_)spatial: support metadata transform #690

Closed
jdries opened this issue Dec 18, 2024 · 8 comments · Fixed by #712
Closed

resample_(cube_)spatial: support metadata transform #690

jdries opened this issue Dec 18, 2024 · 8 comments · Fixed by #712

Comments

@jdries
Copy link
Collaborator

jdries commented Dec 18, 2024

The cube metadata classes currently do not support resampling the spatial dimension. As a consequence, this metadata is incorrect and misaligned with the actual state on the server.
Server-side, the same problem exists in our 'dry-run' setup: no resampling, so incorrect metadata.

By implementing this in this repo, we can solve both problems at once.
For the user, better client metadata for cubes gives another means to detect issues early.

@VictorVerhaert
Copy link
Contributor

This issue (and mainly its related fix to the backend) is relevant for EUGW as one pipeline produces incorrect results when reprojecting

@soxofaan
Copy link
Member

Is there any pointer to a concrete use case or snippet where this goes wrong?

@VictorVerhaert
Copy link
Contributor

Here is a job-id that gives incorrect results: j-2501091523364ccc8d462ddee1e5b385

@soxofaan
Copy link
Member

can you also comment on what is wrong with the result (what you get versus what you expect)?

@JeroenVerstraelen
Copy link
Contributor

@VictorVerhaert
Copy link
Contributor

What I get: (spatial extent in latlon followed by resample to 3035)

Image

What I expect: (spatial extent in 3035 followed by resample to 3035)

Image

(view is in EPSG:3035)

@VictorVerhaert
Copy link
Contributor

python code to recreate the above images:

import openeo
import pyproj
from pathlib import Path

# establish connection to OpenEO backend
connection = (openeo.connect("openeo.dataspace.copernicus.eu"))
connection.authenticate_oidc()

root_dir = Path(__file__).parent / "base_case"
if not root_dir.exists():
    root_dir.mkdir()

# define start date and end date
start_date = "2022-01-01"
end_date = "2022-12-31"

def reproject_extent(extent, from_epsg, to_epsg):
    transformer = pyproj.Transformer.from_crs(f"epsg:{from_epsg}", f"epsg:{to_epsg}", always_xy=True)
    west, south = transformer.transform(extent['west'], extent['south'])
    east, north = transformer.transform(extent['east'], extent['north'])
    return {'west': west, 'south': south, 'east': east, 'north': north, 'crs': f"epsg:{to_epsg}"}

original_spatial_extent = {'west': 19.893982316864847, 'south': 49.16379666241664, 'east': 20.125833976862033, 'north': 49.31558120075986}
reprojected_spatial_extent = reproject_extent(original_spatial_extent, 4326, 3035)

cube_original_crs = connection.load_collection(
        collection_id="COPERNICUS_VEGETATION_PHENOLOGY_PRODUCTIVITY_10M_SEASON1",
        temporal_extent=[start_date, end_date],
        bands=["SPROD"],
        spatial_extent=original_spatial_extent
).resample_spatial(resolution=10, projection=3035, method="bilinear")
cube_original_crs.download(root_dir / "cube_original_crs.tif")

cube_projected_crs = connection.load_collection(
        collection_id="COPERNICUS_VEGETATION_PHENOLOGY_PRODUCTIVITY_10M_SEASON1",
        temporal_extent=[start_date, end_date],
        bands=["SPROD"],
        spatial_extent=reprojected_spatial_extent
).resample_spatial(resolution=10, projection=3035, method="bilinear")
cube_projected_crs.download(root_dir / "cube_projected_crs.tif")

@soxofaan
Copy link
Member

started with pull request #712

soxofaan added a commit that referenced this issue Jan 23, 2025
soxofaan added a commit that referenced this issue Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants