mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Enable overlap plotting from Python API (#3310)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
d643ad0c41
commit
6ae2001400
3 changed files with 25 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue