Skip to content

Commit

Permalink
respect layercatalog bands order #460
Browse files Browse the repository at this point in the history
  • Loading branch information
bossie committed May 2, 2024
1 parent 34474f8 commit 99cc858
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 58 deletions.
2 changes: 1 addition & 1 deletion openeogeotrellis/layercatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def file_agera5_pyramid():
elif layer_source_type == 'stac':
cube = load_stac(layer_source_info["url"], load_params, env,
layer_properties=metadata.get("_vito", "properties", default={}),
batch_jobs=None)
batch_jobs=None, override_band_names=metadata.band_names)
pyramid = cube.pyramid.levels
metadata = cube.metadata
elif layer_source_type == 'accumulo':
Expand Down
7 changes: 5 additions & 2 deletions openeogeotrellis/load_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@


def load_stac(url: str, load_params: LoadParameters, env: EvalEnv, layer_properties: Dict[str, object],
batch_jobs: Optional[backend.BatchJobs]) -> GeopysparkDataCube:
batch_jobs: Optional[backend.BatchJobs], override_band_names: List[str] = None) -> GeopysparkDataCube:
if override_band_names is None:
override_band_names = []

logger.info("load_stac from url {u!r} with load params {p!r}".format(u=url, p=load_params))

no_data_available_exception = OpenEOApiException(message="There is no data available for the given extents.",
Expand Down Expand Up @@ -368,7 +371,7 @@ def intersects_temporally(interval) -> bool:
# TODO: detect actual dimensions instead of this simple default?
SpatialDimension(name="x", extent=[]), SpatialDimension(name="y", extent=[]),
TemporalDimension(name='t', extent=[]),
BandDimension(name="bands", bands=[Band(band_name) for band_name in band_names])
BandDimension(name="bands", bands=[Band(band_name) for band_name in (override_band_names or band_names)])
])

if load_params.bands:
Expand Down
50 changes: 1 addition & 49 deletions tests/layercatalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -1427,20 +1427,8 @@
"bands": {
"type": "bands",
"values": [
"SOSD",
"EOSD",
"MAXD",
"SOSV",
"EOSV",
"MINV",
"MAXV",
"AMPL",
"LENGTH",
"LSLOPE",
"RSLOPE",
"SPROD",
"TPROD",
"QFLAG"
"TPROD"
]
}
},
Expand All @@ -1454,47 +1442,11 @@
},
"summaries": {
"eo:bands": [
{
"name": "SOSD"
},
{
"name": "EOSD"
},
{
"name": "MAXD"
},
{
"name": "SOSV"
},
{
"name": "EOSV"
},
{
"name": "MINV"
},
{
"name": "MAXV"
},
{
"name": "AMPL"
},
{
"name": "LENGTH"
},
{
"name": "LSLOPE"
},
{
"name": "RSLOPE"
},
{
"name": "SPROD"
},
{
"name": "TPROD"
},
{
"name": "QFLAG"
}
]
}
Expand Down
15 changes: 9 additions & 6 deletions tests/test_load_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,11 @@ def test_data_cube_params(catalog):
assert "Average" == str(cube_params.resampleMethod())


def test_load_stac_collection_with_property_filters(catalog, tmp_path, requests_mock):
@pytest.mark.parametrize(["bands", "expected_bands"], [
([], ["SPROD", "TPROD"]), # ordered as specified in layercatalog.json
(["TPROD", "SPROD"], ["TPROD", "SPROD"]) # override order
])
def test_load_stac_collection_with_property_filters(catalog, tmp_path, requests_mock, bands, expected_bands):
requests_mock.get("https://stac.openeo.vito.be/", text=get_test_data_file("stac/issue640-api-layer-property-filter/stac.openeo.vito.be.json").read_text())
requests_mock.get("https://stac.openeo.vito.be/search", [
{'text': get_test_data_file("stac/issue640-api-layer-property-filter/copernicus_r_utm-wgs84_10_m_hrvpp-vpp_p_2017-now_v01_features.json")
Expand All @@ -492,7 +496,7 @@ def test_load_stac_collection_with_property_filters(catalog, tmp_path, requests_

load_params = LoadParameters(spatial_extent={"west": 5.00, "south": 51.20, "east": 5.01, "north": 51.21},
temporal_extent=["2017-07-01T00:00Z", "2018-07-31T00:00Z"],
bands=["SPROD", "TPROD"]) # TODO: remove other bands from layercatalog.json, then drop this bands argument
bands=bands)

env = EvalEnv({'pyramid_levels': 'highest', 'user': None})

Expand All @@ -503,7 +507,6 @@ def test_load_stac_collection_with_property_filters(catalog, tmp_path, requests_
data_cube.save_result(output_file, format="GTiff")

with rasterio.open(output_file) as ds:
expected_band_count = 2
assert ds.count == expected_band_count
assert ds.tags(1)["DESCRIPTION"] == "SPROD"
assert ds.tags(2)["DESCRIPTION"] == "TPROD"
assert ds.count == len(expected_bands)
for band_index, band_name in enumerate(expected_bands):
assert ds.tags(band_index + 1)["DESCRIPTION"] == expected_bands[band_index]

0 comments on commit 99cc858

Please sign in to comment.