Skip to content

Commit 765c1ea

Browse files
update for rio-tiler 9.0.0b1 (#1328)
1 parent 1f95af5 commit 765c1ea

9 files changed

Lines changed: 320 additions & 289 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
- id: ruff-format
1919

2020
- repo: https://github.com/pre-commit/mirrors-mypy
21-
rev: v1.11.2
21+
rev: v1.19.0
2222
hooks:
2323
- id: mypy
2424
language_version: python

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
## 2.0.0b1 (2026-02-22)\
6+
7+
### titiler.core
8+
9+
* change: rio-tiler requirement to `>=9.0.0b1,<10.0`
10+
* add: asset's options parsing in `AssetsParams` dependency
511

612
## 2.0.0a2 (2026-02-13)
713

docs/src/migrations/v2_migration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ GET /stac/tiles/WebMercatorQuad/10/512/384.png?url=...&assets=B02&assets=B03&bid
173173

174174
**After (2.0):**
175175

176-
Use new `asset` notation: `assets={AssetName}|indexes=1,2,3`
176+
Use new `asset` notation: `assets={AssetName}|bidx=1,2,3`
177177

178178
```
179-
GET /stac/tiles/WebMercatorQuad/10/512/384.png?url=...&assets=B02|indexes=1&assets=B03|indexes=1
179+
GET /stac/tiles/WebMercatorQuad/10/512/384.png?url=...&assets=B02|bidx=1&assets=B03|bidx=1
180180
```
181181

182182
### 7. Removed: `asset_indexes` and `asset_expression` Options
@@ -191,10 +191,10 @@ GET /stac/preview.png?url=...&asset_expression=data|b1*b2
191191

192192
**After (2.0):**
193193

194-
Use new `asset` notation: `assets={AssetName}|indexes=1,2,3` or `assets={AssetName}|expression=b1*2`
194+
Use new `asset` notation: `assets={AssetName}|bidx=1,2,3` or `assets={AssetName}|expression=b1*2`
195195

196196
```
197-
GET /stac/preview.png?url=...&assets=B01|indexes=1,2,3
197+
GET /stac/preview.png?url=...&assets=B01|bidx=1,2,3
198198
GET /stac/preview.png?url=...&assets=B01|expression=b1*2
199199
```
200200

src/titiler/core/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies = [
3636
"numpy",
3737
"pydantic~=2.0",
3838
"rasterio",
39-
"rio-tiler>=9.0.0a4,<10.0",
39+
"rio-tiler>=9.0.0b1,<10.0",
4040
"morecantile",
4141
"simplejson",
4242
]

src/titiler/core/tests/test_dependencies.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,23 @@ def _assets_expr(params=Depends(dependencies.AssetsExprParams)):
223223
response = client.get("/first?assets=data&assets=image")
224224
assert response.json() == ["data", "image"]
225225

226+
response = client.get("/first?assets=data|bidx=1,2|expression=b1*b2")
227+
assert response.json()[0]["name"] == "data"
228+
assert response.json()[0]["indexes"] == [1, 2]
229+
assert response.json()[0]["expression"] == "b1*b2"
230+
226231
response = client.get("/second?assets=data&assets=image")
227232
assert response.json()["assets"] == ["data", "image"]
228233
assert not response.json()["expression"]
229234

230235
response = client.get("/second?assets=data&assets=image&expression=b1*b2")
231236
assert response.json()["expression"] == "b1*b2"
232-
assert response.json()["assets"]
237+
assert response.json()["assets"] == ["data", "image"]
238+
239+
response = client.get("/second?assets=data|bidx=1,2|expression=b1*b2")
240+
assert response.json()["assets"][0]["name"] == "data"
241+
assert response.json()["assets"][0]["indexes"] == [1, 2]
242+
assert response.json()["assets"][0]["expression"] == "b1*b2"
233243

234244
response = client.get("/second")
235245
assert response.status_code == 422

src/titiler/core/tests/test_factories.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def test_MultiBaseTilerFactory(rio):
728728
"/preview.tif",
729729
params={
730730
"url": f"{DATA_DIR}/item.json",
731-
"assets": "B01|indexes=1,1,1",
731+
"assets": "B01|bidx=1,1,1",
732732
"return_mask": False,
733733
},
734734
)
@@ -817,16 +817,16 @@ def test_MultiBaseTilerFactory(rio):
817817
assert resp["B09"]["b1"]["description"] == "b1"
818818

