Enable overlap plotting from Python API (#3310)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Patrick Shriwise 2025-02-21 14:58:37 -06:00 committed by GitHub
parent d643ad0c41
commit 6ae2001400
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 4 deletions

View file

@ -863,6 +863,8 @@ class Model:
legend: bool = False,
axis_units: str = 'cm',
outline: bool | str = False,
show_overlaps: bool = False,
overlap_color: Sequence[int] | str | None = None,
n_samples: int | None = None,
plane_tolerance: float = 1.,
legend_kwargs: dict | None = None,
@ -941,6 +943,9 @@ class Model:
plot.pixels = pixels
plot.basis = basis
plot.color_by = color_by
plot.show_overlaps = show_overlaps
if overlap_color is not None:
plot.overlap_color = overlap_color
if colors is not None:
plot.colors = colors
self.plots.append(plot)

View file

@ -209,16 +209,21 @@ _PLOT_PARAMS = """
legend : bool
Whether a legend showing material or cell names should be drawn
.. versionadded:: 0.14.0
axis_units : {'km', 'm', 'cm', 'mm'}
Units used on the plot axis
.. versionadded:: 0.14.0
outline : bool or str
Whether outlines between color boundaries should be drawn. If set to
'only', only outlines will be drawn.
.. versionadded:: 0.14.0
axis_units : {'km', 'm', 'cm', 'mm'}
Units used on the plot axis
.. versionadded:: 0.14.0
show_overlaps: bool
Indicate whether or not overlapping regions are shown.
Default is False.
overlap_color: Iterable of int or str
Color to apply to overlapping regions. Default is red.
n_samples : int, optional
The number of source particles to sample and add to plot. Defaults
to None which doesn't plot any particles on the plot.

View file

@ -638,3 +638,14 @@ def test_model_plot():
plot = model.plot(n_samples=1, plane_tolerance=0.1, basis="xy")
coords = plot.axes.collections[0].get_offsets().data.flatten()
assert (coords == np.array([])).all()
# modify model to include another cell that overlaps the original cell entirely
model.geometry.root_universe.add_cell(openmc.Cell(region=-surface))
axes = model.plot(show_overlaps=True)
white = np.array((1.0, 1.0, 1.0))
red = np.array((1.0, 0.0, 0.0))
axes_image = axes.get_images()[0]
image_data = axes_image.get_array()
# ensure that all of the data in the image data is either white or red
test_mask = (image_data == white) | (image_data == red)
assert np.all(test_mask), "Colors other than white or red found in overlap plot image"