Skip to content

Commit ba2cb6f

Browse files
Revert change to asset indexes
1 parent b68c0c5 commit ba2cb6f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

titiler/stacapi/asset_reader.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def tile( # noqa: C901
142142
tile_z: int,
143143
assets: Union[Sequence[str], str] = (),
144144
expression: Optional[str] = None,
145+
asset_indexes: Optional[Dict[str, Indexes]] = None, # Indexes for each asset
145146
asset_as_band: bool = False,
146147
**kwargs: Any,
147148
) -> ImageData:
@@ -153,6 +154,7 @@ def tile( # noqa: C901
153154
tile_z (int): Tile's zoom level index.
154155
assets (sequence of str or str, optional): assets to fetch info from.
155156
expression (str, optional): rio-tiler expression for the asset list (e.g. asset1/asset2+asset3).
157+
asset_indexes (dict, optional): Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}).
156158
kwargs (optional): Options to forward to the `self.reader.tile` method.
157159
158160
Returns:
@@ -181,16 +183,24 @@ def tile( # noqa: C901
181183
raise MissingAssets(
182184
"assets must be passed either via `expression` or `assets` options."
183185
)
186+
187+
# indexes comes from the bidx query-parameter.
188+
# but for asset based backend we usually use asset_bidx option.
189+
asset_indexes = asset_indexes or {}
190+
191+
# We fall back to `indexes` if provided
192+
indexes = kwargs.pop("indexes", None)
184193

185194
def _reader(asset: str, *args: Any, **kwargs: Any) -> ImageData:
195+
idx = asset_indexes.get(asset) or indexes # type: ignore
186196
asset_info = self._get_asset_info(asset)
187197
reader = self._get_reader(asset_info)
188198

189199
with self.ctx(**asset_info.get("env", {})):
190200
with reader(
191201
asset_info["url"], tms=self.tms, **self.reader_options
192202
) as src:
193-
data = src.tile(*args, **kwargs)
203+
data = src.tile(*args, indexes=idx, **kwargs)
194204

195205
if asset_as_band:
196206
if len(data.band_names) > 1:

0 commit comments

Comments
 (0)