Add xugrid extension for TriMesh plots from unstructured grid data#1724
Add xugrid extension for TriMesh plots from unstructured grid data#1724rsignell wants to merge 7 commits into
Conversation
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>
|
Looks awesome! Took a quick glance at the code and maybe https://holoviz-dev.github.io/holoviz-skills/contributing-to-holoviz/cleanup/ could help clean it up (imports) I think pixi dev may need updating to run these tests in CI. This does increase maintenance burden for a fairly niche library, but I think it's worth having, if this is the one package for reading and parsing unstructured grid? However, I vaguely recall xarray natively supporting unstructured grids too with its new refactor of indexing? Alternatively, could maybe use https://github.com/panel-extensions/copier-template-panel-extension to create an hvplot-extension as well and put this there under hvplot-xugrid. |
- Move pandas import to module level in testxugrid.py (required dep, was scattered in 4 places) - Remove WHAT-explaining comments; keep only non-obvious WHY comments - Simplify over-verbose docstring in _make_simple_node_uda Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks @ahuang11 for taking a look! Since xugrid follows the same integration pattern as hvplot's other data backends (xarray, geopandas, etc.) and this is the canonical Python package for unstructured mesh data, I'd prefer to keep it as a PR to hvplot if you're open to it. On xarray advanced indexing — it'll help xugrid work more efficiently, but it won't replace the need for a package that understands how to subset unstructured meshes, interpolate face data to nodes, and so on -- xugrid is that package! I have updated the PR after telling Claude to run the "cleanup". Hope this looks better! |
|
It sounds fine to me, but I'll defer to @maximlt for his suggestions! |
|
@maximlt , just a note here that I'm still very interested in this -- we would love to share this capability with users in the CoastPredict project that does a lot of work with the SHYFEM triangular mesh coastal ocean model. |
|
Noted @rsignell, I'll review this week and get a release soon. |
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
hvplot/xugrid.py— registers.hvplotonxugrid.UgridDataArrayandxugrid.UgridDataset, enablinguda.hvplot.trimesh()for unstructured triangular mesh plotsHoloViewsConverter(converter.py) with atrimesh()method that supportsrasterize=True,geo=True,tiles=,cmap=, etc.hvPlotinplotting/core.pywith thehvPlotXugridsubclass;_get_converter()extracts mesh topology (node coords, face-node connectivity) and stores it inkwdshvplot/tests/testxugrid.pywith 243 lines of tests covering node-data, face-data, time/depth groupby, geo projection, and rasterizationFVCOM_xugrid.ipynb,STOFS_xugrid.ipynb) demonstrating real-world FVCOM and STOFS coastal ocean model outputUsage
Test plan
pytest hvplot/tests/testxugrid.py— all tests passimport hvplot.xugridis a no-op (clean ImportError) when xugrid is not installed🤖 Generated with Claude Code