Skip to content

Add xugrid extension for TriMesh plots from unstructured grid data#1724

Open
rsignell wants to merge 6 commits into
holoviz:mainfrom
OpenScienceComputing:xugrid
Open

Add xugrid extension for TriMesh plots from unstructured grid data#1724
rsignell wants to merge 6 commits into
holoviz:mainfrom
OpenScienceComputing:xugrid

Conversation

@rsignell
Copy link
Copy Markdown

@rsignell rsignell commented May 12, 2026

Holoviz folks, as you can tell, I made this with Claude Code, and I've been using it for the past few months for many applications. But I have no idea how well it's coded.

@Huite did give it a quick look and didn't raise any red flags.

There is discussion on the xugrid repo here: Deltares/xugrid#204 (comment)

Please let me know if there is anything else I can do -- I'd love to see trimesh supported by hvplot!

Summary

  • Adds hvplot/xugrid.py — registers .hvplot on xugrid.UgridDataArray and xugrid.UgridDataset, enabling uda.hvplot.trimesh() for unstructured triangular mesh plots
  • Extends HoloViewsConverter (converter.py) with a trimesh() method that supports rasterize=True, geo=True, tiles=, cmap=, etc.
  • Extends hvPlot in plotting/core.py with the hvPlotXugrid subclass; _get_converter() extracts mesh topology (node coords, face-node connectivity) and stores it in kwds
  • Defers face-to-node interpolation until after groupby slicing, so extra dimensions (time, sigma layers) become interactive widgets rather than requiring explicit selection
  • Adds hvplot/tests/testxugrid.py with 243 lines of tests covering node-data, face-data, time/depth groupby, geo projection, and rasterization
  • Includes two example notebooks (FVCOM_xugrid.ipynb, STOFS_xugrid.ipynb) demonstrating real-world FVCOM and STOFS coastal ocean model output

Usage

import hvplot.xugrid

# UgridDataArray with node data
uda.hvplot.trimesh(clim=(0, 2), cmap='viridis', rasterize=True, tiles='OSM', geo=True)

# Face data with time/depth sliders (auto groupby)
uda_3d.hvplot.trimesh(rasterize=True)  # sliders for time + siglay

Test plan

  • pytest hvplot/tests/testxugrid.py — all tests pass
  • Manual verification with FVCOM/STOFS example notebooks
  • Confirm import hvplot.xugrid is a no-op (clean ImportError) when xugrid is not installed

🤖 Generated with Claude Code

rsignell and others added 6 commits May 12, 2026 07:42
Add hvplot.xugrid module that patches .hvplot onto xu.UgridDataArray and
xu.UgridDataset, enabling users to create TriMesh plots directly from
xugrid objects (e.g. uda.hvplot.trimesh()). Supports rasterize, geo/tiles,
face-to-node averaging, quad mesh triangulation, and extra dimension reduction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use isel for integer values and sel only for non-integer values like
time strings, so dimensions like FVCOM's siglay that lack a simple
1D index are handled correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…t selection

Extra dimensions (time, siglay, etc.) now automatically become interactive
slider widgets, matching standard hvplot behavior. Users can still fix a
dimension by passing it explicitly (e.g. siglay=0). The xugrid data is
passed as xarray to the converter so its existing groupby/DynamicMap
machinery handles widget creation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Only include proper 1D dimension coordinates when building the xarray
Dataset for the converter. 2D coords like FVCOM's siglay(siglay, node)
were being copied through, breaking the groupby slider machinery.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously, face data (e.g. u-velocity) was converted to nodes via
to_node().mean() on the full multi-dimensional array before the groupby
machinery sliced by time/level, causing hangs on large datasets like FVCOM.
Now the conversion is deferred to the converter's trimesh() method where
the data has already been reduced to a single slice.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Covers node data, face data (with face-to-node interpolation), extra
time dimensions creating DynamicMap groupby sliders, and UgridDataset inputs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant