I have a 3d array (10x10x3) which, for some reason, is saved as a 2d xr.DataArray (100x3). It looks a bit like this:
data = xr.DataArray(np.random.randn(100, 3),
dims=('ct', 'x'),
coords={'ct': range(100)})
c = [x%10 for x in range(100)]
t = [1234+x//10 for x in range(100)]
c and t are the coordinates that are bundled together in ct.
In the past I have solved the issue of separating the two dimension as follows:
t_x_c,x = data.shape
nc = 10
data = np.reshape(data.values,(t_x_c//nc,nc, x))
But this requires a number of assumptions in the data structure that may not be true in the near future (e.g. c and t may not be as regular as in my example).
I have managed to assign c and t as additional coordinates to the array:
data2 = data.assign_coords(
coords={"c": ("ct", c),
"t": ("ct", t),
},)
but I would like to promote them to dimensions of the array. How would I do that?