Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STAC with proj extension and rotations in transform confuses TiTiler /stac endpoints #1074

Closed
scottyhq opened this issue Jan 22, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@scottyhq
Copy link
Contributor

Problem description

I am getting a confusing 500 Error: "detail": "can't multiply sequence by non-int of type 'tuple'" on some STAC items which I spent some time digging into and it seems to be coming from having proj:transform fields present with rotations.

Here is a reproducer with public data:
https://umbra-open-data-catalog.s3.amazonaws.com/sar-data/tasks/Panama+Canal,+Panama/bb17c467-a6a8-41f0-80d8-2da88af9475b/2024-02-15-03-30-26_UMBRA-06/2024-02-15-03-30-26_UMBRA-06_GEC.tif
(yes the spaces in the file names are very annoying !):

  1. /cog/bounds work as expected:
https://titiler.xyz/cog/bounds?url=https%3A%2F%2Fumbra-open-data-catalog.s3.amazonaws.com%2Fsar-data%2Ftasks%2FPanama%2BCanal%2C%2BPanama%2Fbb17c467-a6a8-41f0-80d8-2da88af9475b%2F2024-02-15-03-30-26_UMBRA-06%2F2024-02-15-03-30-26_UMBRA-06_GEC.tif
  1. /cog/stac works
https://titiler.xyz/cog/stac?asset_name=data&asset_media_type=auto&with_proj=true&with_raster=true&with_eo=true&max_size=1024&geometry_densify=0&geometry_precision=-1&url=https%3A%2F%2Fumbra-open-data-catalog.s3.amazonaws.com%2Fsar-data%2Ftasks%2FPanama%2BCanal%2C%2BPanama%2Fbb17c467-a6a8-41f0-80d8-2da88af9475b%2F2024-02-15-03-30-26_UMBRA-06%2F2024-02-15-03-30-26_UMBRA-06_GEC.tif
  1. /stac/bounds returns an error for STAC with proj extension
https://titiler.xyz/stac/bounds?url=https%3A%2F%2Fgist.githubusercontent.com%2Fscottyhq%2F68c296ab3c6e7c6f97f0460629308ddf%2Fraw%2F9a8c0ac6e7a3bbd89f9bb0fd9bfd32d689d2781a%2Ftitiler-proj.json
  1. /stac/bounds Works without proj extension!
https://titiler.xyz/stac/bounds?url=https%3A%2F%2Fgist.githubusercontent.com%2Fscottyhq%2F68c296ab3c6e7c6f97f0460629308ddf%2Fraw%2F9a8c0ac6e7a3bbd89f9bb0fd9bfd32d689d2781a%2Ftitiler-noproj.json

I spent a bit of time trying to figure out where this error is coming from but couldn't figure out the code path... For convenience I've posted the two STACs here
https://gist.github.com/scottyhq/68c296ab3c6e7c6f97f0460629308ddf

Expected Output

Same results for /cog/bounds and /stac/bounds

Environment Information

titiler.xyz

{
  "versions": {
    "titiler": "0.20.1",
    "rasterio": "1.4.3",
    "gdal": "3.9.3",
    "proj": "9.4.1",
    "geos": "3.11.1"
  }
}
@scottyhq scottyhq added the bug Something isn't working label Jan 22, 2025
@vincentsarago
Copy link
Member

Thanks @scottyhq 🙏

This is clearly a rio-tiler (maybe rasterio) issue.

from rio_tiler.io import STACReader

In [3]: with STACReader("https://gist.githubusercontent.com/scottyhq/68c296ab3c6e7c6f97f0460629308ddf/raw/9a8c0ac6e7a3bbd89f9bb0fd9bfd32d689d2781a/titiler-proj.json") as src:
   ...:     print(src.bounds)
   ...: 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-5092201fd028> in <cell line: 1>()
----> 1 with STACReader("https://gist.githubusercontent.com/scottyhq/68c296ab3c6e7c6f97f0460629308ddf/raw/9a8c0ac6e7a3bbd89f9bb0fd9bfd32d689d2781a/titiler-proj.json") as src:
      2     print(src.bounds)
      3 

~/Dev/CogeoTiff/rio-tiler/rio_tiler/io/stac.py in __init__(self, input, item, tms, minzoom, maxzoom, include_assets, exclude_assets, include_asset_types, exclude_asset_types, default_assets, reader, reader_options, fetch_options, ctx)
     23         self.fetch_options = __attr_factory_fetch_options()
     24     self.ctx = ctx
---> 25     self.__attrs_post_init__()

~/Dev/CogeoTiff/rio-tiler/rio_tiler/io/stac.py in __attrs_post_init__(self)
    279                 self.height, self.width = self.item.ext.proj.shape
    280                 self.transform = self.item.ext.proj.transform
--> 281                 self.bounds = array_bounds(self.height, self.width, self.transform)
    282                 self.crs = rasterio.crs.CRS.from_string(self.item.ext.proj.crs_string)
    283 

~/Dev/venv/py39/lib/python3.9/site-packages/rasterio/transform.py in array_bounds(height, width, transform)
    202     else:
    203         c0x, c0y = c, f
--> 204         c1x, c1y = transform * (0, height)
    205         c2x, c2y = transform * (width, height)
    206         c3x, c3y = transform * (width, 0)

TypeError: can't multiply sequence by non-int of type 'tuple'

I'll cannot transfer the issue to the rio-tiler repo but it's fine to keep it here for now

@vincentsarago
Copy link
Member

thanks @scottyhq

This is now fixed by cogeotiff/rio-tiler#781 and rio-tiler==7.3.1 (soon on pypi)

I'll trigger a new deploy for titiler.xyz later today

@scottyhq
Copy link
Contributor Author

Amazing! thanks for the explanation and quick turnaround @vincentsarago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants