Using 'nearest' when having NaN #8303
Unanswered
rodrigo-j-goncalves
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a large sparse matrix of surface temperature values, indexed by
latitude
andlongitude
. The grid is irregular and has lots of NaN values (actually, most values are NaN).I need to inspect the 2D matrix for temperature values at specific locations (i.e., arbitrary latitudes and longitudes).
Say I need the temperature value nearest to
latitude = -24.5
andlongitude = 56.3
Thus I thought I'd use something like
If I do that, I almost always get a NaN (except that I am very lucky and use lat, lon really close to a non-NaN value in my matrix). And I guess this is not wrong, because my matrix actually has a cell 'near' my interest point... it's just that the cell has no temperature value on it. Thus it is not of much use to my case.
Right now I'm using a kind of convoluted approach, which uses slices and basically progressively increases the search intervals (i.e., min and max of the slice range) until I get a non-NaN value.
It would be interesting if I could tell xarray that I am looking for the nearest non-NaN value of my temperature variable. Makes sense? So, is there a way that I can tell xarray that the
.sel(method = 'nearest')
to keep looking until it finds a non-NaN data value? Alternative, could you suggest how (if possible) to mask all the NaN of mytemperature
values sosel(method = 'nearest')
keeps looking until it finds a non-NaN value?Beta Was this translation helpful? Give feedback.
All reactions