819819
response = client.get(
820-
f"/asset_statistics?url={DATA_DIR}/item.json&assets=B09|indexes=1,1"
820+
f"/asset_statistics?url={DATA_DIR}/item.json&assets=B09|bidx=1,1"
821821
)
822822
assert response.status_code == 200
823823
assert response.headers["content-type"] == "application/json"
824824
resp = response.json()
825825
assert len(resp) == 1
826-
assert resp["B09|indexes=1,1"]["b1"]
827-
assert resp["B09|indexes=1,1"]["b2"]
828-
assert resp["B09|indexes=1,1"]["b1"]["description"] == "b1"
829-
assert resp["B09|indexes=1,1"]["b2"]["description"] == "b1"
826+
assert resp["B09|indexes=[1,1]"]["b1"]
827+
assert resp["B09|indexes=[1,1]"]["b2"]
828+
assert resp["B09|indexes=[1,1]"]["b1"]["description"] == "b1"
829+
assert resp["B09|indexes=[1,1]"]["b2"]["description"] == "b1"
830830

831831
# missing assets
832832
response = client.get(f"/statistics?url={DATA_DIR}/item.json")

src/titiler/core/titiler/core/dependencies.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import json
44
from collections.abc import Callable, Sequence
55
from dataclasses import dataclass, field
6-
from typing import Annotated, Literal
6+
from typing import Annotated, Any, Literal, cast
77

88
import numpy
99
from fastapi import HTTPException, Query
10-
from pydantic import BeforeValidator, Field
10+
from pydantic import AfterValidator, BeforeValidator, Field
1111
from rasterio.crs import CRS
1212
from rio_tiler.colormap import ColorMaps
1313
from rio_tiler.colormap import cmap as default_cmap
1414
from rio_tiler.colormap import parse_color
15-
from rio_tiler.types import RIOResampling, WarpResampling
15+
from rio_tiler.types import AssetType, AssetWithOptions, RIOResampling, WarpResampling
1616
from starlette.requests import Request
1717

1818
from titiler.core.resources.enums import ImageType, MediaType
@@ -134,12 +134,37 @@ class BidxExprParams(ExpressionParams, BidxParams):
134134

135135

136136
# Dependencies for MultiBaseReader (e.g STACReader)
137+
def _parse_asset(values: list[str]) -> list[AssetType]:
138+
"""Parse assets with optional parameter."""
139+
assets: list[AssetType] = []
140+
for v in values:
141+
if "|" in v:
142+
asset_name, params = v.split("|", 1)
143+
opts: dict[str, Any] = {"name": asset_name}
144+
for option in params.split("|"):
145+
key, value = option.split("=", 1)
146+
if key == "bidx":
147+
opts["indexes"] = list(map(int, value.split(",")))
148+
elif key == "expression":
149+
opts["expression"] = value
150+
elif key == "bands":
151+
opts["bands"] = value.split(",")
152+
153+
asset = cast(AssetWithOptions, opts)
154+
assets.append(asset)
155+
else:
156+
assets.append(v)
157+
158+
return assets
159+
160+
137161
@dataclass
138162
class AssetsParams(DefaultDependency):
139163
"""Assets parameters."""
140164

141165
assets: Annotated[
142166
list[str],
167+
AfterValidator(_parse_asset),
143168
Query(
144169
title="Asset names",
145170
description="Asset's names.",
@@ -153,6 +178,10 @@ class AssetsParams(DefaultDependency):
153178
"description": "Return results for assets `data` and `cog`.",
154179
"value": ["data", "cog"],
155180
},
181+
"multi-assets-with-options": {
182+
"description": "Return results for assets `data` and `cog`.",
183+
"value": ["data|bidx=1", "cog|bidx=1,2"],
184+
},
156185
},
157186
),
158187
]

src/titiler/xarray/titiler/xarray/io.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import zarr
1818
from morecantile import TileMatrixSet
1919
from rio_tiler.constants import WEB_MERCATOR_TMS
20-
from rio_tiler.io.xarray import XarrayReader
20+
from rio_tiler.io.xarray import Options, XarrayReader
2121
from zarr.storage import ObjectStore
2222

2323
X_DIM_NAMES = ["lon", "longitude", "LON", "LONGITUDE", "Lon", "Longitude"]
@@ -271,11 +271,17 @@ class Reader(XarrayReader):
271271

272272
tms: TileMatrixSet = attr.ib(default=WEB_MERCATOR_TMS)
273273

274+
options: Options = attr.ib()
275+
274276
ds: xarray.Dataset = attr.ib(init=False)
275277
input: xarray.DataArray = attr.ib(init=False)
276278

277279
_dims: list = attr.ib(init=False, factory=list)
278280

281+
@options.default
282+
def _options_default(self):
283+
return {}
284+
279285
def __attrs_post_init__(self):
280286
"""Set bounds and CRS."""
281287
opener_options = {

0 commit comments

Comments
 (0)