I have a dataarray that contains multidimensional coordinates for latitude and longitude (y,x). Xarray natively works with this data is great, and allows me to do something like da.max()
and receive back a value. However, it seems that finding the coordinates associated with that max may not be as trivial (or I could be missing something).
Here is the structure of my dataarray:
xarray.DataArray 'Power' (y:1500, x:2500)
array([[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan],
...,
[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan]], dtype=float32)
Coordinates:
lon
(y, x)
float64
-113.1 -113.0 ... -52.98 -52.95
lat
(y, x)
float64
15.12 15.12 15.12 ... 51.36 51.36
Now, doing something like da.max()
returns a value of array(3335.06591797)
. Trying da.argmax()
also works and returns array(2365177)
. I think there could be a way to utilize this value to find where in the array, i.e. the coordinates, but I am not sure how to do that.
The third option is to try and utilize da.idxmax()
, however that requires that the dataarray have common dimensions and coordinates, which I don't have in this case.
Maybe there is some sort of numpy way to do this as well, but I am unclear on a process to do it that way. Any thoughts on what to do here? Utilizing da.argmax()
seems like the way to go, but am stuck.