Skip to content

Commit

Permalink
allow bidx option in multibasetiler (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago authored Nov 6, 2023
1 parent 75c94de commit fa88732
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 21 deletions.
36 changes: 36 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Release Notes

## 0.15.4 (2023-11-06)

### titiler.core

* update `rio-tiler` requirement to `>=6.2.5,<7.0`

* allow `bidx` option in `titiler.core.dependencies.AssetsBidxExprParams` and `titiler.core.dependencies.AssetsBidxParams`

```python
# merge band 1 form asset1 and asset2
# before
httpx.get(
"/stac/preview",
params=(
("url", "stac.json"),
("assets", "asset1"),
("assets", "asset2"),
("asset_bidx", "asset1|1"),
("asset_bidx", "asset2|1"),
)
)

# now
httpx.get(
"/stac/preview",
params=(
("url", "stac.json"),
("assets", "asset1"),
("assets", "asset2"),
("bidx", 1),
)
)
```

* fix openapi examples

## 0.15.3 (2023-11-02)

* add `dst_crs` options in `/statistics [POST]` and `/feature [POST]` endpoints
Expand Down
18 changes: 9 additions & 9 deletions docs/src/advanced/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AssetsParams(DefaultDependency):
None,
title="Asset names",
description="Asset's names.",
examples={
openapi_examples={
"one-asset": {
"description": "Return results for asset `data`.",
"value": ["data"],
Expand Down Expand Up @@ -96,7 +96,7 @@ class AssetsBidxParams(AssetsParams):
title="Per asset band indexes",
description="Per asset band indexes",
alias="asset_bidx",
examples={
openapi_examples={
"one-asset": {
"description": "Return indexes 1,2,3 of asset `data`.",
"value": ["data|1;2;3"],
Expand All @@ -114,7 +114,7 @@ class AssetsBidxParams(AssetsParams):
Query(
title="Per asset band expression",
description="Per asset band expression",
examples={
openapi_examples={
"one-asset": {
"description": "Return results for expression `b1*b2+b3` of asset `data`.",
"value": ["data|b1*b2+b3"],
Expand Down Expand Up @@ -168,7 +168,7 @@ class AssetsBidxExprParams(AssetsParams):
Query(
title="Band Math expression",
description="Band math expression between assets",
examples={
openapi_examples={
"simple": {
"description": "Return results of expression between assets.",
"value": "asset1_b1 + asset2_b1 / asset3_b1",
Expand All @@ -183,7 +183,7 @@ class AssetsBidxExprParams(AssetsParams):
title="Per asset band indexes",
description="Per asset band indexes (coma separated indexes)",
alias="asset_bidx",
examples={
openapi_examples={
"one-asset": {
"description": "Return indexes 1,2,3 of asset `data`.",
"value": ["data|1,2,3"],
Expand Down Expand Up @@ -269,7 +269,7 @@ class BandsParams(DefaultDependency):
None,
title="Band names",
description="Band's names.",
examples={
openapi_examples={
"one-band": {
"description": "Return results for band `B01`.",
"value": ["B01"],
Expand Down Expand Up @@ -350,7 +350,7 @@ class BidxParams(DefaultDependency):
title="Band indexes",
alias="bidx",
description="Dataset band indexes",
examples={"one-band": {"value": [1]}, "multi-bands": {"value": [1, 2, 3]}},
openapi_examples={"one-band": {"value": [1]}, "multi-bands": {"value": [1, 2, 3]}},
),
] = None
```
Expand Down Expand Up @@ -378,7 +378,7 @@ class ExpressionParams(DefaultDependency):
Query(
title="Band Math expression",
description="rio-tiler's band math expression",
examples={
openapi_examples={
"simple": {"description": "Simple band math.", "value": "b1/b2"},
"multi-bands": {
"description": "Semicolon (;) delimited expressions (band1: b1/b2, band2: b2+b3).",
Expand Down Expand Up @@ -654,7 +654,7 @@ If bins is a sequence (comma `,` delimited values), it defines a monotonically i
link: https://numpy.org/doc/stable/reference/generated/numpy.histogram.html
""",
examples={
openapi_examples={
"simple": {
"description": "Defines the number of equal-width bins",
"value": 8,
Expand Down
2 changes: 1 addition & 1 deletion src/titiler/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
"numpy",
"pydantic~=2.0",
"rasterio",
"rio-tiler>=6.2.1,<7.0",
"rio-tiler>=6.2.5,<7.0",
"morecantile>=5.0,<6.0",
"simplejson",
"typing_extensions>=4.6.1",
Expand Down
19 changes: 19 additions & 0 deletions src/titiler/core/tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,25 @@ def test_MultiBaseTilerFactory(rio):
assert meta["dtype"] == "uint16"
assert meta["count"] == 3

response = client.get(
f"/preview.tif?url={DATA_DIR}/item.json&assets=B01&bidx=1&bidx=1&return_mask=false"
)
assert response.status_code == 200
assert response.headers["content-type"] == "image/tiff; application=geotiff"
meta = parse_img(response.content)
assert meta["dtype"] == "uint16"
assert meta["count"] == 2

with pytest.warns(UserWarning):
response = client.get(
f"/preview.tif?url={DATA_DIR}/item.json&assets=B01&asset_bidx=B01|1,1,1&bidx=1&return_mask=false"
)
assert response.status_code == 200
assert response.headers["content-type"] == "image/tiff; application=geotiff"
meta = parse_img(response.content)
assert meta["dtype"] == "uint16"
assert meta["count"] == 3

response = client.get(
"/preview.tif",
params={
Expand Down
44 changes: 33 additions & 11 deletions src/titiler/core/titiler/core/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Common dependency."""

import json
import warnings
from dataclasses import dataclass
from typing import Callable, Dict, List, Literal, Optional, Sequence, Tuple, Union

Expand Down Expand Up @@ -86,7 +87,10 @@ class BidxParams(DefaultDependency):
title="Band indexes",
alias="bidx",
description="Dataset band indexes",
examples={"one-band": {"value": [1]}, "multi-bands": {"value": [1, 2, 3]}},
openapi_examples={
"one-band": {"value": [1]},
"multi-bands": {"value": [1, 2, 3]},
},
),
] = None

Expand All @@ -100,7 +104,7 @@ class ExpressionParams(DefaultDependency):
Query(
title="Band Math expression",
description="rio-tiler's band math expression",
examples={
openapi_examples={
"simple": {"description": "Simple band math.", "value": "b1/b2"},
"multi-bands": {
"description": "Semicolon (;) delimited expressions (band1: b1/b2, band2: b2+b3).",
Expand Down Expand Up @@ -128,7 +132,7 @@ class AssetsParams(DefaultDependency):
Query(
title="Asset names",
description="Asset's names.",
examples={
openapi_examples={
"one-asset": {
"description": "Return results for asset `data`.",
"value": ["data"],
Expand All @@ -143,15 +147,15 @@ class AssetsParams(DefaultDependency):


@dataclass
class AssetsBidxExprParams(AssetsParams):
class AssetsBidxExprParams(AssetsParams, BidxParams):
"""Assets, Expression and Asset's band Indexes parameters."""

expression: Annotated[
Optional[str],
Query(
title="Band Math expression",
description="Band math expression between assets",
examples={
openapi_examples={
"simple": {
"description": "Return results of expression between assets.",
"value": "asset1_b1 + asset2_b1 / asset3_b1",
Expand All @@ -166,7 +170,7 @@ class AssetsBidxExprParams(AssetsParams):
title="Per asset band indexes",
description="Per asset band indexes (coma separated indexes)",
alias="asset_bidx",
examples={
openapi_examples={
"one-asset": {
"description": "Return indexes 1,2,3 of asset `data`.",
"value": ["data|1,2,3"],
Expand Down Expand Up @@ -200,6 +204,12 @@ def __post_init__(self):
for idx in self.asset_indexes
}

if self.asset_indexes and self.indexes:
warnings.warn(
"Both `asset_bidx` and `bidx` passed; only `asset_bidx` will be considered.",
UserWarning,
)


@dataclass
class AssetsBidxExprParamsOptional(AssetsBidxExprParams):
Expand All @@ -213,9 +223,15 @@ def __post_init__(self):
for idx in self.asset_indexes
}

if self.asset_indexes and self.indexes:
warnings.warn(
"Both `asset_bidx` and `bidx` passed; only `asset_bidx` will be considered.",
UserWarning,
)


@dataclass
class AssetsBidxParams(AssetsParams):
class AssetsBidxParams(AssetsParams, BidxParams):
"""Assets, Asset's band Indexes and Asset's band Expression parameters."""

asset_indexes: Annotated[
Expand All @@ -224,7 +240,7 @@ class AssetsBidxParams(AssetsParams):
title="Per asset band indexes",
description="Per asset band indexes",
alias="asset_bidx",
examples={
openapi_examples={
"one-asset": {
"description": "Return indexes 1,2,3 of asset `data`.",
"value": ["data|1;2;3"],
Expand All @@ -242,7 +258,7 @@ class AssetsBidxParams(AssetsParams):
Query(
title="Per asset band expression",
description="Per asset band expression",
examples={
openapi_examples={
"one-asset": {
"description": "Return results for expression `b1*b2+b3` of asset `data`.",
"value": ["data|b1*b2+b3"],
Expand All @@ -268,6 +284,12 @@ def __post_init__(self):
idx.split("|")[0]: idx.split("|")[1] for idx in self.asset_expression
}

if self.asset_indexes and self.indexes:
warnings.warn(
"Both `asset_bidx` and `bidx` passed; only `asset_bidx` will be considered.",
UserWarning,
)


# Dependencies for MultiBandReader
@dataclass
Expand All @@ -279,7 +301,7 @@ class BandsParams(DefaultDependency):
Query(
title="Band names",
description="Band's names.",
examples={
openapi_examples={
"one-band": {
"description": "Return results for band `B01`.",
"value": ["B01"],
Expand Down Expand Up @@ -462,7 +484,7 @@ class HistogramParams(DefaultDependency):
link: https://numpy.org/doc/stable/reference/generated/numpy.histogram.html
""",
examples={
openapi_examples={
"simple": {
"description": "Defines the number of equal-width bins",
"value": 8,
Expand Down

0 comments on commit fa88732

Please sign in to comment.