Skip to content

rasterize/kde/line_density: output attrs['res'] not updated when output grid resolution differs from input #3571

Description

@brendancol

Describe the bug

Some tools build an output grid at a different resolution than their input but don't write the correct res into the output attrs. get_dataarray_resolution() reads attrs['res'] in preference to deriving cell size from the coordinates, so a stale or missing res feeds the wrong cell size to downstream distance- and area-based ops like slope, aspect, and proximity.

Affected tools:

  • rasterize(..., like=template) when the caller overrides the grid (explicit width/height/bounds/resolution) so the output no longer matches the template. The reshape path drops the template's stale res (correct) but never writes the new res it computes from the output grid, so the result carries no res at all.
  • kde(..., template=None) and line_density(..., template=None) build a fresh grid with a known cell spacing dx/dy, then return a DataArray with no res attr.

resample() already does the right thing and is the model to follow: it recomputes res (and transform) from the rebuilt coordinates on every path, including downsample, upsample, 3D per-band, and target_resolution.

Expected behavior

Each of these outputs should carry attrs['res'] = (abs(dx), abs(dy)) matching its actual output cell size, so downstream tools read the true resolution.

Additional context

preview() has the same class of issue but is being fixed in a separate PR, so it's out of scope here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsweep-metadataFound by /sweep-metadata

    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