-
Notifications
You must be signed in to change notification settings - Fork 44
made load_stac nicer to mismatch in band names #755
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
Changes from 5 commits
2c04f73
66ea570
1446f44
56e0731
4d350c4
5d9b6d4
83ef8eb
c344264
1868c22
371eee5
9c5a6d5
df7f662
494b44a
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 | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2957,7 +2957,40 @@ def test_load_stac_no_cube_extension_temporal_dimension(self, con120, tmp_path, | |||||||||||||||||||||||||||
cube = con120.load_stac(str(stac_path)) | ||||||||||||||||||||||||||||
assert cube.metadata.temporal_dimension == TemporalDimension(name="t", extent=dim_extent) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def test_load_stac_band_filtering(self, con120, tmp_path): | ||||||||||||||||||||||||||||
@pytest.mark.parametrize( | ||||||||||||||||||||||||||||
"bands, expected_warning", | ||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||
( | ||||||||||||||||||||||||||||
["B04"], | ||||||||||||||||||||||||||||
"The specified bands ['B04'] are not a subset of the bands ['B01', 'B02', 'B03'] found in the STAC metadata (unknown bands: ['B04']). Using specified bands as is.", | ||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||
( | ||||||||||||||||||||||||||||
["B03", "B04", "B05"], | ||||||||||||||||||||||||||||
"The specified bands ['B03', 'B04', 'B05'] are not a subset of the bands ['B01', 'B02', 'B03'] found in the STAC metadata (unknown bands: ['B04', 'B05']). Using specified bands as is.", | ||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||
(["B03", "B02"], None), | ||||||||||||||||||||||||||||
(["B01", "B02", "B03"], None), | ||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
def test_load_stac_band_filtering(self, con120, tmp_path, caplog, bands, expected_warning): | ||||||||||||||||||||||||||||
stac_path = tmp_path / "stac.json" | ||||||||||||||||||||||||||||
stac_data = StacDummyBuilder.collection( | ||||||||||||||||||||||||||||
summaries={"eo:bands": [{"name": "B01"}, {"name": "B02"}, {"name": "B03"}]} | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
# TODO #738 real request mocking of STAC resources compatible with pystac? | ||||||||||||||||||||||||||||
stac_path.write_text(json.dumps(stac_data)) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
caplog.set_level(logging.WARNING) | ||||||||||||||||||||||||||||
# Test with non-existing bands in the collection metadata | ||||||||||||||||||||||||||||
cube = con120.load_stac(str(stac_path), bands=bands) | ||||||||||||||||||||||||||||
assert cube.metadata.band_names == bands | ||||||||||||||||||||||||||||
if expected_warning is None: | ||||||||||||||||||||||||||||
assert caplog.text == "" | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
assert expected_warning in caplog.text | ||||||||||||||||||||||||||||
caplog.clear() | ||||||||||||||||||||||||||||
soxofaan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def test_load_stac_band_filtering_no_requested_bands(self, con120, tmp_path): | ||||||||||||||||||||||||||||
stac_path = tmp_path / "stac.json" | ||||||||||||||||||||||||||||
stac_data = StacDummyBuilder.collection( | ||||||||||||||||||||||||||||
summaries={"eo:bands": [{"name": "B01"}, {"name": "B02"}, {"name": "B03"}]} | ||||||||||||||||||||||||||||
|
@@ -2968,8 +3001,24 @@ def test_load_stac_band_filtering(self, con120, tmp_path): | |||||||||||||||||||||||||||
cube = con120.load_stac(str(stac_path)) | ||||||||||||||||||||||||||||
assert cube.metadata.band_names == ["B01", "B02", "B03"] | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
cube = con120.load_stac(str(stac_path), bands=["B03", "B02"]) | ||||||||||||||||||||||||||||
assert cube.metadata.band_names == ["B03", "B02"] | ||||||||||||||||||||||||||||
def test_load_stac_band_filtering_no_metadata(self, con120, tmp_path, caplog): | ||||||||||||||||||||||||||||
stac_path = tmp_path / "stac.json" | ||||||||||||||||||||||||||||
stac_data = StacDummyBuilder.collection() | ||||||||||||||||||||||||||||
# TODO #738 real request mocking of STAC resources compatible with pystac? | ||||||||||||||||||||||||||||
stac_path.write_text(json.dumps(stac_data)) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
cube = con120.load_stac(str(stac_path)) | ||||||||||||||||||||||||||||
assert cube.metadata.band_names == [] | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
caplog.set_level(logging.WARNING) | ||||||||||||||||||||||||||||
cube = con120.load_stac(str(stac_path), bands=["B01", "B02"]) | ||||||||||||||||||||||||||||
assert cube.metadata.band_names == ["B01", "B02"] | ||||||||||||||||||||||||||||
assert ( | ||||||||||||||||||||||||||||
"The specified bands ['B01', 'B02'] are not a subset of the bands [] found in the STAC metadata (unknown bands: ['B01', 'B02']). Using specified bands as is." | ||||||||||||||||||||||||||||
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.
hmm I'm a bit confused here: if there is no band dimension, doesn't the 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. openeo-python-client/openeo/metadata.py Lines 619 to 624 in 4d350c4
openeo-python-client/openeo/metadata.py Line 676 in 4d350c4
So I guess there isn't a case where the metadata has no bands dimension. I'll remove openeo-python-client/openeo/rest/datacube.py Lines 447 to 452 in 4d350c4
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.
not yet, but that will be possible in the future with #743 |
||||||||||||||||||||||||||||
in caplog.text | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
caplog.clear() | ||||||||||||||||||||||||||||
VictorVerhaert marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
VictorVerhaert marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@pytest.mark.parametrize( | ||||||||||||||||||||||||||||
"bands", | ||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.