-
Notifications
You must be signed in to change notification settings - Fork 12
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
Issue with cropped xarray
data causing xarray
's .where()
to behave differently
#115
Labels
bug
Something isn't working
Comments
that would be due to floating point precision most likely. In theory we should have an invariant like this xr_coords(gbox)['y'][3:7].data == xr_coord(gbox[3:7, :])['y'].data but this might not be the case due to numeric precision. |
changing - xx_masked = xx_cropped.where(rasterized)
+ xx_masked = xx_cropped.where(rasterized.data) gives expected result as it ignores tiny differences in lon/lat: rasterized.latitude.data - xx_cropped.latitude.data
>>> array([ 0.00000000e+00, 2.22044605e-16, 2.22044605e-16, 0.00000000e+00,
0.00000000e+00, -2.22044605e-16, 0.00000000e+00, 0.00000000e+00,
-2.22044605e-16, 0.00000000e+00]) |
in general, when using |
Thanks Kirill! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While testing #114, I've been running into a really confusing issue that seems to cause
xarray
's.where
to change the output size of my arrays.Usually,
a.where(b)
simply masks out values froma
that are False inb
, replacing them withNaN
. This normally doesn't have any effect on the shape ofa
(assuming the defaultdrop=False
) - you get back an array of the orginal shape after applying the mask.For example, I might want to rasterize a polygon, then apply this to my original data as a mask. This works fine - my masked data comes out the same size as my original data:
Problem
However, if I modify the shape of my array using
.isel()
or similar,.where()
starts to behave differently. This example is the same, except I select a subset of my array using.isel()
before rasterizing my polygon into its new geobox.The rasterization works fine - my rasterized polygon and clipped array have the same geobox and shape. However, when I attempt to combine them with
xx_cropped.where(rasterized)
, I get out an array with a different geobox, including different resolution and shape:Am I doing something silly here? Or is there some interaction going on between
xarray
andodc-geo
that is causing.where
to behave differently on data that has previously subsetted with.isel()
?The confusing thing is that
xx_cropped
andrasterized
seem to have completely identical pixel grids, i.e. same geobox and even the same spatial dim coordinates...The text was updated successfully, but these errors were encountered: