Skip to content

Coordinates.from_xindex(RasterIndex) produces scalar coords with wrong shape after chunked nearest spatial selection #92

@hrodmn

Description

@hrodmn

Hi rasterix 👋 - thanks for building this awesome package! I found a small bug after bringing rasterix into lazycogs. Maybe this is a known limitation and I am not using it correctly.

Using rasterix.RasterIndex via xarray.Coordinates.from_xindex(index) appears to break a chunked scalar spatial selection path in xarray.

A pattern like:

da = da.chunk(time=1).sel(x=..., y=..., method="nearest").compute()

fails when x and y come from Coordinates.from_xindex(RasterIndex(...)).

What seems to happen:

  • after sel(x=..., y=..., method="nearest"), x and y become scalar coords
  • during compute(), those lazy scalar coords materialize as shape (1,) instead of ()
  • xarray then raises a shape mismatch, e.g.:
ValueError: replacement data must match the Variable's shape. replacement data has shape (1,); Variable has shape ()

Workaround on our side:

  • keep the RasterIndex attached for indexing behavior
  • eagerly materialize the x/y coordinate variables instead of using the lazy coord variables from Coordinates.from_xindex(index)

Question:

  • is this a known limitation/bug in rasterix’s xarray integration?
  • should scalar coord materialization after chunked selection be handled differently in RasterIndex / create_variables() / from_xindex usage?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions