NASA-IMPACT / veda-backend

Backend services for VEDA
Other
13 stars 5 forks source link

Update raster API for alternate assets extension #157

Open anayeaye opened 1 year ago

anayeaye commented 1 year ago

What

Update raster/titiler API to accommodate items that use the alternate assets extension (a common standard used in NASA EarthdataCloud datasets).

Notes

extension docs: stac-extension/alternate-assets

Alternate assets examples https://landsatlook.usgs.gov/stac-server/collections/landsat-c2l2-sr/items/LE

Detail of a single asset with a login protected https href and an alternate s3 url

alternate-assets-detail

07_L2SR_005113_20010116_20200917_02_T2_SR

template/explanation as code: Here are some notes from @vincentsarago about how we can fetch nested alternate asset urls by building a TilerFactory using a custom STACReader

import attr
from rio_tiler.io import stac
from rio_tiler.types import AssetInfo
from rio_tiler.errors import InvalidAssetName

@attr.s
class STACReader(stac.STACReader)

    @minzoom.default
    def _minzoom(self):
        return self.tms.minzoom

    @maxzoom.default
    def _maxzoom(self):
        return self.tms.maxzoom

    def _get_asset_info(self, asset: str) -> AssetInfo:
        """Validate asset names and return asset's url.
        Args:
            asset (str): STAC asset name.
        Returns:
            str: STAC asset href.
        """
        if asset not in self.assets:
            raise InvalidAssetName(f"{asset} is not valid")

        asset_info = self.item.assets[asset]
        info = AssetInfo(url=asset_info.extra_fields["alternate"]["s3"]["href"])

        if "file:header_size" in asset_info.extra_fields:
            h = asset_info.extra_fields["file:header_size"]
            info["env"] = {"GDAL_INGESTED_BYTES_AT_OPEN": h}

        return info

AC

moradology commented 9 months ago

OK, so I've got this issue pretty well cornered, but there are a couple questions that remain.

  1. First one of the non-trivial properties on the alt asset from the example is 'requester-pays'. Any ideas on this question? https://github.com/developmentseed/titiler/discussions/758

  2. Are there any alternate assets that we might want to support other than 's3'? If so, we'll want to make the path slightly more complex (or else add an appropriate query parameter).