Skip to content

Commit

Permalink
Issue #567 initial fix for broken reduce_temporal after load_stac
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Jun 14, 2024
1 parent bb04cdc commit a71f3d8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion openeo/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,8 @@ def is_band_asset(asset: pystac.Asset) -> bool:

# TODO: conditionally include band dimension when there was actual indication of band metadata?
band_dimension = BandDimension(name="bands", bands=bands)
metadata = CubeMetadata(dimensions=[band_dimension])
# TODO: get actual temporal extent information from metadata (if any)
# TODO: is it possible to derive the actual name of temporal dimension that the backend will use?
temporal_dimension = TemporalDimension(name="t", extent=[None, None])
metadata = CubeMetadata(dimensions=[band_dimension, temporal_dimension])
return metadata
46 changes: 46 additions & 0 deletions tests/rest/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,52 @@ def test_load_stac_from_job_empty_result(self, con120, requests_mock):
}
}

def test_load_stac_reduce_temporal(self, con120, tmp_path):
# TODO: reusable utility to create/generate a STAC resource for testing
# (a file, but preferably a URL, but that requires urllib mocking)
stac_path = tmp_path / "stac.json"
stac_data = {
"type": "Collection",
"id": "test-collection",
"stac_version": "1.0.0",
"description": "Test collection",
"links": [],
"title": "Test Collection",
"extent": {
"spatial": {"bbox": [[-180.0, -90.0, 180.0, 90.0]]},
"temporal": {"interval": [["2020-01-01T00:00:00Z", "2020-01-10T00:00:00Z"]]},
},
"license": "proprietary",
"summaries": {"eo:bands": [{"name": "B01"}, {"name": "B02"}]},
}
stac_path.write_text(json.dumps(stac_data))

cube = con120.load_stac(str(stac_path))
reduced = cube.reduce_temporal("max")
assert reduced.flat_graph() == {
"loadstac1": {
"process_id": "load_stac",
"arguments": {"url": str(stac_path)},
},
"reducedimension1": {
"process_id": "reduce_dimension",
"arguments": {
"data": {"from_node": "loadstac1"},
"dimension": "t",
"reducer": {
"process_graph": {
"max1": {
"arguments": {"data": {"from_parameter": "data"}},
"process_id": "max",
"result": True,
}
}
},
},
"result": True,
},
}


@pytest.mark.parametrize(
"data",
Expand Down

0 comments on commit a71f3d8

Please sign in to comment.