diff --git a/examples/plot_rz_slice_point_source_combined_multiple_tallies.py b/examples/plot_rz_slice_point_source_combined_multiple_tallies.py index 31d7372..b44538b 100644 --- a/examples/plot_rz_slice_point_source_combined_multiple_tallies.py +++ b/examples/plot_rz_slice_point_source_combined_multiple_tallies.py @@ -10,7 +10,6 @@ import openmc import numpy as np from math import pi -import matplotlib.pyplot as plt from openmc_cylindrical_mesh_plotter import plot_mesh_tally_rz_slice mesh = openmc.CylindricalMesh( diff --git a/src/openmc_cylindrical_mesh_plotter/__init__.py b/src/openmc_cylindrical_mesh_plotter/__init__.py index bb67a43..7e59db4 100644 --- a/src/openmc_cylindrical_mesh_plotter/__init__.py +++ b/src/openmc_cylindrical_mesh_plotter/__init__.py @@ -1 +1,2 @@ from .core import * +from .app import * diff --git a/src/openmc_cylindrical_mesh_plotter/app.py b/src/openmc_cylindrical_mesh_plotter/app.py index c041bb0..e617406 100644 --- a/src/openmc_cylindrical_mesh_plotter/app.py +++ b/src/openmc_cylindrical_mesh_plotter/app.py @@ -23,7 +23,6 @@ def get_tallies_with_cylindrical_mesh_filters(statepoint: openmc.StatePoint): mf = tally.find_filter(filter_type=openmc.MeshFilter) if isinstance(mf.mesh, openmc.CylindricalMesh): matching_tally_ids.append(tally.id) - print("found regmeshfilter") except ValueError: mf = None @@ -78,8 +77,6 @@ def header(): 💾 Raise a feature request, report and issue or make a contribution on [GitHub](https://github.com/fusion-energy/openmc_cylindrical_mesh_plotter) - 📧 Email feedback to mail@jshimwell.com - 🔗 This package forms part of a more [comprehensive openmc plot](https://github.com/fusion-energy/openmc_plot) package where geometry, tallies, slices, etc can be plotted and is hosted on [xsplot.com](https://www.xsplot.com/) . """ ) @@ -94,8 +91,6 @@ def main(): """ # Not got a h5 file handy, right mouse 🖱️ click and save these links - # [ example 1 ](https://fusion-energy.github.io/openmc_cylindrical_mesh_plotter/examples/csg_tokamak/geometry.xml), - # [ example 2 ](https://fusion-energy.github.io/openmc_cylindrical_mesh_plotter/examples/csg_cylinder_box/geometry.xml) ) statepoint_file = st.file_uploader("Select your statepoint h5 file", type=["h5"]) @@ -108,6 +103,8 @@ def main(): save_uploadedfile(statepoint_file) statepoint = openmc.StatePoint(statepoint_file.name) + geometry = statepoint.summary.geometry + tally_description = get_cylindricalmesh_tallies_and_scores(statepoint) tally_description_str = [ f"ID={td['id']} score={td['score']} name={td['name']}" @@ -123,7 +120,7 @@ def main(): basis = st.sidebar.selectbox( label="view direction", options=("PhiR", "RZ"), - index=0, + index=1, key="axis", help="", ) @@ -131,7 +128,10 @@ def main(): value = st.sidebar.radio("Tally mean or std dev", options=["mean", "std_dev"]) axis_units = st.sidebar.selectbox( - "Axis units", ["km", "m", "cm", "mm"], index=2 + "Axis units", + ["km", "m", "cm", "mm"], + index=2, + help="The units that appear on the X and Y axis", ) volume_normalization = st.sidebar.radio( @@ -146,8 +146,6 @@ def main(): tally = statepoint.get_tally(id=int(tally_id_to_plot)) - mesh = tally.find_filter(filter_type=openmc.MeshFilter).mesh - if basis == "RZ": max_value = int(tally.shape[1] / 2) # index 1 is the phi value if basis == "PhiR": @@ -175,21 +173,53 @@ def main(): # else: # contour_levels = None - colorbar = st.sidebar.radio("Include colorbar", options=[True, False]) - - title = st.sidebar.text_input( - "Colorbar title", - help="Optionally set your own colorbar label for the plot", - value="colorbar title", + log_lin_scale = st.sidebar.radio( + "Scale", options=["log", "linear"], help="The color scale applied" ) - - log_lin_scale = st.sidebar.radio("Scale", options=["log", "linear"]) if log_lin_scale == "linear": norm = None else: norm = LogNorm() + colorbar = st.sidebar.radio("Include colorbar", options=[True, False]) + + if colorbar: + title = st.sidebar.text_input( + "Colorbar title", + help="Optionally set your own colorbar label for the plot", + value="colorbar title", + ) + else: + title = None + if basis == "RZ": + outline = st.sidebar.radio("Geometry outline", options=[True, False]) + if outline: + geometry_basis = st.sidebar.selectbox( + label="geometry outline basis", + options=("xz", "yz"), + index=0, + key="outline_axis", + help="The axis/basis to use for the geometry outline plot", + ) + outline_by = st.sidebar.selectbox( + label="geometry outline basis", + options=("cell", "material"), + index=0, + key="outline_by", + help="The type of geometry outline to plot", + ) + outline_pixels = st.sidebar.number_input( + "Scaling factor", + value=40000, + help="The resolution to use for the outline plot. Increaing the value produces a smoother outline but takes longer.", + ) + else: + # outline not plotted but varibles still need values + geometry_basis = "xz" + outline_by = "cell" + outline_pixels = 40000 + plot = plot_mesh_tally_rz_slice( tally=tally, slice_index=slice_index, @@ -197,11 +227,11 @@ def main(): axes=None, axis_units=axis_units, value=value, - # outline: bool = False, - # outline_by: str = "cell", - # geometry: Optional["openmc.Geometry"] = None, - # geometry_basis: str = "xz", - # pixels: int = 40000, + outline=outline, + outline_by=outline_by, + geometry=geometry, + geometry_basis=geometry_basis, + pixels=outline_pixels, colorbar=colorbar, volume_normalization=volume_normalization, scaling_factor=scaling_factor, diff --git a/src/openmc_cylindrical_mesh_plotter/core.py b/src/openmc_cylindrical_mesh_plotter/core.py index 1b04d09..45c90c1 100644 --- a/src/openmc_cylindrical_mesh_plotter/core.py +++ b/src/openmc_cylindrical_mesh_plotter/core.py @@ -7,6 +7,9 @@ import openmc import openmc.checkvalue as cv import matplotlib.pyplot as plt +import matplotlib + +matplotlib.use("agg") from packaging import version