-
Notifications
You must be signed in to change notification settings - Fork 51
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
64a1423
2dd590d
954fe02
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 |
|---|---|---|
|
|
@@ -1159,6 +1159,27 @@ def test_metadata_from_stac_bands(tmp_path, test_stac, expected): | |
| assert metadata.band_names == expected | ||
|
|
||
|
|
||
| def test_metadata_from_stac_stac_1_1_common_bands_without_datacube_extension(tmp_path): | ||
| stac_dict = StacDummyBuilder.collection( | ||
| stac_version="1.1.0", | ||
| bands=[ | ||
| {"name": "red", "eo:common_name": "red", "eo:center_wavelength": 0.665}, | ||
| {"name": "nir", "eo:common_name": "nir", "eo:center_wavelength": 0.842}, | ||
| ], | ||
| ) | ||
| assert "stac_extensions" not in stac_dict | ||
| assert "cube:dimensions" not in stac_dict | ||
|
|
||
| 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)) | ||
|
|
||
| assert metadata.dimension_names() == ["x", "y", "bands", "t"] | ||
| assert metadata.band_names == ["red", "nir"] | ||
| assert metadata.band_dimension.bands[0].common_name == "red" | ||
| assert metadata.band_dimension.bands[1].wavelength_um == 0.842 | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not _PYSTAC_1_9_EXTENSION_INTERFACE, reason="Requires PySTAC 1.9+ extension interface") | ||
| @pytest.mark.parametrize( | ||
|
|
@@ -1210,7 +1231,17 @@ def test_metadata_from_stac_collection_bands_from_item_assets( | |
| [ | ||
| ( | ||
| StacDummyBuilder.item(), | ||
| None, | ||
| ("t", ["2024-03-08", "2024-03-08"]), | ||
| ), | ||
| ( | ||
| StacDummyBuilder.item( | ||
| properties={ | ||
| "datetime": "2024-03-08T00:00:00Z", | ||
| "start_datetime": "2024-04-04T00:00:00Z", | ||
| "end_datetime": "2024-06-06T00:00:00Z", | ||
| } | ||
| ), | ||
| ("t", ["2024-04-04T00:00:00Z", "2024-06-06T00:00:00Z"]), | ||
| ), | ||
| ( | ||
| StacDummyBuilder.item(cube_dimensions={"t": {"type": "temporal", "extent": ["2024-04-04", "2024-06-06"]}}), | ||
|
|
@@ -1256,6 +1287,69 @@ def test_metadata_from_stac_temporal_dimension(tmp_path, stac_dict, expected): | |
| assert not metadata.has_temporal_dimension() | ||
|
|
||
|
|
||
|
|
||
| # Dimension name resolution policy (STAC cube:dimensions vs openEO defaults) | ||
|
suriyahgit marked this conversation as 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?
Member
Author
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. Added a STAC 1.1 |
||
| [ | ||
| ( | ||
| # 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"}, | ||
| ), | ||
| ( | ||
| # cube:dimensions present without band dimension -> don't inject an openEO "bands" dimension | ||
| StacDummyBuilder.collection( | ||
| summaries={"eo:bands": [{"name": "B01"}]}, | ||
| cube_dimensions={ | ||
| "time": {"type": "temporal", "axis": "t", "extent": ["2024-04-04", "2024-06-06"]}, | ||
| "y": {"type": "spatial", "axis": "y", "extent": [0, 1]}, | ||
| "x": {"type": "spatial", "axis": "x", "extent": [0, 1]}, | ||
| }, | ||
| ), | ||
| {"time", "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( | ||
| ["kwargs", "expected_x", "expected_y"], | ||
| [ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.