Xarray find lat/lon coordinates for maximum/minimum values for each timestep
Question:
As the title says, supposing I have a ds
with coords: [time lat lon]
, how can I obtain for each timestep in time
the pair of ['lat','lon']
in which the maximum(or minimum) value for a given variable is located.
Answers:
Use xr.Dataset.idxmax
to find the index label of the maximum along a dimension (one at a time). Same for xr.Dataset.idxmin
.
max_lons = ds.max(dim="lat").idxmax(dim="lon")
max_lats = ds.max(dim="lon").idxmax(dim="lat")
The results will be datasets, with each variable giving the lon or lat coresponding to the maximum in each time step for that variable.
As the title says, supposing I have a ds
with coords: [time lat lon]
, how can I obtain for each timestep in time
the pair of ['lat','lon']
in which the maximum(or minimum) value for a given variable is located.
Use xr.Dataset.idxmax
to find the index label of the maximum along a dimension (one at a time). Same for xr.Dataset.idxmin
.
max_lons = ds.max(dim="lat").idxmax(dim="lon")
max_lats = ds.max(dim="lon").idxmax(dim="lat")
The results will be datasets, with each variable giving the lon or lat coresponding to the maximum in each time step for that variable.