From d577fc7a36587c0d24ebf32830435b89373d8327 Mon Sep 17 00:00:00 2001 From: Rosie Barker Date: Wed, 28 Feb 2024 15:25:25 +0000 Subject: [PATCH 1/5] Added option to reflect plot in z axis --- src/openmc_cylindrical_mesh_plotter/core.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/openmc_cylindrical_mesh_plotter/core.py b/src/openmc_cylindrical_mesh_plotter/core.py index edd7ada..52e4de0 100644 --- a/src/openmc_cylindrical_mesh_plotter/core.py +++ b/src/openmc_cylindrical_mesh_plotter/core.py @@ -143,6 +143,7 @@ def plot_mesh_tally_rz_slice( pixels: int = 40000, colorbar: bool = True, volume_normalization: bool = True, + reflect_in_z: bool = False, scaling_factor: typing.Optional[float] = None, colorbar_kwargs: dict = {}, outline_kwargs: dict = _default_outline_kwargs, @@ -183,6 +184,8 @@ def plot_mesh_tally_rz_slice( Whether or not to add a colorbar to the plot. volume_normalization : bool, optional Whether or not to normalize the data by the volume of the mesh elements. + reflect_in_z : bool, optional + Whether to reflect the plot in the z axis to include negative r values. scaling_factor : float A optional multiplier to apply to the tally data prior to ploting. colorbar_kwargs : dict @@ -251,6 +254,11 @@ def plot_mesh_tally_rz_slice( score, slice_index, ) + + if reflect_in_z: + data_reflected = np.fliplr(data) + data = np.concatenate((data_reflected, data), axis=1) + x_min = x_max * -1 im = axes.imshow(data, extent=(x_min, x_max, y_min, y_max), **default_imshow_kwargs) @@ -301,6 +309,10 @@ def plot_mesh_tally_rz_slice( # Combine R, G, B values into a single int rgb = (img * 256).astype(int) image_value = (rgb[..., 0] << 16) + (rgb[..., 1] << 8) + (rgb[..., 2]) + + if reflect_in_z: + image_value_reflected = np.fliplr(image_value) + image_value = np.concatenate((image_value_reflected, image_value), axis=1) # Plot geometry image axes.contour( From a21946e4c47946bec187ac0107686af49f2b2266 Mon Sep 17 00:00:00 2001 From: Rosie Barker Date: Wed, 28 Feb 2024 15:25:42 +0000 Subject: [PATCH 2/5] Added example plot with reflection in z axis --- examples/plot_rz_slices_ring_source.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/plot_rz_slices_ring_source.py b/examples/plot_rz_slices_ring_source.py index f0c9aaf..f14b158 100644 --- a/examples/plot_rz_slices_ring_source.py +++ b/examples/plot_rz_slices_ring_source.py @@ -69,6 +69,16 @@ my_tally_result = statepoint.get_tally(name="my_tally") for slice_index in range(1, len(mesh.phi_grid) - 1): + plot = plot_mesh_tally_rz_slice( + tally=my_tally_result, + geometry=my_geometry, + outline=True, + norm=LogNorm(), + slice_index=slice_index, + reflect_in_z=True + ) + plot.figure.savefig(f"rz_ring_source_reflected_{slice_index}.png") + plot = plot_mesh_tally_rz_slice( tally=my_tally_result, geometry=my_geometry, @@ -77,3 +87,4 @@ slice_index=slice_index, ) plot.figure.savefig(f"rz_ring_source_{slice_index}.png") + From cbdac11e82a73c01cce8b5fd640fa00dd7c5c85f Mon Sep 17 00:00:00 2001 From: Rosie Barker Date: Thu, 29 Feb 2024 17:01:02 +0000 Subject: [PATCH 3/5] renamed reflect_in_z to mirror --- src/openmc_cylindrical_mesh_plotter/core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openmc_cylindrical_mesh_plotter/core.py b/src/openmc_cylindrical_mesh_plotter/core.py index 52e4de0..6e53ec8 100644 --- a/src/openmc_cylindrical_mesh_plotter/core.py +++ b/src/openmc_cylindrical_mesh_plotter/core.py @@ -143,7 +143,7 @@ def plot_mesh_tally_rz_slice( pixels: int = 40000, colorbar: bool = True, volume_normalization: bool = True, - reflect_in_z: bool = False, + mirror: bool = False, scaling_factor: typing.Optional[float] = None, colorbar_kwargs: dict = {}, outline_kwargs: dict = _default_outline_kwargs, @@ -184,7 +184,7 @@ def plot_mesh_tally_rz_slice( Whether or not to add a colorbar to the plot. volume_normalization : bool, optional Whether or not to normalize the data by the volume of the mesh elements. - reflect_in_z : bool, optional + mirror : bool, optional Whether to reflect the plot in the z axis to include negative r values. scaling_factor : float A optional multiplier to apply to the tally data prior to ploting. @@ -255,7 +255,7 @@ def plot_mesh_tally_rz_slice( slice_index, ) - if reflect_in_z: + if mirror: data_reflected = np.fliplr(data) data = np.concatenate((data_reflected, data), axis=1) x_min = x_max * -1 @@ -310,7 +310,7 @@ def plot_mesh_tally_rz_slice( rgb = (img * 256).astype(int) image_value = (rgb[..., 0] << 16) + (rgb[..., 1] << 8) + (rgb[..., 2]) - if reflect_in_z: + if mirror: image_value_reflected = np.fliplr(image_value) image_value = np.concatenate((image_value_reflected, image_value), axis=1) From 431bd4caa056bb0344d806f08be63f80a2a76491 Mon Sep 17 00:00:00 2001 From: Rosie Barker Date: Thu, 29 Feb 2024 17:01:18 +0000 Subject: [PATCH 4/5] Added test for mirroring --- tests/test_slice_of_data.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_slice_of_data.py b/tests/test_slice_of_data.py index f883ce9..593733f 100644 --- a/tests/test_slice_of_data.py +++ b/tests/test_slice_of_data.py @@ -185,3 +185,14 @@ def test_phir_slice_of_data_circular_simulation_normalization( def test_rz_slice_of_data_point_simulation_combined(point_source_simulation): tally = point_source_simulation plot_mesh_tally_rz_slice(tally=[tally, tally]) + + +def test_rz_slice_of_data_point_simulation_flipping(point_source_simulation): + tally = point_source_simulation + plot = plot_mesh_tally_rz_slice(tally=tally) + width_plot = plot.get_xlim()[1] - plot.get_xlim()[0] + + plot_flipped = plot_mesh_tally_rz_slice(tally=tally, mirror=True) + width_plot_flipped = plot_flipped.get_xlim()[1] - plot_flipped.get_xlim()[0] + + assert width_plot * 2 == width_plot_flipped From 533f2bf2c92435ddab5e33834961b1ec6922e449 Mon Sep 17 00:00:00 2001 From: Rosie Barker Date: Thu, 29 Feb 2024 17:18:55 +0000 Subject: [PATCH 5/5] updated reflect_in_z to mirror --- examples/plot_rz_slices_ring_source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_rz_slices_ring_source.py b/examples/plot_rz_slices_ring_source.py index f14b158..34c1391 100644 --- a/examples/plot_rz_slices_ring_source.py +++ b/examples/plot_rz_slices_ring_source.py @@ -75,7 +75,7 @@ outline=True, norm=LogNorm(), slice_index=slice_index, - reflect_in_z=True + mirror=True ) plot.figure.savefig(f"rz_ring_source_reflected_{slice_index}.png")