0

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?

ofionnad
  • 41
  • 1
  • If your goal is to use the datetime information for plotting, you can invoke Datashader via hvPlot (hvplot.holoviz.org) or HoloViews (holoviews.org), which will convert the datetimes into an axis that Datashader can handle, then render the data, and then label the axes with the original datetime information. – James A. Bednar Oct 29 '20 at 19:25
  • However, that approach won't help if you want an xarray DataArray at the end to use for further computations, in which case it would be better if Datashader supported datetime axes directly or if Datashader had a utility to do what HoloViews does. However, both those latter options are just ideas, with no one to implement them yet! – James A. Bednar Oct 29 '20 at 19:26
  • Hi James, thanks for responding. Yeah I have the same issue if I use holoviews.operation.datashade, it gives the same error. Ideally yes, I would like to keep the workable xarray, but doesn't seem to be possible. I will try hvPlot! I actually did not notice the difference between holoviews and holoviz. – ofionnad Oct 30 '20 at 10:08
  • I can get all the image functionality I want with just datashader, except that the images have no axes or labels, and there doesn't seem to be an easy way to implement that with just datashader. All I can manage to do is to add a title to the image. – ofionnad Oct 30 '20 at 10:25

0 Answers0