Skip to content

Commit

Permalink
merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Nov 28, 2023
2 parents 37a61f9 + 63158b2 commit fa5a5ef
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion examples/plot_minimal_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@

plot.title.set_text("")
plot.figure.savefig("example_openmc_regular_mesh_plotter.png")
print('file created example_openmc_regular_mesh_plotter.png')
print("file created example_openmc_regular_mesh_plotter.png")
12 changes: 6 additions & 6 deletions examples/plot_plotly_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
model = openmc.model.Model(my_geometry, my_materials, my_settings, my_tallies)
# sp_filename = model.run()

sp_filename = '/home/jshimwell/reactor_csg_neutronics_model/statepoint.12.h5'
sp_filename = "/home/jshimwell/reactor_csg_neutronics_model/statepoint.12.h5"

# post process simulation result
statepoint = openmc.StatePoint(sp_filename)
Expand All @@ -77,19 +77,19 @@
# in a regular mesh all the voxels have the same volume so the [0][0][0] just picks the first volume

plot = plot_mesh_tally(
plotting_backend='plotly',
plotting_backend="plotly",
tally=my_mesh_tally,
# outline=True, # enables an outline around the geometry
# geometry=my_geometry, # needed for outline
norm=LogNorm(), # log scale
colorbar=True,
scaling_factor=scaling_factor,
colorbar_kwargs={'title':'Heating [MJ cm-3s-1]'},
basis='xz',
colorbar_kwargs={"title": "Heating [MJ cm-3s-1]"},
basis="xz",
)

# setting title of the plot
plot.update_layout({'title': ' made with openmc_regular_mesh_plotter'})
plot.update_layout({"title": " made with openmc_regular_mesh_plotter"})
plot.show()
# plot.write_html("example_openmc_regular_mesh_plotter.html")
print('file created example_openmc_regular_mesh_plotter.html')
print("file created example_openmc_regular_mesh_plotter.html")
72 changes: 40 additions & 32 deletions src/openmc_regular_mesh_plotter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def plot_mesh_tally(
scaling_factor: typing.Optional[float] = None,
colorbar_kwargs: dict = {},
outline_kwargs: dict = _default_outline_kwargs,
plotting_backend: str = 'matplotlib',
plotting_backend: str = "matplotlib",
**kwargs,
) -> "matplotlib.image.AxesImage":
"""Display a slice plot of the mesh tally score.
Expand Down Expand Up @@ -176,10 +176,11 @@ def plot_mesh_tally(
slice_index,
)

if plotting_backend == 'plotly':
if plotting_backend == "plotly":
import plotly.graph_objects as go
dx = abs(x_min - x_max)/(data.shape[0]-1)
dy = abs(y_min - y_max)/(data.shape[1]-1)

dx = abs(x_min - x_max) / (data.shape[0] - 1)
dy = abs(y_min - y_max) / (data.shape[1] - 1)

fig = go.Figure()
fig.add_trace(
Expand All @@ -191,9 +192,10 @@ def plot_mesh_tally(
dy=dy,
showscale=colorbar,
colorbar=colorbar_kwargs,
colorscale='viridis',
line = {'width': 0}
))
colorscale="viridis",
line={"width": 0},
)
)
fig.update_layout(
xaxis_title=xlabel,
yaxis_title=ylabel,
Expand All @@ -207,29 +209,30 @@ def plot_mesh_tally(
)

if outline and geometry is not None:

image_value = get_outline(mesh, basis, slice_index, geometry, outline_by, pixels)

dx = abs(x_min - x_max)/(image_value.shape[0]-1)
dy = abs(y_min - y_max)/(image_value.shape[1]-1)
image_value = get_outline(
mesh, basis, slice_index, geometry, outline_by, pixels
)

dx = abs(x_min - x_max) / (image_value.shape[0] - 1)
dy = abs(y_min - y_max) / (image_value.shape[1] - 1)
fig.add_trace(
go.Contour(
z=image_value,
x0=x_min,
dx=dx,
y0=y_min,
dy=dy,
contours_coloring='lines',
colorscale=[[0, 'black'], [1.0, 'black']],
line = {'width': 1, 'color': 'rgb(50,50,50)'}
# contours=dict(
# start=0,
# end=8,
# size=2,
# ),
# ncontours=1
# line = {'width': 0}
)
go.Contour(
z=image_value,
x0=x_min,
dx=dx,
y0=y_min,
dy=dy,
contours_coloring="lines",
colorscale=[[0, "black"], [1.0, "black"]],
line={"width": 1, "color": "rgb(50,50,50)"}
# contours=dict(
# start=0,
# end=8,
# size=2,
# ),
# ncontours=1
# line = {'width': 0}
)
)
print()
return fig
Expand All @@ -249,8 +252,9 @@ def plot_mesh_tally(
fig.colorbar(im, **colorbar_kwargs)

if outline and geometry is not None:

image_value = get_outline(mesh, basis, slice_index, geometry, outline_by, pixels)
image_value = get_outline(
mesh, basis, slice_index, geometry, outline_by, pixels
)

if basis == "xz":
image_value = np.rot90(image_value, 2)
Expand All @@ -270,7 +274,10 @@ def plot_mesh_tally(

return axes
else:
raise ValueError(f'plotting_backend must be either matplotlib or plotly, not {plotting_backend}')
raise ValueError(
f"plotting_backend must be either matplotlib or plotly, not {plotting_backend}"
)


def get_outline(mesh, basis, slice_index, geometry, outline_by, pixels):
import matplotlib.image as mpimg
Expand Down Expand Up @@ -335,6 +342,7 @@ def get_outline(mesh, basis, slice_index, geometry, outline_by, pixels):

return image_value


# TODO currently we allow slice index, but this code will be useful if want to
# allow slicing by axis values / coordinates.
def get_index_where(self, value: float, basis: str = "xy"):
Expand Down

0 comments on commit fa5a5ef

Please sign in to comment.