Merge pull request #2251 from paulromano/universe-plot-ppm

Handle possibility of .ppm file in Universe.plot
This commit is contained in:
Patrick Shriwise 2022-10-18 12:27:24 -05:00 committed by GitHub
commit e2f6f5d1ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -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))

View file

@ -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