xarray: How to get the coordinates of the maximum and minimum value over a spatial domain in xarray? #8036
Replies: 2 comments
-
There might be a better way, but I think this is one way: First mask out all the data that isn't in your lat/long box. If your latitude and longitude are 1D then you could use condition = np.logical_and(data.lat > 10.0, data.lon < 50.0)
box = data.where(condition) Then use inds_of_max = box.argmax(dims=['lat', 'lon']) Pass those indices to your latitude/longitude coordinate arrays to get the (lat, lon) pair you want. lat, lon = data.lat[inds_of_max], data.lon[inds_of_max] (This would probably be better placed on stackoverflow than here but doesn't matter) |
Beta Was this translation helpful? Give feedback.
-
In fact, this was already asked on StackOverflow :) I'm going to close this, but feel free to comment or reopen if you have any further questions. |
Beta Was this translation helpful? Give feedback.
-
I have a netcdf file containing a surface variable over a latlon area. I want to get the coordinate (as lat, lon value) of maximum as well as minimum value of that variable over a certain area which I can define with latlon box. How to do it in xarray ?
Beta Was this translation helpful? Give feedback.
All reactions