Skip to content

load_stac + resample_spatial incompatibility #737

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

Closed
soxofaan opened this issue Feb 21, 2025 · 6 comments · May be fixed by #739
Closed

load_stac + resample_spatial incompatibility #737

soxofaan opened this issue Feb 21, 2025 · 6 comments · May be fixed by #739
Assignees
Labels

Comments

@soxofaan
Copy link
Member

minimal reproduction example:

import openeo
connection = openeo.connect(url="openeo.dataspace.copernicus.eu")

cube = connection.load_stac("https://stac.openeo.vito.be/collections/wenr_features")
cube.resample_spatial(projection=3035, resolution=10.0)

gives

MetadataException: Expected two spatial dimensions but found spatial_indices=[]

Current load_stac implementation only detects:

>>> cube.metadata.dimension_names()
['bands', 't']

and resample_spatial expects spatial dimensions to work on

@soxofaan soxofaan added the bug label Feb 21, 2025
@soxofaan
Copy link
Member Author

Solution would be to make sure that DataCube.load_stac adds the spatial dimensions to the client side metadata when necessary (probably just always, or when the raster/eo extensions are present)

@soxofaan soxofaan self-assigned this Feb 21, 2025
@VictorVerhaert
Copy link
Contributor

@soxofaan I think the python clinent should be as flexible as possible with incoming stac collections, and always result in datacube with spatial, temporal and band dimensions unless the stac item contains a datacube extension that states otherwise.
If a stac collection cannot be reached the results should be some default (empty) metadata as well.

@VincentVerelst this might be relevant for the datacube dimensions question you had

soxofaan added a commit that referenced this issue Feb 24, 2025
This is not perfect, but at least a quick fix for common use cases
@soxofaan
Copy link
Member Author

quickfixed this with 05b527f:
indeed always assume presence of spatial dimensions, which should resolve the problem for common use cases

@soxofaan
Copy link
Member Author

Reopening to align spatial dimension detection with the approach for temporal dim:

def get_temporal_dimension(self, stac_obj: pystac.STACObject) -> Union[TemporalDimension, None]:
"""
Extract the temporal dimension from a STAC Collection/Item (if any)
"""
# TODO: also extract temporal dimension from assets?
if _PYSTAC_1_9_EXTENSION_INTERFACE:
if stac_obj.ext.has("cube") and hasattr(stac_obj.ext, "cube"):
temporal_dims = [
(n, d.extent or [None, None])
for (n, d) in stac_obj.ext.cube.dimensions.items()
if d.dim_type == pystac.extensions.datacube.DimensionType.TEMPORAL
]
if len(temporal_dims) == 1:
name, extent = temporal_dims[0]
return TemporalDimension(name=name, extent=extent)

@soxofaan
Copy link
Member Author

started PR #739 to leverage pystac for better spatial dimension detection

@soxofaan
Copy link
Member Author

I'm going to close this ticket, as the remaining work is now actually topic of

@soxofaan soxofaan linked a pull request Feb 26, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants