-
What is the best way to access the original values of stacked coordinates? import numpy as np
import xarray as xr
n = 40
lat = np.ones(n)
lon = np.arange(n)
time = np.ones(n)
A = np.zeros((n,n,n))
da = xr.DataArray(data=A,
dims=['lat','lon','time'],
coords=dict(lat=lat,lon=lon,time=time))
da = da.stack(latlon=('lat','lon'))
print(f'neither of these are the desired length ({n}):')
print(da.lon.shape)
print(da.coords['lon'].shape) Edit: switched one of the stacked coordinates to |
Beta Was this translation helpful? Give feedback.
Answered by
dcherian
Jun 17, 2024
Replies: 1 comment 1 reply
-
You can use the underlying pandas multiindex: It'll be easier to interpret if you use |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ghbrown
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the underlying pandas multiindex:
da.xindexes["latlon"].index
Thelevels
andnames
properties will be useful: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.MultiIndex.htmlIt'll be easier to interpret if you use
lon = np.arange(n)