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

Bug fix for geometries without bounding box #30

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Changes from all 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
78 changes: 36 additions & 42 deletions src/openmc_geometry_plot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def main():
if my_geometry:
print("geometry is set to something so attempting to plot")
bb = my_geometry.bounding_box
print(f'bounding box {bb}')

basis = st.sidebar.selectbox(
label="basis",
Expand All @@ -166,7 +167,7 @@ def main():
)
backend = st.sidebar.selectbox(
label="Ploting backend",
options=("plotly", "matplotlib"),
options=("matplotlib", "plotly"),
index=0,
key="geometry_plotting_backend",
help="Create png images with MatPlotLib or HTML plots with Plotly",
Expand Down Expand Up @@ -201,69 +202,63 @@ def main():
slice_index = {"xy": 2, "xz": 1, "yz": 0}[basis]
slice_axis = {"xy": 'Z', "xz": 'Y', "yz": 'X'}[basis]

# x axis values
if np.isinf(bb[0][x_index]) or np.isinf(bb[1][x_index]):
x_min = st.sidebar.number_input(
label="minimum vertical axis value", key="x_min"
plot_left = st.sidebar.number_input(
value = -2000., label="minimum vertical axis value", key="x_min"
)
x_max = st.sidebar.number_input(
label="maximum vertical axis value", key="x_max"
plot_right = st.sidebar.number_input(
value=2000., label="maximum vertical axis value", key="x_max"
)
else:
x_min = float(bb[0][x_index])
x_max = float(bb[1][x_index])
plot_right, plot_left = st.sidebar.slider(
label="Left and right values for the horizontal axis",
min_value=x_min,
max_value=x_max,
value=(x_min, x_max),
key="left_right_slider",
help="Set the lowest visible value and highest visible value on the horizontal axis",
)

# y axis is y values

# y axis values
if np.isinf(bb[0][y_index]) or np.isinf(bb[1][y_index]):
y_min = st.sidebar.number_input(
label="minimum vertical axis value", key="y_min"
plot_bottom = st.sidebar.number_input(
value=-2000., label="minimum vertical axis value", key="y_min"
)
y_max = st.sidebar.number_input(
label="maximum vertical axis value", key="y_max"
plot_top = st.sidebar.number_input(
value=2000., label="maximum vertical axis value", key="y_max"
)
else:
y_min = float(bb[0][y_index])
y_max = float(bb[1][y_index])
plot_bottom, plot_top = st.sidebar.slider(
label="Bottom and top values for the vertical axis",
min_value=y_min,
max_value=y_max,
value=(y_min, y_max),
key="bottom_top_slider",
help="Set the lowest visible value and highest visible value on the vertical axis",
)

# slice axis is z
if np.isinf(bb[0][slice_index]) or np.isinf(bb[1][slice_index]):
slice_min = st.sidebar.number_input(
label="minimum slice value", key="slice_min"
)
slice_max = st.sidebar.number_input(
label="maximum slice value", key="slice_max"
slice_value = st.sidebar.number_input(
value=0, label=f"Slice value on slice axis", key="slice_slider"
)
else:
slice_min = float(bb[0][slice_index])
slice_max = float(bb[1][slice_index])

if isinstance(slice_min, float) and isinstance(slice_max, float):
slice_value = st.sidebar.slider(
label="Slice value",
label=f"Slice value on slice axis",
min_value=slice_min,
max_value=slice_max,
value=(slice_min + slice_max) / 2,
key="slice_slider",
help="Set the value of the slice axis",
)
if isinstance(x_min, float) and isinstance(x_max, float):
plot_right, plot_left = st.sidebar.slider(
label="Left and right values for the horizontal axis",
min_value=x_min,
max_value=x_max,
value=(x_min, x_max),
key="left_right_slider",
help="Set the lowest visible value and highest visible value on the horizontal axis",
)

if isinstance(y_min, float) and isinstance(y_max, float):
plot_bottom, plot_top = st.sidebar.slider(
label="Bottom and top values for the vertical axis",
min_value=y_min,
max_value=y_max,
value=(y_min, y_max),
key="bottom_top_slider",
help="Set the lowest visible value and highest visible value on the vertical axis",
)

color_by = st.sidebar.selectbox(
label="Color by",
Expand Down Expand Up @@ -300,10 +295,8 @@ def main():

my_colors = {}
for id in set_mat_ids:
print('id from set_mat_ids', id)
hex_color = st.session_state[f"mat_{id}"].lstrip("#")
RGB = tuple(int(hex_color[i : i + 2], 16) for i in (0, 2, 4))
print('RGB',RGB)
mat = my_geometry.get_all_materials()[id]
my_colors[mat] = RGB

Expand Down Expand Up @@ -331,10 +324,8 @@ def main():
for id, value in all_cells.items():
hex_color = st.session_state[f"cell_{id}"].lstrip("#")
RGB = tuple(int(hex_color[i : i + 2], 16) for i in (0, 2, 4))
print('RGB',RGB)
my_colors[value] = RGB

print(my_colors)
title = st.sidebar.text_input(
"Plot title",
help="Optionally set your own title for the plot",
Expand Down Expand Up @@ -368,10 +359,10 @@ def main():
)

if backend == "matplotlib":
print('plotting with matplotlib')

width_x=plot_left-plot_right
width_y=plot_top-plot_bottom
print('origin',origin)

plot = my_geometry.plot(
origin=origin,
Expand All @@ -398,6 +389,7 @@ def main():
)
else:
from openmc_geometry_plot import plot_plotly
print('plotting with plotly')
plot = plot_plotly(
my_geometry,
origin=origin,
Expand Down Expand Up @@ -431,6 +423,8 @@ def main():
# st.write(f"Cell names found {all_cells.}")
st.write(f"Bounding box lower left x={bb[0][0]} y={bb[0][1]} z={bb[0][2]}")
st.write(f"Bounding box upper right x={bb[1][0]} y={bb[1][1]} z={bb[1][2]}")
else:
print(plot_left,plot_right, plot_top, plot_bottom)


if __name__ == "__main__":
Expand Down
Loading