Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable algorithm in statistics endpoints #143

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading