Add F.plot(...) for one-line PyVista field visualization#1176
Add F.plot(...) for one-line PyVista field visualization#1176RemDelaporteMathurin with Copilot wants to merge 23 commits into
F.plot(...) for one-line PyVista field visualization#1176Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1176 +/- ##
==========================================
- Coverage 94.76% 94.68% -0.09%
==========================================
Files 46 47 +1
Lines 3534 3592 +58
==========================================
+ Hits 3349 3401 +52
- Misses 185 191 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
F.plot(...) for one-line PyVista field visualization
| try: | ||
| import pyvista | ||
| except ImportError as import_error: | ||
| raise ImportError( | ||
| "pyvista is required for plotting. Install it with `pip install pyvista`." | ||
| ) from import_error |
There was a problem hiding this comment.
We're already importing pyvista in the conda env; maybe we could just make it a requirement in the pyproject.toml as well, and add it to the festim-feedstock conda recipe too?
There was a problem hiding this comment.
which conda env? as in it's a dependency inthe FESTIM conda-forge recipe?
| else: | ||
| if field.post_processing_solution is not None: | ||
| raise ValueError( | ||
| "Problem seems to be HydrogenTransportProblem but a subdomain" | ||
| " was provided." | ||
| ) | ||
| if not field.subdomain_to_post_processing_solution: | ||
| raise ValueError( | ||
| f"Species {field.name} has no subdomain post-processing solutions." | ||
| ) | ||
| if subdomain not in field.subdomain_to_post_processing_solution: | ||
| raise ValueError( | ||
| f"Species {field.name} has no post-processing solution on subdomain " | ||
| f"{subdomain}." | ||
| ) |
There was a problem hiding this comment.
We could write some quick, simple tests to make sure these get raised, and that errors are not raised beforehand elsewhere
| return field.subdomain_to_post_processing_solution[subdomain] | ||
|
|
||
|
|
||
| def _make_ugrid(solution, pyvista_module, name="c"): |
There was a problem hiding this comment.
Even its a hidden method, could use some doc strings
| raise TypeError("field must be of type festim.Species or a list of festim.Species") | ||
|
|
||
|
|
||
| def _get_solution(field: Species, subdomain=None): |
| DEFAULT_TITLE_FONT_SIZE = 12 | ||
|
|
||
|
|
||
| def _normalize_fields(field: Species | list[Species]) -> list[Species]: |
jhdark
left a comment
There was a problem hiding this comment.
Just some minor changes from me
|
|
||
| from festim.species import Species | ||
|
|
||
| DEFAULT_TITLE_FONT_SIZE = 12 |
There was a problem hiding this comment.
This is only used in one place, dont think its needed
There was a problem hiding this comment.
I would keep it here as 1. we may use it in other places 2. it helps keep the "config" variables easily accessible
Co-authored-by: James Dark <65899899+jhdark@users.noreply.github.com>
Description
Summary
This PR adds a lightweight plotting API for species fields so users can generate PyVista visuals in one line, including multi-species and subdomain-aware cases.
F.plot(...)entrypoint (src/festim/plot.py, exported viasrc/festim/__init__.py).subdomain=...for mixed-domain/discontinuous workflows.filename=...for screenshot output andshow_edges=Trueshortcut.**kwargstoplotter.add_mesh(...).pyvistadependency.test/test_plot.pycovering API behavior, edge cases, and error paths.Related Issues
Handled by automatic issue linking in the PR system.
Motivation and Context
Plotting fields with PyVista currently requires repetitive boilerplate (
vtk_mesh, grid wiring, plotter setup). This change introduces a small wrapper to make field visualization immediate while preserving control through optional arguments.Type of Change
Testing
pytest)Code Quality Checklist
ruff format .)ruff check .)Documentation
Breaking Changes
None.
Screenshots/Examples
Additional Notes
This PR keeps scope intentionally narrow: one public plotting helper plus focused tests around that API surface.