I frequently use broadcast_arrays to to feed xray variables to non-xray libraries (e.g. gsw.) Often I need to broadcast the coordinates and variables in order to do call functions that take both as arguments.
I have found that broadcast_arrays doesn't work as I expect with coordinates. For example
import xray
import numpy as np
ds = xray.Dataset({'a': (['y','x'], np.ones((20,10)))},
coords={'x': (['x'], np.arange(10)),
'y': (['y'], np.arange(20))})
xbc, ybc, abc = xray.broadcast_arrays(ds.x, ds.y, ds.a)
This raises ValueError: an index variable must be defined with 1-dimensional data.
If I change the last line to
xbc, ybc, abc = xray.broadcast_arrays(1*ds.x, 1*ds.y, ds.a)
it works fine.
I frequently use
broadcast_arraysto to feed xray variables to non-xray libraries (e.g. gsw.) Often I need to broadcast the coordinates and variables in order to do call functions that take both as arguments.I have found that
broadcast_arraysdoesn't work as I expect with coordinates. For exampleThis raises
ValueError: an index variable must be defined with 1-dimensional data.If I change the last line to
it works fine.