Fix use of cwd in plot_inline and Plot.to_ipython_image

This commit is contained in:
Paul Romano 2022-03-31 14:45:59 -05:00
parent dedafa49f6
commit a61f3f534b
2 changed files with 8 additions and 8 deletions

View file

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

View file

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