From 004199c49d43031e9737f0f70b5b9ae66626c654 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 5 Oct 2022 09:08:02 -0500 Subject: [PATCH] Handle possibility of .ppm file in Universe.plot --- openmc/plots.py | 4 +++- openmc/universe.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/openmc/plots.py b/openmc/plots.py index b22ee9125..2708683b1 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -171,7 +171,9 @@ def _get_plot_image(plot, cwd): stem = plot.filename if plot.filename is not None else f'plot_{plot.id}' png_file = Path(cwd) / f'{stem}.png' if not png_file.exists(): - raise FileNotFoundError(f"Could not find .png image for plot {plot.id}") + raise FileNotFoundError( + f"Could not find .png image for plot {plot.id}. Your version of " + "OpenMC may not be built against libpng.") return Image(str(png_file)) diff --git a/openmc/universe.py b/openmc/universe.py index 0c8a26a48..db828e33c 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -358,7 +358,10 @@ class Universe(UniverseBase): model.plot_geometry(False, cwd=tmpdir, openmc_exec=openmc_exec) # Read image from file - img = mpimg.imread(Path(tmpdir) / f'plot_{plot.id}.png') + img_path = Path(tmpdir) / f'plot_{plot.id}.png' + if not img_path.is_file(): + img_path = img_path.with_suffix('.ppm') + img = mpimg.imread(img_path) # Create a figure sized such that the size of the axes within # exactly matches the number of pixels specified