Remove convert_exec arguments, update documentation

This commit is contained in:
Paul Romano 2021-10-06 11:51:38 -05:00
parent 613d6e3ba2
commit 66ef28a385
5 changed files with 30 additions and 54 deletions

3
.gitignore vendored
View file

@ -64,6 +64,7 @@ scripts/*.tar.*
scripts/G4EMLOW*/
# Images
*.png
*.ppm
*.voxel
*.vti
@ -103,4 +104,4 @@ CMakeSettings.json
.vscode/
# Python pickle files
*.pkl
*.pkl

View file

@ -10,9 +10,9 @@ of the plots.xml is simply ``<plots>`` and any number output plots can be
defined with ``<plot>`` sub-elements. Two plot types are currently implemented
in openMC:
* ``slice`` 2D pixel plot along one of the major axes. Produces a PPM image
* ``slice`` 2D pixel plot along one of the major axes. Produces a PNG image
file.
* ``voxel`` 3D voxel data dump. Produces a binary file containing voxel xyz
* ``voxel`` 3D voxel data dump. Produces an HDF5 file containing voxel xyz
position and cell or material id.
@ -68,20 +68,14 @@ sub-elements:
:type:
Keyword for type of plot to be produced. Currently only "slice" and "voxel"
plots are implemented. The "slice" plot type creates 2D pixel maps saved in
the PPM file format. PPM files can be displayed in most viewers (e.g. the
default Gnome viewer, IrfanView, etc.). The "voxel" plot type produces a
binary datafile containing voxel grid positioning and the cell or material
(specified by the ``color`` tag) at the center of each voxel. These
datafiles can be processed into VTK files using the :ref:`scripts_voxel`
script provided with OpenMC, and subsequently viewed with a 3D viewer such
as VISIT or Paraview. See the :ref:`io_voxel` for information about the
datafile structure.
the PNG file format. The "voxel" plot type produces a binary datafile
containing voxel grid positioning and the cell or material (specified by the
``color`` tag) at the center of each voxel. Voxel plot files can be
processed into VTK files using the :ref:`scripts_voxel` script provided with
OpenMC and subsequently viewed with a 3D viewer such as VISIT or Paraview.
See the :ref:`io_voxel` for information about the datafile structure.
.. note:: Since the PPM format is saved without any kind of compression,
the resulting file sizes can be quite large. Saving the image in
the PNG format can often times reduce the file size by orders of
magnitude without any loss of image quality. Likewise,
high-resolution voxel files produced by OpenMC can be quite large,
.. note:: High-resolution voxel files produced by OpenMC can be quite large,
but the equivalent VTK files will be significantly smaller.
*Default*: "slice"
@ -94,11 +88,6 @@ attribute or sub-element:
directions for "slice" and "voxel" plots, respectively. Should be two or
three integers separated by spaces.
.. warning:: The ``pixels`` input determines the output file size. For the
PPM format, 10 million pixels will result in a file just under
30 MB in size. A 10 million voxel binary file will be around
40 MB.
.. warning:: If the aspect ratio defined in ``pixels`` does not match the
aspect ratio defined in ``width`` the plot may appear stretched
or squeezed.

View file

@ -137,9 +137,14 @@ def plot_geometry(output=True, openmc_exec='openmc', cwd='.'):
_run([openmc_exec, '-p'], output, cwd)
def plot_inline(plots, openmc_exec='openmc', cwd='.', convert_exec='convert'):
def plot_inline(plots, openmc_exec='openmc', cwd='.'):
"""Display plots inline in a Jupyter notebook.
.. versionchanged:: 0.13.0
The *convert_exec* argument was removed since OpenMC now produces
.png images directly.
Parameters
----------
plots : Iterable of openmc.Plot
@ -148,9 +153,6 @@ def plot_inline(plots, openmc_exec='openmc', cwd='.', convert_exec='convert'):
Path to OpenMC executable
cwd : str, optional
Path to working directory to run in
convert_exec : str, optional
Command that can convert PPM files into PNG files. Only used if your
OpenMC installation was not compiled against libpng.
Raises
------
@ -170,7 +172,7 @@ def plot_inline(plots, openmc_exec='openmc', cwd='.', convert_exec='convert'):
plot_geometry(False, openmc_exec, cwd)
if plots is not None:
images = [_get_plot_image(p, convert_exec) for p in plots]
images = [_get_plot_image(p) for p in plots]
display(*images)

View file

@ -166,28 +166,15 @@ _SVG_COLORS = {
}
def _get_plot_image(plot, convert_exec):
def _get_plot_image(plot):
from IPython.display import Image
# Check for .png first
# 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 Path(png_file).exists():
return Image(png_file)
if not Path(png_file).exists():
raise FileNotFoundError(f"Could not find .png image for plot {plot.id}")
# If .png doesn't exist, try finding .ppm
ppm_file = f'{stem}.ppm'
if not Path(ppm_file).exists():
raise FileNotFoundError(f"Could not find image for plot {plot.id}")
# Check that 'convert' command exists
if shutil.which(convert_exec) is None:
raise RuntimeError(
f"ImageMagick is needed to convert {ppm_file} to .png format. Please "
"install ImageMagick and try again.")
# Convert .ppm to .png and return image
subprocess.check_call([convert_exec, ppm_file, png_file])
return Image(png_file)
@ -697,13 +684,14 @@ class Plot(IDManagerMixin):
return element
def to_ipython_image(self, openmc_exec='openmc', cwd='.',
convert_exec='convert'):
def to_ipython_image(self, openmc_exec='openmc', cwd='.'):
"""Render plot as an image
This method runs OpenMC in plotting mode to produce a .png file. If your
installation of OpenMC was not compiled against libpng, try converting
the fallback .ppm file to .png using ImageMagick's convert command.
This method runs OpenMC in plotting mode to produce a .png file.
.. versionchanged:: 0.13.0
The *convert_exec* argument was removed since OpenMC now produces
.png images directly.
Parameters
----------
@ -711,9 +699,6 @@ class Plot(IDManagerMixin):
Path to OpenMC executable
cwd : str, optional
Path to working directory to run in
convert_exec : str, optional
Command that can convert PPM files into PNG files. Only used if your
OpenMC installation was not compiled against libpng.
Returns
-------
@ -728,7 +713,7 @@ class Plot(IDManagerMixin):
openmc.plot_geometry(False, openmc_exec, cwd)
# Return produced image
return _get_plot_image(self, convert_exec)
return _get_plot_image(self)
class Plots(cv.CheckedList):

View file

@ -329,8 +329,7 @@ def test_plots(run_in_tmpdir, pin_model_attributes, mpi_intracomm):
test_model = openmc.Model(geom, mats, settings, tals, plots)
# This test cannot check the correctness of the plot, but it can
# check that a plot was made and that the expected ppm and png files are
# there
# check that a plot was made and that the expected png files are there
# We will run the test twice, the first time without C API, the second with
for i in range(2):