From a61f3f534bf155143511cd603e770ad66bc1bbd1 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 31 Mar 2022 14:45:59 -0500 Subject: [PATCH] Fix use of cwd in plot_inline and Plot.to_ipython_image --- openmc/executor.py | 4 ++-- openmc/plots.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openmc/executor.py b/openmc/executor.py index 63653f4d00..357fa64d55 100644 --- a/openmc/executor.py +++ b/openmc/executor.py @@ -166,13 +166,13 @@ def plot_inline(plots, openmc_exec='openmc', cwd='.'): plots = [plots] # Create plots.xml - openmc.Plots(plots).export_to_xml() + openmc.Plots(plots).export_to_xml(cwd) # Run OpenMC in geometry plotting mode plot_geometry(False, openmc_exec, cwd) if plots is not None: - images = [_get_plot_image(p) for p in plots] + images = [_get_plot_image(p, cwd) for p in plots] display(*images) diff --git a/openmc/plots.py b/openmc/plots.py index 3599a32742..6bce8894c8 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -164,16 +164,16 @@ _SVG_COLORS = { } -def _get_plot_image(plot): +def _get_plot_image(plot, cwd): from IPython.display import Image # Make sure .png file was created stem = plot.filename if plot.filename is not None else f'plot_{plot.id}' - png_file = f'{stem}.png' - if not Path(png_file).exists(): + png_file = Path(cwd) / f'{stem}.png' + if not png_file.exists(): raise FileNotFoundError(f"Could not find .png image for plot {plot.id}") - return Image(png_file) + return Image(str(png_file)) class Plot(IDManagerMixin): @@ -784,13 +784,13 @@ class Plot(IDManagerMixin): """ # Create plots.xml - Plots([self]).export_to_xml() + Plots([self]).export_to_xml(cwd) # Run OpenMC in geometry plotting mode openmc.plot_geometry(False, openmc_exec, cwd) # Return produced image - return _get_plot_image(self) + return _get_plot_image(self, cwd) class Plots(cv.CheckedList):