Skip to content

structured_da_to_ds incorrectly produces nans in rotated grids with different delr and delc #444

Open
@rubencalje

Description

@rubencalje

Ok, kind of an edge-case, but a problem for what I am working on right now: when I use a different delr and delc, and I use grid-rotation, the method nlmod.resample.structured_da_to_ds produces nans in areas that should not be nan. This can be reproduced with the following code:

import nlmod

ds = nlmod.get_ds(
    [0, 1000, 0, 100],
    xorigin=100_000,
    yorigin=400_000,
    angrot=45,
    delr=100.0,
    delc=100.0,
)
extent = nlmod.grid.get_extent(ds)
ahn = nlmod.read.ahn.get_ahn4(extent)
da = nlmod.resample.structured_da_to_ds(ahn, ds)

And then plot this data-array, using

f, ax = nlmod.plot.get_map(extent, ncols=2)
nlmod.plot.data_array(ahn, ax=ax[0], vmin=-0.5, vmax=2.0)
nlmod.plot.data_array(da, ax=ax[1], vmin=-0.5, vmax=2.0, rotated=True)

Everything looks good. I have a value for each of my grid-cells that are the average of the original data within this cell

Image

If I change the grid to have a delr of 50m and a delc of 100m:

ds = nlmod.get_ds(
    [0, 1000, 0, 100],
    xorigin=100_000,
    yorigin=400_000,
    angrot=45,
    delr=50.0,
    delc=100.0,
)
da = nlmod.resample.structured_da_to_ds(ahn, ds)

There are nans in my DataArray da that should not be nan. The non-nan values seem to be right (the mean of the original data-array):

Image

I think this is because of a bug in rioxarray:
corteva/rioxarray#847

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions