Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Canvas.lines of 2D xarray with common x coordinates #1278

Closed
ianthomas23 opened this issue Sep 15, 2023 · 2 comments
Closed

Support Canvas.lines of 2D xarray with common x coordinates #1278

ianthomas23 opened this issue Sep 15, 2023 · 2 comments

Comments

@ianthomas23
Copy link
Member

I would like to support the xarray equivalent of LinesAxis1XConstant which has multiple lines that all share the same x coordinates. The xarray.DataArray would be 2D, one dimension would be the x dimension and the other could be anything including a string/categorical dimension. It is best illustrated by an example:

import datashader as ds
import numpy as np
import xarray as xr

xr_ds = xr.Dataset(
    data_vars=dict(
        name=(("channel", "x"), [[2, 1, 0, 1, 2], [1, 1, 1, 1, 1]]),
    ),
    coords=dict(
        channel=("channel", ['a', 'b']),
        x=("x", np.arange(5)),
    ),
)

canvas = ds.Canvas(plot_height=3, plot_width=5)
agg = canvas.line(source=xr_ds, x="x", y="name", agg=ds.count())

The x coordinates here have length 5 and the DataArray is of shape (2, 5). The output aggregation here would be something like

<xarray.DataArray (y: 3, x: 5)>
array([[0, 0, 1, 0, 0],
       [1, 2, 1, 2, 1],
       [1, 0, 0, 0, 1]], dtype=uint32)

This should support both dask and CUDA backed xarrays, and the 2D dimensions could be in either order as we do not want to force the user to do an unnecessary array transpose.

We do support some use of xarray for lines at the moment, but it is restricted to 1D x and y values.

@jbednar
Copy link
Member

jbednar commented Sep 18, 2023

Sounds good to me!

@ianthomas23
Copy link
Member Author

Closed by #1282.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants