mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
make meshlines a dict as a single attribute of plot
This commit is contained in:
parent
6eaf6e04d0
commit
b01a897250
1 changed files with 50 additions and 68 deletions
118
openmc/plots.py
118
openmc/plots.py
|
|
@ -69,14 +69,9 @@ class Plot(object):
|
|||
colored with a specific RGB (values)
|
||||
level : int
|
||||
Universe depth to plot at
|
||||
meshlines_type : {'tally', 'entropy', 'ufs', 'cmfd'}
|
||||
The type of the mesh to be plotted
|
||||
meshlines_id : int
|
||||
ID for the mesh specified on ``tallies.xml`` that should be plotted
|
||||
meshlines_linewidth : int
|
||||
Pixels of linewidth to specify for the mesh boundaries
|
||||
meshlines_color : Iterable of int
|
||||
Color for the meshlines boundaries by RGB.
|
||||
meshlines : dict
|
||||
Dictionary defining type, id, linewidth and color of a regular mesh
|
||||
to be plotted on top of a plot
|
||||
|
||||
"""
|
||||
|
||||
|
|
@ -91,15 +86,12 @@ class Plot(object):
|
|||
self._color = 'cell'
|
||||
self._type = 'slice'
|
||||
self._basis = 'xy'
|
||||
self._background = [0, 0, 0]
|
||||
self._background = None
|
||||
self._mask_components = None
|
||||
self._mask_background = None
|
||||
self._col_spec = None
|
||||
self._level = None
|
||||
self._meshlines_type = None
|
||||
self._meshlines_id = None
|
||||
self._meshlines_linewidth = None
|
||||
self._meshlines_color = None
|
||||
self._meshlines = None
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
|
|
@ -158,20 +150,8 @@ class Plot(object):
|
|||
return self._level
|
||||
|
||||
@property
|
||||
def meshlines_type(self):
|
||||
return self._meshlines_type
|
||||
|
||||
@property
|
||||
def meshlines_id(self):
|
||||
return self._meshlines_id
|
||||
|
||||
@property
|
||||
def meshlines_linewidth(self):
|
||||
return self._meshlines_linewidth
|
||||
|
||||
@property
|
||||
def meshlines_color(self):
|
||||
return self._meshlines_color
|
||||
def meshlines(self):
|
||||
return self._meshlines
|
||||
|
||||
@id.setter
|
||||
def id(self, plot_id):
|
||||
|
|
@ -286,33 +266,38 @@ class Plot(object):
|
|||
cv.check_greater_than('plot level', plot_level, 0, equality=True)
|
||||
self._level = plot_level
|
||||
|
||||
@meshlines_type.setter
|
||||
def meshlines_type(self, meshlines_type):
|
||||
cv.check_type('plot meshlines type', meshlines_type, basestring)
|
||||
cv.check_value('plot meshlines type', meshlines_type,
|
||||
['tally', 'entropy', 'ufs', 'cmfd'])
|
||||
self._meshlines_type = meshlines_type
|
||||
@meshlines.setter
|
||||
def meshlines(self, meshlines):
|
||||
cv.check_type('plot meshlines', meshlines, dict)
|
||||
if 'type' not in meshlines:
|
||||
msg = 'Unable to set on plot the meshlines "{0}" which ' \
|
||||
'does not have a "type" key'.format(meshlines)
|
||||
raise ValueError(msg)
|
||||
|
||||
@meshlines_id.setter
|
||||
def meshlines_id(self, mesh_id):
|
||||
cv.check_type('plot meshlines id', mesh_id, Integral)
|
||||
cv.check_greater_than('plot meshlines id', mesh_id, 0, equality=True)
|
||||
self._meshlines_id = mesh_id
|
||||
elif meshlines['type'] not in ['tally', 'entropy', 'ufs', 'cmfd']:
|
||||
msg = 'Unable to set the meshlines with ' \
|
||||
'type "{0}"'.format(meshlines['type'])
|
||||
raise ValueError(msg)
|
||||
|
||||
@meshlines_linewidth.setter
|
||||
def meshlines_linewidth(self, linewidth):
|
||||
cv.check_type('plot mesh linewidth', linewidth, Integral)
|
||||
cv.check_greater_than('plot mesh linewidth', linewidth, 0, equality=True)
|
||||
self._meshlines_linewidth = linewidth
|
||||
if 'id' in meshlines:
|
||||
cv.check_type('plot meshlines id', meshlines['id'], Integral)
|
||||
cv.check_greater_than('plot meshlines id', meshlines['id'], 0,
|
||||
equality=True)
|
||||
|
||||
@meshlines_color.setter
|
||||
def meshlines_color(self, color):
|
||||
cv.check_type('plot meshlines color', color, Iterable, Integral)
|
||||
cv.check_length('plot meshlines color', color, 3)
|
||||
for rgb in color:
|
||||
cv.check_greater_than('plot meshlines color', rgb, 0, True)
|
||||
cv.check_less_than('plot meshlines color', rgb, 256)
|
||||
self._meshlines_color = color
|
||||
if 'linewidth' in meshlines:
|
||||
cv.check_type('plot mesh linewidth', meshlines['linewidth'], Integral)
|
||||
cv.check_greater_than('plot mesh linewidth', meshlines['linewidth'],
|
||||
0, equality=True)
|
||||
|
||||
if 'color' in meshlines:
|
||||
cv.check_type('plot meshlines color', meshlines['color'], Iterable,
|
||||
Integral)
|
||||
cv.check_length('plot meshlines color', meshlines['color'], 3)
|
||||
for rgb in meshlines['color']:
|
||||
cv.check_greater_than('plot meshlines color', rgb, 0, True)
|
||||
cv.check_less_than('plot meshlines color', rgb, 256)
|
||||
|
||||
self._meshlines = meshlines
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Plot\n'
|
||||
|
|
@ -325,20 +310,16 @@ class Plot(object):
|
|||
string += '{0: <16}{1}{2}\n'.format('\tOrigin', '=\t', self._origin)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tPixels', '=\t', self._origin)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tColor', '=\t', self._color)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tBackground', '=\t',
|
||||
self._background)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMask components', '=\t',
|
||||
self._mask_components)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMask background', '=\t',
|
||||
self._mask_background)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tCol Spec', '=\t', self._col_spec)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tLevel', '=\t', self._level)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMeshlines type', '=\t',
|
||||
self._meshlines_type)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMeshlines id', '=\t',
|
||||
self._meshlines_id)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMeshlines color', '=\t',
|
||||
self._meshlines_color)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMeshlines linewidth', '=\t',
|
||||
self._meshlines_linewidth)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMeshlines', '=\t',
|
||||
self._meshlines)
|
||||
return string
|
||||
|
||||
def colorize(self, geometry, seed=1):
|
||||
|
|
@ -480,17 +461,18 @@ class Plot(object):
|
|||
|
||||
if self._level is not None:
|
||||
subelement = ET.SubElement(element, "level")
|
||||
subelement.text = ' '.join(str(self._level))
|
||||
subelement.text = str(self._level)
|
||||
|
||||
if self._meshlines_type is not None:
|
||||
if self._meshlines is not None:
|
||||
subelement = ET.SubElement(element, "meshlines")
|
||||
subelement.set("meshtype", self._meshlines_type)
|
||||
if self._meshlines_id is not None:
|
||||
subelement.set("id", str(self._meshlines_id))
|
||||
if self._meshlines_linewidth is not None:
|
||||
subelement.set("linewidth", str(self._meshlines_linewidth))
|
||||
if self._meshlines_color is not None:
|
||||
subelement.set("color", ' '.join(map(str, self._meshlines_color)))
|
||||
subelement.set("meshtype", self._meshlines['type'])
|
||||
if self._meshlines['id'] is not None:
|
||||
subelement.set("id", str(self._meshlines['id']))
|
||||
if self._meshlines['linewidth'] is not None:
|
||||
subelement.set("linewidth", str(self._meshlines['linewidth']))
|
||||
if self._meshlines['color'] is not None:
|
||||
subelement.set("color", ' '.join(map(
|
||||
str, self._meshlines['color'])))
|
||||
|
||||
return element
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue