-
I have MxNxT xarray with the following dimensions and coordinates:
I am trying to apply groupby the "gridcell" dimension so I can perform an operation on each of those groups using xr.map, or apply_ufunc function.
When I do that, the resulting group matrix is 1xNxT, but I only want groups to be NxT, isn't that what squeeze is supposed to do? I don't see any changes whatsoever. Any other suggestions are very much appreciated as well. Your help would be and immense relief! Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Shouldn't the call be You are currently grouping over import numpy as np
import xarray as xr
air = xr.tutorial.open_dataset("air_temperature")
a = air.stack(gridcell=("lat", "lon"))
len(np.unique(a.gridcell.values)) == len(a.gridcell.values) |
Beta Was this translation helpful? Give feedback.
-
Here is a small example. Kind of works import numpy as np
import xarray as xr
data = np.arange(8).reshape(2, 4)
da = xr.DataArray(data, dims=("y", "x"), coords=dict(y=[1, 2], x=[1, 1, 1, 1]))
da = da.stack(gridcell=("x", "y"))
da_g = da.groupby("gridcell").mean() It keeps the multiindex but renames the levels (this could be considered a bug).
This can be fixed like so: mi = da_g.indexes["gridcell"]
da_g.assign_coords(gridcell=mi.set_names(["x", "y"])) Do you experience something different? If so a small example would be helpful. (There is a refactor of the way indexes are treated underway - this may change how this behaves). |
Beta Was this translation helpful? Give feedback.
Here is a small example. Kind of works
It keeps the multiindex but renames the levels (this could be considered a bug).
This can be fixed like so:
Do you experience something different? If s…