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

Holoviews / Datashader integration #204

Open
Huite opened this issue Jan 25, 2024 · 0 comments
Open

Holoviews / Datashader integration #204

Huite opened this issue Jan 25, 2024 · 0 comments

Comments

@Huite
Copy link
Collaborator

Huite commented Jan 25, 2024

Holoviews and Datashader supports TriMesh/trimesh (resp.):
https://datashader.org/user_guide/Trimesh.html

This is obviously useful, especially for larger grids.

Althought not every 2D grid is triangular, it can be easily triangulated (which is done for a number of plotting methods, since matplotlib can will only draw contours for triangles e.g.).

The following suffices for Ugrid2d topologies in the _PlotMethods accessor:

    def to_holoviews(self):
        import holoviews
        import pandas as pd

        grid = self.grid
        da = self.darray
        (_, _, triangles), index = grid.triangulation
        name = getattr(da, "name", "data")

        vertices = pd.DataFrame(
            data=grid.node_coordinates,
            columns=("x", "y"),
        )
        triangles = pd.DataFrame(
            data=triangles,
            columns=("v0", "v1", "v2"),
        )

        dim = get_ugrid_dim(grid, da)
        if dim == NODE:
            vertices[name] = da
        elif dim == FACE:
            triangles[name] = da.isel({grid.face_dimension: index})
        else:
            raise ValueError("only supports data on nodes or faces")

        return holoviews.TriMesh((triangles, vertices))

Then, to draw something:

import holoviews as hv
from datashader import rasterize

hv.extension("matplotlib")
rasterize(uda.to_holoviews()).opts(colorbar=True)

What makes it not totally trivial:

  • What to do for 1D topologies? Return a network I guess? https://datashader.org/user_guide/Networks.html
  • The datashader/holoviews isn't entirely obvious to me. Should we add (more) methods to let it resemble the "standard" plotting arguments (i.e. like xarray/matplotlib?)
  • Should we default to bokeh/matplotlib as the extension? Not setting it results in nothing being shown.

Having to call rasterize yourself is a bit annoying. Something like .ugrid.holoviews.plot() could be an option but:

  • We're stacking a lot of accessors...
  • There are arguments for both the rasterize function as well as the plotting options. Should they be combined?

Secondly, there's a package called hvplot: https://hvplot.holoviz.org/
It adds an hvplot and interactive accessor to dataframes and xarray objects. This seems like it's more work, because it actually does data selection.

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

No branches or pull requests

1 participant