Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Padding to original bounds extends the array #155

Open
davidbrochart opened this issue Jun 29, 2020 · 7 comments
Open

Padding to original bounds extends the array #155

davidbrochart opened this issue Jun 29, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@davidbrochart
Copy link
Contributor

Code Sample, a copy-pastable example if possible

import rioxarray
import xarray

xds = xarray.open_dataarray("test/test_data/input/MODIS_ARRAY.nc")
# xds.shape is (200, 200)
bounds = xds.rio.bounds()
xdsc = xds.rio.pad_box(
    minx=bounds[0],
    miny=bounds[1],
    maxx=bounds[2],
    maxy=bounds[3],
)
# xdsc.shape is (201, 200)

Problem description

I think we shouldn't include the half-pixel here.

Expected Output

The shape of the padded array should remain the same.

@davidbrochart davidbrochart added the bug Something isn't working label Jun 29, 2020
@snowman2
Copy link
Member

Does pad_xy behave as expected?

@davidbrochart
Copy link
Contributor Author

Yes, but I guess it's a question of definition of the bounding box. In pad_box, do we expect a box that is relative to the "pixel boundaries" or the pixel centers (which correspond to the array coordinates)?

@snowman2
Copy link
Member

do we expect a box that is relative to the "pixel boundaries"

I would assume that would be the behavior. What are your thoughts?

@davidbrochart
Copy link
Contributor Author

I don't know, but it has to be consistent with clip_box. It looks like clip_box expects a box relative to the "pixel centers" (it extends it with a half-pixel to the "pixel boundaries"), so in this case pad_box behaves similarly (although clip_box uses rasterio.windows.from_bounds).
Calling pad_box with the rio.bounds() (which include the half-pixel) can lead to a random behavior because of floating point approximations, so it's not a good idea. It's better in that case to call it with the first/last coordinates.

@snowman2
Copy link
Member

One idea I had was to reduce the buffer by multiplying the cell size by 0.9999 and see if that helps with the floating point precision issues.

@davidbrochart
Copy link
Contributor Author

I'm not sure, it would be kind of a hack. I think the current behavior is OK, we might just have to document it a bit more.

@snowman2
Copy link
Member

snowman2 commented Jul 1, 2020

That sounds good to me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants