paramak icon indicating copy to clipboard operation
paramak copied to clipboard

Adding plotly option to the 2D mesh tally plots

Open shimwell opened this issue 4 years ago • 0 comments

Currently matplotlib functions are used to plot 2D slice mesh tally results. However plotly can also do this and the results are then interactive. This snippet takes a slice from a 3D mesh tally and plots it and is close to the function needed.

import openmc

statepoint = openmc.StatePoint('statepoint.42.h5')
tallies = statepoint.tallies
tally = tallies[tally_id]  
results = tally.mean.flatten()

mesh = statepoint.meshes[1]

xyz_length_of_mesh = mesh._dimension
print('xyz_length_of_mesh', xyz_length_of_mesh)

results_slice = results.reshape(xyz_length_of_mesh) 
z = results_slice[100]

xx=np.linspace(mesh._lower_left[0], mesh._upper_right[0], xyz_length_of_mesh[0])
yy=np.linspace(mesh._lower_left[1], mesh._upper_right[1], xyz_length_of_mesh[1])

fig = go.Figure()
fig.add_trace(
    go.Heatmap(
        x=xx,
        y=yy,
        z=z,
        hovertemplate='x: %{x}<br>y: %{y}<br>value: %{z} units<extra></extra>'
    )
)

layout = go.Layout(
    xaxis=go.layout.XAxis(
        title=go.layout.xaxis.Title(
            text='Depth Axis',
    )),
    yaxis=go.layout.YAxis(
        title=go.layout.yaxis.Title(
            text='y (cm)',
        )
    )
)

fig.show()
fig.write_html('2d_heat_map_with_CAD'+str(tally_id)+'.html')

shimwell avatar Jan 07 '21 00:01 shimwell