From 42ff5a4c85b5ac2aeadb80a03ffb990fb3d2e80b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 11 Jun 2019 15:51:25 -0500 Subject: [PATCH] Adding show_overlaps and overlap_color to Python API. --- openmc/plots.py | 48 ++++++++++++++++++++++++++++++++++ tests/unit_tests/test_plots.py | 4 +++ 2 files changed, 52 insertions(+) diff --git a/openmc/plots.py b/openmc/plots.py index 5a5282298..3c810fcf6 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -208,6 +208,10 @@ class Plot(IDManagerMixin): The cells or materials to plot mask_background : Iterable of int or str Color to apply to all cells/materials not listed in mask_components + show_overlaps : bool + Inidicate whether or not overlapping regions are shown + overlap_color : Iterable of int or str + Color to apply to overlapping regions colors : dict Dictionary indicating that certain cells/materials (keys) should be displayed with a particular color. @@ -236,6 +240,8 @@ class Plot(IDManagerMixin): self._background = None self._mask_components = None self._mask_background = None + self._show_overlaps = False + self._overlap_color = None self._colors = {} self._level = None self._meshlines = None @@ -284,6 +290,14 @@ class Plot(IDManagerMixin): def mask_background(self): return self._mask_background + @property + def show_overlaps(self): + return self._show_overlaps + + @property + def overlap_color(self): + return self._overlap_color + @property def colors(self): return self._colors @@ -391,6 +405,25 @@ class Plot(IDManagerMixin): cv.check_less_than('plot mask background', rgb, 256) self._mask_background = mask_background + @show_overlaps.setter + def show_overlaps(self, show_overlaps): + cv.check_type('Show overlaps flag for Plot ID="{}"'.format(self.id), + show_overlaps, bool) + self._show_overlaps = show_overlaps + + @overlap_color.setter + def overlap_color(self, overlap_color): + cv.check_type('plot overlap color', overlap_color, Iterable) + if isinstance(overlap_color, str): + if overlap_color.lower() not in _SVG_COLORS: + raise ValueError("'{}' is not a valid color.".format(overlap_color)) + else: + cv.check_length('plot overlap color', overlap_color, 3) + for rgb in overlap_color: + cv.check_greater_than('plot overlap color', rgb, 0, True) + cv.check_less_than('plot overlap color', rgb, 256) + self._overlap_color = overlap_color + @level.setter def level(self, plot_level): cv.check_type('plot level', plot_level, Integral) @@ -446,6 +479,8 @@ class Plot(IDManagerMixin): self._mask_components) string += '{: <16}=\t{}\n'.format('\tMask background', self._mask_background) + string += '{: <16}=\t{}\n'.format('\Overlap Color', + self._overlap_color) string += '{: <16}=\t{}\n'.format('\tColors', self._colors) string += '{: <16}=\t{}\n'.format('\tLevel', self._level) string += '{: <16}=\t{}\n'.format('\tMeshlines', self._meshlines) @@ -635,6 +670,19 @@ class Plot(IDManagerMixin): subelement.set("background", ' '.join( str(x) for x in color)) + if self._show_overlaps: + subelement = ET.SubElement(element, "show_overlaps") + subelement.text = "true" + + if self._overlap_color is not None: + color = self._overlap_color + if isinstance(color, str): + color = _SVG_COLORS[color.lower()] + + subelement = ET.SubElement(element, "overlap_color") + subelement.text = ' '.join(str(x) for x in color) + + if self._level is not None: subelement = ET.SubElement(element, "level") subelement.text = str(self._level) diff --git a/tests/unit_tests/test_plots.py b/tests/unit_tests/test_plots.py index 840e7e635..f2d3e1014 100644 --- a/tests/unit_tests/test_plots.py +++ b/tests/unit_tests/test_plots.py @@ -24,6 +24,10 @@ def myplot(): plot.mask_background = (255, 255, 255) plot.mask_background = 'white' + plot.overlap_color = (255, 211, 0) + plot.overlap_color = 'yellow' + plot.show_overlaps = True + plot.level = 1 plot.meshlines = { 'type': 'tally',