diff --git a/openmc/plots.py b/openmc/plots.py index df4a766331..02a44449be 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -171,8 +171,14 @@ 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 = Path(cwd) / f'{stem}.png' + png_filename = plot.filename if plot.filename is not None else f'plot_{plot.id}' + + # Add file extension if not already present. The C++ code added it + # automatically if it wasn't present. + if Path(png_filename).suffix != ".png": + png_filename += ".png" + + png_file = Path(cwd) / png_filename if not png_file.exists(): raise FileNotFoundError( f"Could not find .png image for plot {plot.id}. Your version of " @@ -630,7 +636,7 @@ class Plot(PlotBase): cv.check_type('plot meshlines', meshlines, dict) if 'type' not in meshlines: msg = f'Unable to set the meshlines to "{meshlines}" which ' \ - 'does not have a "type" key' + 'does not have a "type" key' raise ValueError(msg) elif meshlines['type'] not in ['tally', 'entropy', 'ufs', 'cmfd']: @@ -968,8 +974,13 @@ class Plot(PlotBase): # Run OpenMC in geometry plotting mode and produces a h5 file openmc.plot_geometry(False, openmc_exec, cwd) - stem = self.filename if self.filename is not None else f'plot_{self.id}' - h5_voxel_file = Path(cwd) / f'{stem}.h5' + h5_voxel_filename = self.filename if self.filename is not None else f'plot_{self.id}' + + # Add file extension if not already present + if Path(h5_voxel_filename).suffix != ".h5": + h5_voxel_filename += ".h5" + + h5_voxel_file = Path(cwd) / h5_voxel_filename if output is None: output = h5_voxel_file.with_suffix('.vti')