diff --git a/CHANGES.md b/CHANGES.md index 2d2520e1..89a466b3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Release Notes +## 1.0.0a4 (2023-11-10) + +* add `algorithm` options for `/statistics [POST]` endpoints (back-ported from 0.8.1) + ## 1.0.0a3 (2023-11-03) * remove `reverse` option in `PGSTACBackend` mosaic backend. Reverse item order should be achieved with STAC search sortby. @@ -155,6 +159,10 @@ add_search_list_route(app) ``` +## 0.8.1 (2023-11-10) + +* add `algorithm` options for `/statistics [POST]` endpoints + ## 0.8.0 (2023-10-06) * update titiler requirement to `>=0.15.0,<0.16` diff --git a/tests/test_searches.py b/tests/test_searches.py index 9de06d31..bc32cad9 100644 --- a/tests/test_searches.py +++ b/tests/test_searches.py @@ -693,6 +693,23 @@ def test_statistics(rio, app, search_no_bbox, search_bbox): resp = response.json() assert resp["detail"] == "SearchId `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` not found" + # with Algorithm + response = app.post( + f"/searches/{search_no_bbox}/statistics", + json=feat, + params={ + "assets": "cog", + "max_size": 1024, + "algorithm": "normalizedIndex", + "asset_bidx": "cog|1,2", + }, + ) + assert response.status_code == 200 + assert response.headers["content-type"] == "application/geo+json" + resp = response.json() + stats = resp["features"][0]["properties"]["statistics"] + assert "(cog_b2 - cog_b1) / (cog_b2 + cog_b1)" in stats + def test_mosaic_list(app): """Test list mosaic.""" diff --git a/titiler/pgstac/factory.py b/titiler/pgstac/factory.py index 54ad53fa..bc5b9894 100644 --- a/titiler/pgstac/factory.py +++ b/titiler/pgstac/factory.py @@ -693,6 +693,7 @@ def geojson_statistics( dataset_params=Depends(self.dataset_dependency), image_params=Depends(self.img_part_dependency), pixel_selection=Depends(self.pixel_selection_dependency), + post_process=Depends(self.process_dependency), stats_params=Depends(self.stats_dependency), histogram_params=Depends(self.histogram_dependency), pgstac_params=Depends(self.pgstac_dependency), @@ -714,7 +715,7 @@ def geojson_statistics( for feature in fc: shape = feature.model_dump(exclude_none=True) - data, _ = src_dst.feature( + image, _ = src_dst.feature( shape, shape_crs=coord_crs or WGS84_CRS, dst_crs=dst_crs, @@ -726,12 +727,15 @@ def geojson_statistics( **pgstac_params, ) - coverage_array = data.get_coverage_array( + coverage_array = image.get_coverage_array( shape, shape_crs=coord_crs or WGS84_CRS, ) - stats = data.statistics( + if post_process: + image = post_process(image) + + stats = image.statistics( **stats_params, hist_options={**histogram_params}, coverage=coverage_array,