When we handle the climate model output, we often get a NetCDF file with dimensions including member, lon, lat. Foe every member, how do we get the minimum of data, the lon and the lat of the data?
What We Have
Let’s start with an Xarray DataArray, which has dimensions with member, lat, lon
member = range(30)
lat = np.linspace(10,90,81) # len(lat)=81
lon = np.linspace(-50,50,101) # len(lon)=101
da = xr.DataArray(
data = np.random.random([30, 81, 101]),
dims = ['member','lat','lon'],
coords=dict(
member = member,
lat = lat,
lon = lon,
)
)
print(da)
<xarray.DataArray (member: 30, lat: 81, lon: 101)>
array([[[0.2891831 , 0.15339252, 0.11480441, ..., 0.52430944,
0.1713771 , 0.67480492],
[0.2033522 , 0.14739973, 0.28882198, ..., 0.37215926,
0.36807609, 0.71486314],
[0.31566454, 0.09916745, 0.01528857, ..., 0.08635732,
0.14854258, 0.19532821],
...,
[0.17011999, 0.35888976, 0.75866957, ..., 0.05882159,
0.78562657, 0.2738246 ],
[0.45221776, 0.51605168, 0.83711006, ..., 0.98703641,
0.54330316, 0.27072401],
[0.64459723, 0.31273233, 0.30999083, ..., 0.94173884,
0.12521629, 0.21233589]]])
Coordinates:
* member (member) int64 0 1 2 3 4 5 6 7 8 9 ... 21 22 23 24 25 26 27 28 29
* lat (lat) float64 10.0 11.0 12.0 13.0 14.0 ... 86.0 87.0 88.0 89.0 90.0
* lon (lon) float64 -50.0 -49.0 -48.0 -47.0 -46.0 ... 47.0 48.0 49.0 50.0
What We Want
For every member, I want to get the minimum of the data, and its lon/lat information. So, the expected result could be an DataArray of Pandas Dataframe, like the following structure:
Output:
member : 0, 1, 2,..., 29
lon: lon0, lon1, lon2, ..., lon29
lat: lat0, lat1, lat2, ..., lat29
I have tried the da.min()
or the da.argmin()
, but it seems not work well.