Skip to content

Commit

Permalink
Merge pull request #143 from stac-utils/feat/algorithm-in-statistics-1.0
Browse files Browse the repository at this point in the history
enable algorithm in statistics endpoints
  • Loading branch information
vincentsarago authored Nov 10, 2023
2 parents 6008d1b + 47efa6e commit bd2a5fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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`
Expand Down
17 changes: 17 additions & 0 deletions tests/test_searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
10 changes: 7 additions & 3 deletions titiler/pgstac/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit bd2a5fe

Please sign in to comment.