Skip to content

Commit

Permalink
Revert change to asset indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
abarciauskas-bgse committed Jun 4, 2024
1 parent b68c0c5 commit ba2cb6f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion titiler/stacapi/asset_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def tile( # noqa: C901
tile_z: int,
assets: Union[Sequence[str], str] = (),
expression: Optional[str] = None,
asset_indexes: Optional[Dict[str, Indexes]] = None, # Indexes for each asset
asset_as_band: bool = False,
**kwargs: Any,
) -> ImageData:
Expand All @@ -153,6 +154,7 @@ def tile( # noqa: C901
tile_z (int): Tile's zoom level index.
assets (sequence of str or str, optional): assets to fetch info from.
expression (str, optional): rio-tiler expression for the asset list (e.g. asset1/asset2+asset3).
asset_indexes (dict, optional): Band indexes for each asset (e.g {"asset1": 1, "asset2": (1, 2,)}).
kwargs (optional): Options to forward to the `self.reader.tile` method.
Returns:
Expand Down Expand Up @@ -181,16 +183,24 @@ def tile( # noqa: C901
raise MissingAssets(
"assets must be passed either via `expression` or `assets` options."
)

# indexes comes from the bidx query-parameter.
# but for asset based backend we usually use asset_bidx option.
asset_indexes = asset_indexes or {}

# We fall back to `indexes` if provided
indexes = kwargs.pop("indexes", None)

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

with self.ctx(**asset_info.get("env", {})):
with reader(
asset_info["url"], tms=self.tms, **self.reader_options
) as src:
data = src.tile(*args, **kwargs)
data = src.tile(*args, indexes=idx, **kwargs)

if asset_as_band:
if len(data.band_names) > 1:
Expand Down

0 comments on commit ba2cb6f

Please sign in to comment.