Skip to content

ValueError: conflicting sizes for dimension with single item / asset #33

Closed
@TomAugspurger

Description

@TomAugspurger

I haven't looked too closely at this, but I'm wondering if there's some issue with the resampling / resolution handling? In this example I have a single STAC item and I select a single asset from it. stackstac (actually xarray) complains that the sizes of the data and coordinates don't match. (this example requires pip install planetary-computer and pystac, but doesn't need an API token).

import planetary_computer as pc
import stackstac
import requests
import pystac

r = requests.get(
    "https://planetarycomputer.microsoft.com/api/stac/v1/collections/landsat-8-c2-l2/items/LC08_L2SP_046027_20200908_20200919_02_T1"
)

item = pystac.Item.from_dict(r.json())

sitem = pc.sign_assets(item)

stackstac.stack([sitem.to_dict()], assets=["SR_B2"])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-b99acad73e1d> in <module>
     13 sitem = pc.sign_assets(item)
     14 
---> 15 stackstac.stack([sitem.to_dict()], assets=["SR_B2"])

/srv/conda/envs/notebook/lib/python3.8/site-packages/stackstac/stack.py in stack(items, assets, epsg, resolution, bounds, bounds_latlon, snap_bounds, resampling, chunksize, dtype, fill_value, rescale, sortby_date, xy_coords, properties, band_coords, gdal_env, reader)
    290     )
    291 
--> 292     return xr.DataArray(
    293         arr,
    294         *to_coords(

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/core/dataarray.py in __init__(self, data, coords, dims, name, attrs, indexes, fastpath)
    407             data = _check_data_shape(data, coords, dims)
    408             data = as_compatible_data(data)
--> 409             coords, dims = _infer_coords_and_dims(data.shape, coords, dims)
    410             variable = Variable(dims, data, attrs, fastpath=True)
    411             indexes = dict(

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/core/dataarray.py in _infer_coords_and_dims(shape, coords, dims)
    155         for d, s in zip(v.dims, v.shape):
    156             if s != sizes[d]:
--> 157                 raise ValueError(
    158                     "conflicting sizes for dimension %r: "
    159                     "length %s on the data but length %s on "

ValueError: conflicting sizes for dimension 'x': length 7772 on the data but length 7773 on coordinate 'x'

The correct shape, according to rasterio, is

>>> ds = rasterio.open(sitem.assets["SR_B2"].href)
>>> ds.shape
(7891, 7771)

This could easily be user error :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-future-testAdd a test for this in the future, once tests exist (#26)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions