mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Fix use of cwd in plot_inline and Plot.to_ipython_image
This commit is contained in:
parent
dedafa49f6
commit
a61f3f534b
2 changed files with 8 additions and 8 deletions
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue