From d1c55d1dd12cc409eb7c9a537f8b79b74abeff5e Mon Sep 17 00:00:00 2001 From: Jeroen Dries Date: Fri, 19 Apr 2024 14:35:34 +0200 Subject: [PATCH] load_stac got a bit more accurate https://github.com/Open-EO/openeo-geotrellis-extensions/issues/282 https://github.com/Open-EO/openeo-geotrellis-extensions/issues/284 --- openeogeotrellis/load_stac.py | 3 ++- tests/test_api_result.py | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/openeogeotrellis/load_stac.py b/openeogeotrellis/load_stac.py index 72b3c5c5..1cacce22 100644 --- a/openeogeotrellis/load_stac.py +++ b/openeogeotrellis/load_stac.py @@ -297,6 +297,7 @@ def intersects_temporally(interval) -> bool: builder = builder.withResolution(cell_width) latlon_bbox = BoundingBox.from_wsen_tuple(itm.bbox,4326) if itm.bbox else None + item_bbox = latlon_bbox if proj_bbox is not None and proj_epsg is not None: item_bbox = BoundingBox.from_wsen_tuple(proj_bbox, crs=proj_epsg) latlon_bbox = item_bbox.reproject(4326) @@ -308,7 +309,7 @@ def intersects_temporally(interval) -> bool: opensearch_client.addFeature(f) - stac_bbox = (latlon_bbox if stac_bbox is None + stac_bbox = (item_bbox if stac_bbox is None else BoundingBox.from_wsen_tuple(item_bbox.as_polygon().union(stac_bbox.as_polygon()).bounds, stac_bbox.crs)) diff --git a/tests/test_api_result.py b/tests/test_api_result.py index 7f361b84..167e58bd 100644 --- a/tests/test_api_result.py +++ b/tests/test_api_result.py @@ -3860,14 +3860,14 @@ def item_json(path): ds = xarray.load_dataset(res_path) - assert ds.dims["x"] == 13010 - assert ds.dims["y"] == 773 + assert ds.dims["x"] == 12987 + assert ds.dims["y"] == 767 # TODO: there's a "t" dimension that corresponds to the start_datetime of the two items; is this right? assert list(ds.data_vars.keys())[1:] == ["B04", "B03", "B02"] - assert ds.coords["x"].values.min() == pytest.approx(572400.000, abs=10) - assert ds.coords["y"].values.min() == pytest.approx(5618660.000, abs=10) - assert ds.coords["x"].values.max() == pytest.approx(702500.000, abs=10) - assert ds.coords["y"].values.max() == pytest.approx(5626390.000, abs=10) + assert ds.coords["x"].values.min() == pytest.approx(572465.000, abs=10) + assert ds.coords["y"].values.min() == pytest.approx(5618675.000, abs=10) + assert ds.coords["x"].values.max() == pytest.approx(702325.000, abs=10) + assert ds.coords["y"].values.max() == pytest.approx(5626335.000, abs=10) def test_load_stac_from_spatiotemporal_netcdf_job_results(self, api110, urllib_mock, tmp_path):