Skip to content

Incorrect bounds and shape when stacking 3DEP items from Planetary Computer #147

Closed
@aazuspan

Description

@aazuspan

Hi @gjoseph92, I'm using stackstac.stack with two adjacent COGs from the Planetary Computer 3dep-seamless collection, and the output bounds and shape are incorrect. If I load them manually with xarray and concat them, the bounds are correct.

Reproducing

import planetary_computer
from pystac_client import Client
import stackstac
import xarray as xr

catalog = Client.open("https://planetarycomputer.microsoft.com/api/stac/v1")
collection = "3dep-seamless"
# This bbox spans two items that are adjacent in x dimension
bbox = [-124.210979, 43.336502, -123.657496, 43.798309]

search = catalog.search(
    collections=[collection],
    bbox=bbox,
    # 3DEP contains both 10m and 30m items
    filter={"eq": [{"property": "gsd"}, 30]},
)

signed = planetary_computer.sign(search)

# Stack the two adjacent items with stackstac (doesn't work as expected)
da_stackstac = stackstac.stack(signed, assets=["data"])

# Stack the two items manually by opening and concatenating with xarray (works as expected)
da_list = [xr.open_rasterio(item.assets["data"].href, chunks=1024) for item in signed]
da_xarray = xr.concat(da_list, dim="time")

Issues

The bounds for the two arrays are much different and the stackstac version doesn't cover the the search bbox:

# Bounds don't cover the bbox: (-125.00167, 43.965540000000004, -123.96554, 44.001670000000004)
print(stackstac.array_bounds(da_stackstac))

# Bounds do cover the bbox: (-125.00152777777778, 42.99819444444364, -122.99819444444364, 44.001527777777774)
print(stackstac.array_bounds(da_xarray))

The array shapes (ignoring the time and band dims) are also much different:

# (3613, 103613)
print(da_stackstac.shape[2:])

# (3612, 7224)
print(da_xarray.shape[2:])

Checking the proj:shape property for the items indicates their shape should be 3612 x 3612, so it looks like the stackstac version is off by 1 in the y dimension and 100k in the x dimension.

Any thoughts on what's going on here? Thanks!

For reference, I'm running stackstac=0.4.1 and xarray=2022.3.0.

EDIT: This looked like it might be related to #132, but the proj:transform of the items seem to be in the correct order:

>> signed[0].properties

{'gsd': 30,
 'datetime': '2013-01-01T00:00:00Z',
 'proj:epsg': 5498,
 'proj:shape': [3612, 3612],
 'end_datetime': '2013-11-01T00:00:00Z',
 'proj:transform': [1e-05,
  0.0,
  -125.0016666667,
  0.0,
  -1e-05,
  44.00166666666,
  0.0,
  0.0,
  1.0],
 'start_datetime': '1999-02-01T00:00:00Z',
 'threedep:region': 'n40w130'}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions