Skip to content

Performance: use ImageData when grid has uniform axis spacing#81

Merged
banesullivan merged 19 commits intomainfrom
perf/use-image-data
Mar 18, 2026
Merged

Performance: use ImageData when grid has uniform axis spacing#81
banesullivan merged 19 commits intomainfrom
perf/use-image-data

Conversation

@banesullivan
Copy link
Copy Markdown
Member

@banesullivan banesullivan commented Jul 8, 2025

Use pv.ImageData over pv.RectilinearGrid when the axes have uniform spacing.

This yields significant performance improvements, especially if wanting to volume render:

import xarray as xr
import pvxarray
import pyvista as pv

ds = xr.tutorial.load_dataset("cells3d")
da = ds.images
nuclei = da.sel(c='nuclei').pyvista.mesh(x="x", y="y", z="z")

pl = pv.Plotter()
pl.add_volume(nuclei, clim=(0, 30000), opacity='sigmoid')
pl.enable_terrain_style()
pl.show()

screenshot (7)

The tests here are working around an upstream bug: pyvista/pyvista#7686

maintenance

  • Updates the GitHub Actions to run again
  • Bump the required version of PyVista
  • Fix deprecation issues
  • More python testing versions

Comment thread pvxarray/io.py Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jul 10, 2025

Codecov Report

❌ Patch coverage is 80.95238% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.90%. Comparing base (cc606e4) to head (761029b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pvxarray/structured.py 40.00% 6 Missing ⚠️
pvxarray/rectilinear.py 84.00% 4 Missing ⚠️
pvxarray/accessor.py 86.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #81      +/-   ##
==========================================
- Coverage   93.60%   92.90%   -0.70%     
==========================================
  Files          11       11              
  Lines         657      691      +34     
==========================================
+ Hits          615      642      +27     
- Misses         42       49       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

banesullivan and others added 15 commits July 10, 2025 12:40
- Merge main branch (PRs #83-#91) into perf/use-image-data
- Resolve all merge conflicts, keeping main's improvements
  (docstrings, type annotations, CF support, Dataset accessor)
- Address review feedback: use _generate_rectilinear_coords()
  in io.py instead of manual cumsum
- Bump minimum PyVista to >=0.45 for _generate_rectilinear_coords
- Update tests for ImageData return type
- Add comprehensive ImageData optimization tests
- Add benchmark script demonstrating ImageData vs RectilinearGrid

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Demonstrates ImageData auto-detection with the cells3d dataset,
GPU-accelerated volume rendering, dual-channel visualization,
uniform vs non-uniform spacing comparison, and roundtrip conversion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Volume rendering is the primary motivation for the ImageData
optimization. The benchmark now measures add_volume + render
across mesh types and grid sizes, tests mapper compatibility,
and shows ~1.9x speedup on the cells3d dataset.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@banesullivan banesullivan merged commit 6d1b4da into main Mar 18, 2026
6 checks passed
@banesullivan banesullivan deleted the perf/use-image-data branch March 18, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants