Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reflect in z axis option #18

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/plot_rz_slices_ring_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
shimwell marked this conversation as resolved.
Show resolved Hide resolved
)
plot.figure.savefig(f"rz_ring_source_reflected_{slice_index}.png")

plot = plot_mesh_tally_rz_slice(
tally=my_tally_result,
geometry=my_geometry,
Expand All @@ -77,3 +87,4 @@
slice_index=slice_index,
)
plot.figure.savefig(f"rz_ring_source_{slice_index}.png")

12 changes: 12 additions & 0 deletions src/openmc_cylindrical_mesh_plotter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def plot_mesh_tally_rz_slice(
pixels: int = 40000,
colorbar: bool = True,
volume_normalization: bool = True,
mirror: bool = False,
scaling_factor: typing.Optional[float] = None,
colorbar_kwargs: dict = {},
outline_kwargs: dict = _default_outline_kwargs,
Expand Down Expand Up @@ -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.
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.
colorbar_kwargs : dict
Expand Down Expand Up @@ -251,6 +254,11 @@ def plot_mesh_tally_rz_slice(
score,
slice_index,
)

if mirror:
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)

Expand Down Expand Up @@ -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 mirror:
image_value_reflected = np.fliplr(image_value)
image_value = np.concatenate((image_value_reflected, image_value), axis=1)

# Plot geometry image
axes.contour(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_slice_of_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading