I have an xarray with multiple coordinates along a single dimension. In the example below, coords a and b are defined along dimension dim1. How would I groupby using two coordinates that are defined along the same dimension(s)? Unlike this question, I am not trying to group along different dimensions, but a single one.
import xarray as xr
d = xr.DataArray([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],
coords={
'a': ('dim1',['A', 'A', 'B', 'B']),
'b': ('dim1',['1', '2', '1', '2']),
'c': ('dim2',['x', 'y', 'z'])
},
dims=['dim1', 'dim2'])
d.groupby(['a','b']) # this gives: TypeError: `group` must be an xarray.DataArray or the name of an xarray variable or dimension