diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 0d9bdb2..98af70c 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -28,7 +28,8 @@ jobs: - name: install dependancies run: | - conda install -c conda-forge openmc + conda install -c conda-forge mamba + mamba install -c conda-forge openmc - name: install package run: | diff --git a/CITATION.cff b/CITATION.cff index 48da971..3b13c28 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -4,6 +4,9 @@ authors: - family-names: "Shimwell" given-names: "Jonathan" orcid: "https://orcid.org/0000-0001-6909-0946" +- family-names: "Delaporte-Mathurin" + given-names: "RĂ©mi" + orcid: "https://orcid.org/0000-0003-1064-8882" title: "A Python package for plotting regular mesh tally results from neutronics simulations." version: 0.1.0 date-released: 2021-10-30 diff --git a/README.md b/README.md index 9f21165..2501d0c 100644 --- a/README.md +++ b/README.md @@ -50,15 +50,16 @@ Example 1 shows a OpenMC tally plotted ```python import regular_mesh_plotter as rmp +import matplotlib.pyplot as plt -my_plot = rmp.plot_regular_mesh_tally( +rmp.plot_regular_mesh_tally( tally=my_tally, std_dev_or_tally_value="tally_value", x_label="X [cm]", y_label="Y [cm]", ) -my_plot.save_fig('openmc_mesh_tally_plot.png') +plt.savefig('openmc_mesh_tally_plot.png') ``` Example 4 shows a OpenMC tally plotted with an underlying DAGMC geometry diff --git a/examples/examples_from_readme.py b/examples/examples_from_readme.py index 3c23db6..1cf2073 100644 --- a/examples/examples_from_readme.py +++ b/examples/examples_from_readme.py @@ -2,7 +2,7 @@ from dagmc_geometry_slice_plotter import plot_slice_of_dagmc_geometry from stl_to_h5m import stl_to_h5m - +import matplotlib.pyplot as plt import paramak my_reactor = paramak.SubmersionTokamak( @@ -45,14 +45,14 @@ ) -plot = plot_slice_of_dagmc_geometry( +plot_slice_of_dagmc_geometry( dagmc_file_or_trimesh_object="dagmc.h5m", plane_normal=[0, 0, 1], output_filename="my_plot1.png", ) -plot = plot_slice_of_dagmc_geometry( +plot_slice_of_dagmc_geometry( dagmc_file_or_trimesh_object="dagmc.h5m", plane_origin=[0, 0, 300], plane_normal=[0, 0, 1], @@ -60,14 +60,14 @@ ) -plot = plot_slice_of_dagmc_geometry( +plot_slice_of_dagmc_geometry( dagmc_file_or_trimesh_object="dagmc.h5m", plane_normal=[0, 1, 0], rotate_plot=45, output_filename="my_plot3.png", ) -plot.savefig("big.png", dpi=600) +plt.savefig("big.png", dpi=600) plot_slice_of_dagmc_geometry( dagmc_file_or_trimesh_object="dagmc.h5m", diff --git a/examples/plot_regular_mesh_dose_tally.py b/examples/plot_regular_mesh_dose_tally.py index 23c13df..9bcbf83 100644 --- a/examples/plot_regular_mesh_dose_tally.py +++ b/examples/plot_regular_mesh_dose_tally.py @@ -1,5 +1,6 @@ import regular_mesh_plotter as rmp import openmc +import matplotlib.pyplot as plt # loads in the statepoint file containing tallies statepoint = openmc.StatePoint(filepath="statepoint.2.h5") @@ -8,11 +9,9 @@ my_tally = statepoint.get_tally(name="neutron_effective_dose_on_2D_mesh_xy") # creates a plot of the mesh tally -my_plot = rmp.plot_regular_mesh_dose_tally( +rmp.plot_regular_mesh_dose_tally( tally=my_tally, # the openmc tally object to plot, must be a 2d mesh tally filename="plot_regular_mesh_dose_tally.png", # the filename of the picture file saved - scale=None, # LogNorm(), - vmin=None, x_label="X [cm]", y_label="Y [cm]", rotate_plot=0, @@ -22,4 +21,4 @@ ) # displays the plot -my_plot.show() +plt.show() diff --git a/examples/plot_regular_mesh_dose_tally_with_geometry.py b/examples/plot_regular_mesh_dose_tally_with_geometry.py index 7c6d810..40b6f7d 100644 --- a/examples/plot_regular_mesh_dose_tally_with_geometry.py +++ b/examples/plot_regular_mesh_dose_tally_with_geometry.py @@ -1,5 +1,6 @@ import regular_mesh_plotter as rmp import openmc +import matplotlib.pyplot as plt # loads in the statepoint file containing tallies statepoint = openmc.StatePoint(filepath="statepoint.2.h5") @@ -8,12 +9,10 @@ my_tally = statepoint.get_tally(name="neutron_effective_dose_on_2D_mesh_xy") # creates a plot of the mesh -my_plot = rmp.plot_regular_mesh_dose_tally_with_geometry( +rmp.plot_regular_mesh_dose_tally_with_geometry( tally=my_tally, dagmc_file_or_trimesh_object="dagmc.h5m", filename="plot_regular_mesh_dose_tally_with_geometry.png", - scale=None, # LogNorm(), - vmin=None, label="Effective dose [picosievert / second]", x_label="X [cm]", y_label="Y [cm]", @@ -25,4 +24,4 @@ source_strength=1e20, ) -my_plot.show() +plt.show() diff --git a/examples/plot_regular_mesh_tally.py b/examples/plot_regular_mesh_tally.py index 56b540f..3f99d29 100644 --- a/examples/plot_regular_mesh_tally.py +++ b/examples/plot_regular_mesh_tally.py @@ -11,10 +11,7 @@ rmp.plot_regular_mesh_tally( tally=my_tally, filename="neutron_effective_dose_on_2D_mesh_xy.png", - scale=None, # LogNorm(), - vmin=None, label="", - base_plt=None, x_label="X [cm]", y_label="Y [cm]", # rotate_plot: float = 0, diff --git a/examples/plot_regular_mesh_tally_with_geometry.py b/examples/plot_regular_mesh_tally_with_geometry.py index 787c58c..cd63873 100644 --- a/examples/plot_regular_mesh_tally_with_geometry.py +++ b/examples/plot_regular_mesh_tally_with_geometry.py @@ -1,6 +1,8 @@ import regular_mesh_plotter as rmp import openmc +import matplotlib.pyplot as plt + # loads in the statepoint file containing tallies statepoint = openmc.StatePoint(filepath="statepoint.2.h5") @@ -8,13 +10,11 @@ my_tally = statepoint.get_tally(name="neutron_effective_dose_on_2D_mesh_xy") # creates a plot of the mesh -my_plot = rmp.plot_regular_mesh_tally_with_geometry( +rmp.plot_regular_mesh_tally_with_geometry( tally=my_tally, dagmc_file_or_trimesh_object="dagmc.h5m", std_dev_or_tally_value="tally_value", filename="plot_regular_mesh_tally_with_geometry.png", - scale=None, # LogNorm(), - vmin=None, label="", x_label="X [cm]", y_label="Y [cm]", @@ -26,4 +26,4 @@ source_strength=None, ) -my_plot.show() +plt.show() diff --git a/examples/plot_regular_mesh_values.py b/examples/plot_regular_mesh_values.py index e7b76a3..1514f57 100644 --- a/examples/plot_regular_mesh_values.py +++ b/examples/plot_regular_mesh_values.py @@ -70,8 +70,6 @@ rmp.plot_regular_mesh_values( values=values, filename="plot_regular_mesh_values.png", - scale=None, # LogNorm(), - vmin=None, label="legend label", x_label="X [cm]", y_label="Y [cm]", diff --git a/examples/plot_regular_mesh_values_with_geometry.py b/examples/plot_regular_mesh_values_with_geometry.py index 0053ed3..80ea5c4 100644 --- a/examples/plot_regular_mesh_values_with_geometry.py +++ b/examples/plot_regular_mesh_values_with_geometry.py @@ -71,8 +71,6 @@ values=values, dagmc_file_or_trimesh_object="example.stl", filename="plot_regular_mesh_values_with_geometry.png", - scale=None, # LogNorm(), - vmin=None, label="legend label", x_label="X [cm]", y_label="Y [cm]", diff --git a/regular_mesh_plotter/core.py b/regular_mesh_plotter/core.py index 7dca465..efda23c 100644 --- a/regular_mesh_plotter/core.py +++ b/regular_mesh_plotter/core.py @@ -17,24 +17,15 @@ def plot_regular_mesh_values( values: np.ndarray, filename: Optional[str] = None, - scale=None, # LogNorm(), - vmin=None, label="", title=None, - base_plt=None, extent=None, x_label="X [cm]", y_label="Y [cm]", rotate_plot: float = 0, + **kwargs ): - if base_plt: - plt = base_plt - else: - import matplotlib.pyplot as plt - - plt.plot() - if rotate_plot != 0: x_center = sum(extent[:2]) / 2 y_center = sum(extent[2:]) / 2 @@ -42,17 +33,10 @@ def plot_regular_mesh_values( rot = transforms.Affine2D().rotate_deg_around(x_center, y_center, rotate_plot) image_map = plt.imshow( - values, - norm=scale, - vmin=vmin, - extent=extent, - transform=rot + base, - origin="lower", + values, extent=extent, transform=rot + base, origin="lower", **kwargs ) else: - image_map = plt.imshow( - values, norm=scale, vmin=vmin, extent=extent, origin="lower" - ) + image_map = plt.imshow(values, extent=extent, origin="lower", **kwargs) plt.xlabel(x_label) plt.ylabel(y_label) @@ -61,17 +45,14 @@ def plot_regular_mesh_values( # image_map = fig.imshow(values, norm=scale, vmin=vmin) plt.colorbar(image_map, label=label) - if filename: + if filename: # TODO should we not let the users do that? plt.savefig(filename, dpi=300) - return plt def plot_regular_mesh_values_with_geometry( values: np.ndarray, dagmc_file_or_trimesh_object, filename: Optional[str] = None, - scale=None, # LogNorm(), - vmin=None, label="", title=None, extent=None, @@ -81,6 +62,7 @@ def plot_regular_mesh_values_with_geometry( plane_normal: List[float] = [0, 0, 1], rotate_mesh: float = 0, rotate_geometry: float = 0, + **kwargs ): slice = dgsp.plot_slice_of_dagmc_geometry( @@ -90,30 +72,24 @@ def plot_regular_mesh_values_with_geometry( rotate_plot=rotate_geometry, ) - both = plot_regular_mesh_values( + plot_regular_mesh_values( values=values, filename=filename, - scale=scale, # LogNorm(), - vmin=vmin, label=label, title=title, - base_plt=slice, extent=extent, x_label=x_label, y_label=y_label, rotate_plot=rotate_mesh, + **kwargs ) - return both - def plot_regular_mesh_tally_with_geometry( tally, dagmc_file_or_trimesh_object, std_dev_or_tally_value="tally_value", filename: Optional[str] = None, - scale=None, # LogNorm(), - vmin=None, label="", title=None, x_label="X [cm]", @@ -124,6 +100,7 @@ def plot_regular_mesh_tally_with_geometry( rotate_geometry: float = 0, required_units=None, source_strength: float = None, + **kwargs ): if required_units is not None: @@ -137,44 +114,38 @@ def plot_regular_mesh_tally_with_geometry( extent = get_tally_extent(tally) - base_plt = dgsp.plot_slice_of_dagmc_geometry( + dgsp.plot_slice_of_dagmc_geometry( dagmc_file_or_trimesh_object=dagmc_file_or_trimesh_object, plane_origin=plane_origin, plane_normal=plane_normal, rotate_plot=rotate_geometry, ) - plot = plot_regular_mesh_values( + plot_regular_mesh_values( values=value, filename=filename, - scale=scale, - vmin=vmin, label=label, title=title, - base_plt=base_plt, extent=extent, x_label=x_label, y_label=y_label, rotate_plot=rotate_mesh, + **kwargs ) - return plot - def plot_regular_mesh_tally( tally, filename: Optional[str] = None, - scale=None, # LogNorm(), - vmin=None, label="", title=None, - base_plt=None, x_label="X [cm]", y_label="Y [cm]", rotate_plot: float = 0, required_units: str = None, source_strength: float = None, std_dev_or_tally_value="tally_value", + **kwargs ): if required_units is not None: @@ -190,37 +161,31 @@ def plot_regular_mesh_tally( extent = get_tally_extent(tally) - plot = plot_regular_mesh_values( + plot_regular_mesh_values( values=value, filename=filename, - scale=scale, - vmin=vmin, label=label, title=title, - base_plt=base_plt, extent=extent, x_label=x_label, y_label=y_label, rotate_plot=rotate_plot, + **kwargs ) - return plot - def plot_regular_mesh_dose_tally( tally, filename: Optional[str] = None, - scale=None, # LogNorm(), - vmin=None, label="", title=None, - base_plt=None, x_label="X [cm]", y_label="Y [cm]", rotate_plot: float = 0, required_units="picosievert / source_particle", source_strength: float = None, std_dev_or_tally_value: str = "tally_value", + **kwargs ): if required_units is not None: @@ -236,29 +201,23 @@ def plot_regular_mesh_dose_tally( extent = get_tally_extent(tally) - plot = plot_regular_mesh_values( + plot_regular_mesh_values( values=value, filename=filename, - scale=scale, - vmin=vmin, label=label, title=title, - base_plt=base_plt, extent=extent, x_label=x_label, y_label=y_label, rotate_plot=rotate_plot, + **kwargs ) - return plot - def plot_regular_mesh_dose_tally_with_geometry( tally, dagmc_file_or_trimesh_object, filename: Optional[str] = None, - scale=None, # LogNorm(), - vmin=None, label="", title=None, x_label="X [cm]", @@ -270,29 +229,26 @@ def plot_regular_mesh_dose_tally_with_geometry( required_units="picosievert / source_particle", source_strength: float = None, std_dev_or_tally_value: str = "tally_value", + **kwargs ): - slice = dgsp.plot_slice_of_dagmc_geometry( + dgsp.plot_slice_of_dagmc_geometry( dagmc_file_or_trimesh_object=dagmc_file_or_trimesh_object, plane_origin=plane_origin, plane_normal=plane_normal, rotate_plot=rotate_geometry, ) - both = plot_regular_mesh_dose_tally( + plot_regular_mesh_dose_tally( tally=tally, filename=filename, - scale=scale, # LogNorm(), - vmin=vmin, label=label, title=title, - base_plt=slice, x_label=x_label, y_label=y_label, rotate_plot=rotate_mesh, required_units=required_units, source_strength=source_strength, std_dev_or_tally_value=std_dev_or_tally_value, + **kwargs ) - - return both diff --git a/tests/test_plot_regular_mesh_values.py b/tests/test_plot_regular_mesh_values.py index 2a9b08d..91cf03e 100644 --- a/tests/test_plot_regular_mesh_values.py +++ b/tests/test_plot_regular_mesh_values.py @@ -2,7 +2,6 @@ import unittest from pathlib import Path -import matplotlib import numpy as np from regular_mesh_plotter import plot_regular_mesh_values @@ -77,9 +76,7 @@ def setUp(self): def test_plot_regular_mesh_values(self): - test_plot = plot_regular_mesh_values(values=self.values) - - assert isinstance(test_plot, type(matplotlib.pyplot)) + plot_regular_mesh_values(values=self.values) def test_plot_regular_mesh_values_with_output(self): @@ -88,3 +85,12 @@ def test_plot_regular_mesh_values_with_output(self): plot_regular_mesh_values(values=self.values, filename="test.png") assert Path("test.png").is_file() + + def test_plot_regular_mesh_values_with_custom_colorbar(self): + """Checks that other parameters can be used such as cmap""" + + os.system("rm test.png") + + plot_regular_mesh_values(values=self.values, filename="test.png", cmap="jet") + + assert Path("test.png").is_file() diff --git a/tests/test_plot_regular_mesh_values_with_geometry.py b/tests/test_plot_regular_mesh_values_with_geometry.py index fad6cc1..28b8717 100644 --- a/tests/test_plot_regular_mesh_values_with_geometry.py +++ b/tests/test_plot_regular_mesh_values_with_geometry.py @@ -77,20 +77,7 @@ def setUp(self): def test_plot_regular_mesh_values_with_geometry(self): - test_plot = plot_regular_mesh_values_with_geometry( + plot_regular_mesh_values_with_geometry( values=self.values, dagmc_file_or_trimesh_object="tests/example.stl", # this could be a h5m file ) - - assert isinstance(test_plot, type(matplotlib.pyplot)) - - def test_plot_regular_mesh_values_with_geometry(self): - - test_plot = plot_regular_mesh_values_with_geometry( - values=self.values, - dagmc_file_or_trimesh_object="tests/example.stl", # this could be a h5m file - filename="test.png", - ) - - assert isinstance(test_plot, type(matplotlib.pyplot)) - assert Path("test.png").is_file()