-
Notifications
You must be signed in to change notification settings - Fork 49
Respect STAC cube:dimensions as source of truth in metadata_from_stac + align tests with dimension policy #867
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
base: master
Are you sure you want to change the base?
Changes from all commits
ccd7f23
b49026b
b9abf3b
d83208c
f77982c
ad706de
833d1e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1156,7 +1156,10 @@ def test_metadata_from_stac_bands(tmp_path, test_stac, expected): | |
| # TODO #738 real request mocking of STAC resources compatible with pystac? | ||
| path.write_text(json.dumps(test_stac)) | ||
| metadata = metadata_from_stac(str(path)) | ||
| assert metadata.band_names == expected | ||
| if expected: | ||
| assert metadata.band_names == expected | ||
| else: | ||
| assert not metadata.has_band_dimension() | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -1253,7 +1256,73 @@ def test_metadata_from_stac_temporal_dimension(tmp_path, stac_dict, expected): | |
| assert isinstance(dim, TemporalDimension) | ||
| assert (dim.name, dim.extent) == expected | ||
| else: | ||
| assert not metadata.has_temporal_dimension() | ||
| # With openEO defaults, a temporal dimension name ('t') can exist even when extent is unknown. | ||
suriyahgit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Depending on STAC input, pystac/datacube parsing can produce: | ||
| # - a degenerate extent [d, d] when a single `datetime` is present | ||
| # - an "unknown" extent [None, None] when there is no temporal info | ||
| assert metadata.has_temporal_dimension() | ||
| extent = metadata.temporal_dimension.extent | ||
| if extent is None: | ||
| pass | ||
| else: | ||
| assert isinstance(extent, list) and len(extent) == 2 | ||
| # Allow "unknown" temporal extent representation | ||
| if extent == [None, None]: | ||
| pass | ||
| else: | ||
| # Allow degenerate interval when a single datetime is available | ||
| assert extent[0] == extent[1] | ||
|
|
||
|
|
||
|
|
||
| # Dimension name resolution policy (STAC cube:dimensions vs openEO defaults) | ||
suriyahgit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @pytest.mark.parametrize( | ||
| ["stac_dict", "expected_dims"], | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can a STAC 1.1 style test case be added which uses the new 'bands' common metadata and no datacube extension? |
||
| [ | ||
| ( | ||
| # No cube:dimensions -> fall back to openEO default naming convention | ||
| StacDummyBuilder.collection(summaries={"eo:bands": [{"name": "B01"}]}), | ||
| {"t", "bands", "y", "x"}, | ||
| ), | ||
| ( | ||
| # No cube:dimensions (item) -> fall back to openEO default naming convention | ||
| StacDummyBuilder.item( | ||
| properties={"datetime": "2020-05-22T00:00:00Z", "eo:bands": [{"name": "B01"}]} | ||
| ), | ||
| {"t", "bands", "y", "x"}, | ||
| ), | ||
| ( | ||
| # cube:dimensions present -> use the dimension names as suggested by cube:dimensions keys | ||
| StacDummyBuilder.collection( | ||
| cube_dimensions={ | ||
| "time": {"type": "temporal", "axis": "t", "extent": ["2024-04-04", "2024-06-06"]}, | ||
| "band": {"type": "bands", "axis": "bands", "values": ["B01"]}, | ||
| "y": {"type": "spatial", "axis": "y", "extent": [0, 1]}, | ||
| "x": {"type": "spatial", "axis": "x", "extent": [0, 1]}, | ||
| } | ||
| ), | ||
| {"time", "band", "y", "x"}, | ||
| ), | ||
| ], | ||
| ) | ||
| def test_metadata_from_stac_dimension_policy_cube_dimensions_vs_default(tmp_path, stac_dict, expected_dims): | ||
| path = tmp_path / "stac.json" | ||
| # TODO #738 real request mocking of STAC resources compatible with pystac? | ||
| path.write_text(json.dumps(stac_dict)) | ||
| metadata = metadata_from_stac(str(path)) | ||
|
|
||
| got = tuple(metadata.dimension_names() or ()) | ||
|
|
||
| # Order-insensitive check: names only | ||
| assert set(got) == expected_dims | ||
|
|
||
| # Ensure the policy logic is exercised correctly: | ||
| # cube:dimensions can be located at root (collection) or in properties (item) | ||
| cube_dims = stac_dict.get("cube:dimensions") or (stac_dict.get("properties") or {}).get("cube:dimensions") | ||
| if cube_dims is None: | ||
| assert set(got) == {"t", "bands", "y", "x"} | ||
| else: | ||
| assert set(got) == set(cube_dims.keys()) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.