I have an xarray DataArray that is 2d. One dimension is frequency and the other is time. When creating the DataArray I specify the coordinates.
data = np.memmap(fname, np.float32, mode="c")
dx = xr.DataArray(data, coords=[dt,freqs], dims=["Time", "Frequency"])
The issue I am having is that if I define the time coordinate (dt) as a pandas date_range or a timedelta_range
times = pd.date_range("2020-10-13", periods=data.shape[0], freq='81.92U')
or
times = pd.timedelta_range(start="0 millisecond", periods=data.shape[0], freq='81.92U')
datashader throws the error
TypeError: Cannot cast ufunc less input from dtype('<m8[ns]') to dtype('<m8') with casting rule 'same_kind'
after running
import datasahder as ds
cvs = ds.Canvas(plot_width=1000, plot_height=300)
agg = cvs.raster(dx.T, interpolate='linear')
img = tf.Images(tf.shade(agg, cmap=gray, name="linear interpolation (default)"))
However, I can specify the time coordinate to just be a np.arange
object, which has the int
type and it works fine. But then I lose the datetime information from the array.
Is there a way around this?