From 74d7cf483b74804ae256ee0a34e8bae38ec39c46 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 10:39:12 +0100 Subject: [PATCH 1/3] added warning for outline usage --- examples/plot_minimal_2d_example.py | 2 +- examples/plot_minimal_example.py | 2 +- examples/plot_sweep_through_slice_indexes.py | 7 ++++--- examples/plot_two_tallies_combined.py | 2 +- examples/plot_with_custom_color_map.py | 6 +++--- src/openmc_regular_mesh_plotter/__init__.py | 4 ++-- src/openmc_regular_mesh_plotter/core.py | 10 ++++++---- tests/test_units.py | 3 ++- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/examples/plot_minimal_2d_example.py b/examples/plot_minimal_2d_example.py index f290368..1af84b1 100644 --- a/examples/plot_minimal_2d_example.py +++ b/examples/plot_minimal_2d_example.py @@ -1,7 +1,7 @@ import openmc from matplotlib.colors import LogNorm -from openmc_regular_mesh_plotter import plot_mesh_tally +from openmc_regular_mesh_plotter import plot_mesh_tally # MATERIALS mat_1 = openmc.Material() diff --git a/examples/plot_minimal_example.py b/examples/plot_minimal_example.py index 04342ee..f6bedaf 100644 --- a/examples/plot_minimal_example.py +++ b/examples/plot_minimal_example.py @@ -1,7 +1,7 @@ import openmc from matplotlib.colors import LogNorm -from openmc_regular_mesh_plotter import plot_mesh_tally +from openmc_regular_mesh_plotter import plot_mesh_tally # MATERIALS mat_1 = openmc.Material() diff --git a/examples/plot_sweep_through_slice_indexes.py b/examples/plot_sweep_through_slice_indexes.py index 9c321f2..a3dd299 100644 --- a/examples/plot_sweep_through_slice_indexes.py +++ b/examples/plot_sweep_through_slice_indexes.py @@ -2,12 +2,13 @@ # It is also set up to accept any geometry and the mesh tally will adapt to the geometry dimensions -import openmc +import matplotlib import numpy as np +import openmc +from matplotlib import cm from matplotlib.colors import LogNorm + from openmc_regular_mesh_plotter import plot_mesh_tally -from matplotlib import cm -import matplotlib # sets the font for the axis matplotlib.rc("font", **{"family": "normal", "size": 22}) diff --git a/examples/plot_two_tallies_combined.py b/examples/plot_two_tallies_combined.py index 10d6c87..fe6af27 100644 --- a/examples/plot_two_tallies_combined.py +++ b/examples/plot_two_tallies_combined.py @@ -1,7 +1,7 @@ import openmc from matplotlib.colors import LogNorm -from openmc_regular_mesh_plotter import plot_mesh_tally +from openmc_regular_mesh_plotter import plot_mesh_tally # MATERIALS mat_1 = openmc.Material() diff --git a/examples/plot_with_custom_color_map.py b/examples/plot_with_custom_color_map.py index cdac48a..a5ae7af 100644 --- a/examples/plot_with_custom_color_map.py +++ b/examples/plot_with_custom_color_map.py @@ -2,12 +2,12 @@ # It is also set up to accept any geometry and the mesh tally will adapt to the geometry dimensions +import matplotlib.pyplot as plt import openmc -from matplotlib.colors import LogNorm -from openmc_regular_mesh_plotter import plot_mesh_tally from matplotlib import cm -import matplotlib.pyplot as plt +from matplotlib.colors import LogNorm +from openmc_regular_mesh_plotter import plot_mesh_tally # materials mat_concrete = openmc.Material() diff --git a/src/openmc_regular_mesh_plotter/__init__.py b/src/openmc_regular_mesh_plotter/__init__.py index dd0f602..146eafb 100644 --- a/src/openmc_regular_mesh_plotter/__init__.py +++ b/src/openmc_regular_mesh_plotter/__init__.py @@ -1,7 +1,7 @@ try: - from importlib.metadata import version, PackageNotFoundError + from importlib.metadata import PackageNotFoundError, version except (ModuleNotFoundError, ImportError): - from importlib_metadata import version, PackageNotFoundError + from importlib_metadata import PackageNotFoundError, version try: __version__ = version("openmc_regular_mesh_plotter") except PackageNotFoundError: diff --git a/src/openmc_regular_mesh_plotter/core.py b/src/openmc_regular_mesh_plotter/core.py index b42b905..f3d04c3 100644 --- a/src/openmc_regular_mesh_plotter/core.py +++ b/src/openmc_regular_mesh_plotter/core.py @@ -1,13 +1,13 @@ import math +import typing +import warnings from pathlib import Path from tempfile import TemporaryDirectory -import typing -import openmc + +import matplotlib.pyplot as plt import numpy as np import openmc import openmc.checkvalue as cv -import matplotlib.pyplot as plt - from packaging import version if version.parse(openmc.__version__) < version.parse("0.13.3"): @@ -182,6 +182,8 @@ def plot_mesh_tally( if colorbar: fig.colorbar(im, **colorbar_kwargs) + if outline and geometry is None: + warnings.warn('output has been set to True but the geometry has not been set. When setting outline to True please also provide the geometry. Plotting without the outline.') if outline and geometry is not None: import matplotlib.image as mpimg diff --git a/tests/test_units.py b/tests/test_units.py index df33329..e6b9826 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -1,7 +1,8 @@ import openmc +import pytest from matplotlib.colors import LogNorm + from openmc_regular_mesh_plotter import plot_mesh_tally -import pytest @pytest.fixture() From 0b0198ba962810c1ab97374199734d983004479c Mon Sep 17 00:00:00 2001 From: shimwell Date: Thu, 9 May 2024 09:39:32 +0000 Subject: [PATCH 2/3] [skip ci] Apply formatting changes --- src/openmc_regular_mesh_plotter/core.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/openmc_regular_mesh_plotter/core.py b/src/openmc_regular_mesh_plotter/core.py index f3d04c3..d643ce6 100644 --- a/src/openmc_regular_mesh_plotter/core.py +++ b/src/openmc_regular_mesh_plotter/core.py @@ -183,7 +183,9 @@ def plot_mesh_tally( fig.colorbar(im, **colorbar_kwargs) if outline and geometry is None: - warnings.warn('output has been set to True but the geometry has not been set. When setting outline to True please also provide the geometry. Plotting without the outline.') + warnings.warn( + "output has been set to True but the geometry has not been set. When setting outline to True please also provide the geometry. Plotting without the outline." + ) if outline and geometry is not None: import matplotlib.image as mpimg From 6709070296666e87275833292409e83a1bdb98dd Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 10:46:44 +0100 Subject: [PATCH 3/3] raising value error for incorrect usage --- src/openmc_regular_mesh_plotter/core.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/openmc_regular_mesh_plotter/core.py b/src/openmc_regular_mesh_plotter/core.py index f3d04c3..bb2e5d6 100644 --- a/src/openmc_regular_mesh_plotter/core.py +++ b/src/openmc_regular_mesh_plotter/core.py @@ -1,6 +1,5 @@ import math import typing -import warnings from pathlib import Path from tempfile import TemporaryDirectory @@ -183,7 +182,7 @@ def plot_mesh_tally( fig.colorbar(im, **colorbar_kwargs) if outline and geometry is None: - warnings.warn('output has been set to True but the geometry has not been set. When setting outline to True please also provide the geometry. Plotting without the outline.') + raise ValueError('When calling plot_mesh_tally with outline=True the geometry should also be provided. Either set outline to False or set the geometry to and openmc.Geometry object') if outline and geometry is not None: import matplotlib.image as mpimg