add support for `BitsPerSample=15`

Open
#376 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python, rust
Domain
backend

Research direction

Start by tracing tile decoding from fetch_tile through the decode path, focusing on how BitsPerSample=15 affects the expected sample count and output shape. Use the Sentinel-2 COG reproduction in the issue to verify the failure; done means decoding that tile succeeds without the reported shape or data length error.

Written by the indexing model from the issue text.

Description

duplicate

Some Sentinel2 COGs in the planetary computer have BitsPerSample=15 which breaks async-tiff. Encountered this through async-geotiff, but opening the issue here.

ValueError: General error: Internal error: incorrect shape or data length passed to Array::try_new. Got data length 491520, expected 262144

Reproducible example (created wth claude):

# /// script
# requires-python = ">=3.11"
# dependencies = ["async-tiff==0.7.2", "obstore", "requests"]
# ///
"""async-tiff cannot decode a tile of a COG with BitsPerSample=15 (Planetary Computer Sentinel-2 L2A).

Run: uv run repro_async_tiff.py
"""
import asyncio

import requests
from async_tiff import TIFF
from obstore.store import AzureStore

ACCOUNT, CONTAINER = "sentinel2l2a01", "sentinel2-l2"
PATH = ("15/U/US/2025/04/26/S2B_MSIL2A_20250426T171859_N0511_R012_T15UUS_20250426T204945.SAFE/GRANULE/"
        "L2A_T15UUS_A042509_20250426T172529/IMG_DATA/R10m/T15UUS_20250426T171859_B03_10m.tif")


async def main():
    # a free, anonymous read token; the endpoint is rate-limited (429 with retry-after)
    token = requests.get(f"https://planetarycomputer.microsoft.com/api/sas/v1/token/{ACCOUNT}/{CONTAINER}", timeout=60)
    token.raise_for_status()
    store = AzureStore(account_name=ACCOUNT, container_name=CONTAINER, sas_token=token.json()["token"])

    tiff = await TIFF.open(PATH, store=store)
    ifd = tiff.ifds[0]
    print("bits_per_sample:", ifd.bits_per_sample, "sample_format:", ifd.sample_format)
    print("tile:", ifd.tile_width, "x", ifd.tile_height, "compression:", ifd.compression)
    tile = await tiff.fetch_tile(0, 0, 0)  # fetching works
    await tile.decode()  # ValueError: ... Got data length 491520, expected 262144


asyncio.run(main())
Dominant language
Rust
Stars
125
Forks
17
Avg merge
7h 33m
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from developmentseed/async-tiff

All issues in developmentseed/async-tiff

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.