From 66ef28a3854769ea3baec19191c1ec138dbad20c Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 6 Oct 2021 11:51:38 -0500 Subject: [PATCH] Remove convert_exec arguments, update documentation --- .gitignore | 3 ++- docs/source/io_formats/plots.rst | 29 ++++++++----------------- openmc/executor.py | 12 ++++++----- openmc/plots.py | 37 ++++++++++---------------------- tests/unit_tests/test_model.py | 3 +-- 5 files changed, 30 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index f328d7b9a..88e59895d 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ scripts/*.tar.* scripts/G4EMLOW*/ # Images +*.png *.ppm *.voxel *.vti @@ -103,4 +104,4 @@ CMakeSettings.json .vscode/ # Python pickle files -*.pkl \ No newline at end of file +*.pkl diff --git a/docs/source/io_formats/plots.rst b/docs/source/io_formats/plots.rst index 966d2b802..e6b75eafc 100644 --- a/docs/source/io_formats/plots.rst +++ b/docs/source/io_formats/plots.rst @@ -10,9 +10,9 @@ of the plots.xml is simply ```` and any number output plots can be defined with ```` 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. diff --git a/openmc/executor.py b/openmc/executor.py index b64d50125..63653f4d0 100644 --- a/openmc/executor.py +++ b/openmc/executor.py @@ -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) diff --git a/openmc/plots.py b/openmc/plots.py index 424a4eb84..521be95ad 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -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): diff --git a/tests/unit_tests/test_model.py b/tests/unit_tests/test_model.py index 994130f89..d22485b3c 100644 --- a/tests/unit_tests/test_model.py +++ b/tests/unit_tests/test_model.py @@ -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):