Use collections.Iterable rather than collections.Sequence. Unfortunately

ndarrays are not sequences.
This commit is contained in:
Paul Romano 2015-06-29 07:45:52 +07:00
parent fa26a4df13
commit 98206be1fe
9 changed files with 87 additions and 87 deletions

View file

@ -31,13 +31,13 @@ def check_type(name, value, expected_type, expected_iter_type=None):
def check_length(name, value, length_min, length_max=None):
"""Ensure that a sequence has length within a given range.
"""Ensure that a sized object has length within a given range.
Parameters
----------
name : str
Description of value being checked
value : Sequence
value : collections.Sized
Object to check length of
length_min : int
Minimum length of object
@ -70,7 +70,7 @@ def check_value(name, value, accepted_values):
----------
name : str
Description of value being checked
value : Sequence
value : collections.Iterable
Object to check
accepted_values : collections.Container
Container of acceptable values

View file

@ -10,7 +10,7 @@ References
"""
from collections import Sequence
from collections import Iterable
from numbers import Real, Integral
from xml.etree import ElementTree as ET
import sys
@ -30,26 +30,26 @@ class CMFDMesh(object):
Attributes
----------
lower_left : Sequence of float
lower_left : Iterable of float
The lower-left corner of the structured mesh. If only two coordinates are
given, it is assumed that the mesh is an x-y mesh.
upper_right : Sequence of float
upper_right : Iterable of float
The upper-right corner of the structrued mesh. If only two coordinates
are given, it is assumed that the mesh is an x-y mesh.
dimension : Sequence of int
dimension : Iterable of int
The number of mesh cells in each direction.
width : Sequence of float
width : Iterable of float
The width of mesh cells in each direction.
energy : Sequence of float
energy : Iterable of float
Energy bins in MeV, listed in ascending order (e.g. [0.0, 0.625e-7,
20.0]) for CMFD tallies and acceleration. If no energy bins are listed,
OpenMC automatically assumes a one energy group calculation over the
entire energy range.
albedo : Sequence of float
albedo : Iterable of float
Surface ratio of incoming to outgoing partial currents on global
boundary conditions. They are listed in the following order: -x +x -y +y
-z +z.
map : Sequence of int
map : Iterable of int
An optional acceleration map can be specified to overlay on the coarse
mesh spatial grid. If this option is used, a ``1`` is used for a
non-accelerated region and a ``2`` is used for an accelerated region.
@ -109,31 +109,31 @@ class CMFDMesh(object):
@lower_left.setter
def lower_left(self, lower_left):
check_type('CMFD mesh lower_left', lower_left, Sequence, Real)
check_type('CMFD mesh lower_left', lower_left, Iterable, Real)
check_length('CMFD mesh lower_left', lower_left, 2, 3)
self._lower_left = lower_left
@upper_right.setter
def upper_right(self, upper_right):
check_type('CMFD mesh upper_right', upper_right, Sequence, Real)
check_type('CMFD mesh upper_right', upper_right, Iterable, Real)
check_length('CMFD mesh upper_right', upper_right, 2, 3)
self._upper_right = upper_right
@dimension.setter
def dimension(self, dimension):
check_type('CMFD mesh dimension', dimension, Sequence, Integral)
check_type('CMFD mesh dimension', dimension, Iterable, Integral)
check_length('CMFD mesh dimension', dimension, 2, 3)
self._dimension = dimension
@width.setter
def width(self, width):
check_type('CMFD mesh width', width, Sequence, Real)
check_type('CMFD mesh width', width, Iterable, Real)
check_length('CMFD mesh width', width, 2, 3)
self._width = width
@energy.setter
def energy(self, energy):
check_type('CMFD mesh energy', energy, Sequence, Real)
check_type('CMFD mesh energy', energy, Iterable, Real)
for e in energy:
if e < 0:
msg = 'Unable to set CMFD Mesh energy to {0} which is ' \
@ -143,7 +143,7 @@ class CMFDMesh(object):
@albedo.setter
def albedo(self, albedo):
check_type('CMFD mesh albedo', albedo, Sequence, Real)
check_type('CMFD mesh albedo', albedo, Iterable, Real)
check_length('CMFD mesh albedo', albedo, 6)
for a in albedo:
if a < 0 or a > 1:
@ -154,7 +154,7 @@ class CMFDMesh(object):
@map.setter
def map(self, meshmap):
check_type('CMFD mesh map', meshmap, Sequence, Integral)
check_type('CMFD mesh map', meshmap, Iterable, Integral)
for m in meshmap:
if m != 1 and m != 2:
msg = 'Unable to set CMFD Mesh map to {0} which is ' \
@ -221,7 +221,7 @@ class CMFDFile(object):
feedback : bool
Indicate or not the CMFD diffusion result is used to adjust the weight
of fission source neutrons on the next OpenMC batch. Defaults to False.
gauss_seidel_tolerance : Sequence of float
gauss_seidel_tolerance : Iterable of float
Two parameters specifying the absolute inner tolerance and the relative
inner tolerance for Gauss-Seidel iterations when performing CMFD.
ktol : float
@ -369,7 +369,7 @@ class CMFDFile(object):
@gauss_seidel_tolerance.setter
def gauss_seidel_tolerance(self, gauss_seidel_tolerance):
check_type('Gauss-Seidel tolerance', gauss_seidel_tolerance,
Sequence, Real)
Iterable, Real)
check_length('Gauss-Seidel tolerance', gauss_seidel_tolerance, 2)
self._gauss_seidel_tolerance = gauss_seidel_tolerance
@ -415,7 +415,7 @@ class CMFDFile(object):
@tally_reset.setter
def tally_reset(self, tally_reset):
check_type('tally reset batches', tally_reset, Sequence, Integral)
check_type('tally reset batches', tally_reset, Iterable, Integral)
self._tally_reset = tally_reset
@write_matrices.setter

View file

@ -1,4 +1,4 @@
from collections import Sequence
from collections import Iterable
import copy
from numbers import Real, Integral
@ -16,7 +16,7 @@ class Filter(object):
The type of the tally filter. Acceptable values are "universe",
"material", "cell", "cellborn", "surface", "mesh", "energy",
"energyout", and "distribcell".
bins : int or Sequence of int or Sequence of float
bins : int or Iterable of int or Iterable of float
The bins for the filter. This takes on different meaning for different
filters.
@ -24,7 +24,7 @@ class Filter(object):
----------
type : str
The type of the tally filter.
bins : int or Sequence of int or Sequence of float
bins : int or Iterable of int or Iterable of float
The bins for the filter
"""
@ -123,7 +123,7 @@ class Filter(object):
raise ValueError(msg)
# If the bin edge is a single value, it is a Cell, Material, etc. ID
if not isinstance(bins, Sequence):
if not isinstance(bins, Iterable):
bins = [bins]
# If the bins are in a collection, convert it to a list

View file

@ -1,4 +1,4 @@
from collections import Sequence
from collections import Iterable
from copy import deepcopy
from numbers import Real, Integral
import warnings
@ -541,9 +541,9 @@ class MaterialsFile(object):
"""
if not isinstance(materials, Sequence):
if not isinstance(materials, Iterable):
msg = 'Unable to create OpenMC materials.xml file from {0} which ' \
'is not a sequence'.format(materials)
'is not iterable'.format(materials)
raise ValueError(msg)
for material in materials:

View file

@ -1,4 +1,4 @@
from collections import Sequence
from collections import Iterable
import copy
from numbers import Real, Integral
from xml.etree import ElementTree as ET
@ -41,10 +41,10 @@ class Mesh(object):
lower_left : Seuqnce of float
The lower-left corner of the structured mesh. If only two coordinate are
given, it is assumed that the mesh is an x-y mesh.
upper_right : Sequence of float
upper_right : Iterable of float
The upper-right corner of the structrued mesh. If only two coordinate
are given, it is assumed that the mesh is an x-y mesh.
width : Sequence of float
width : Iterable of float
The width of mesh cells in each direction.
"""
@ -163,25 +163,25 @@ class Mesh(object):
@dimension.setter
def dimension(self, dimension):
check_type('mesh dimension', dimension, Sequence, Integral)
check_type('mesh dimension', dimension, Iterable, Integral)
check_length('mesh dimension', dimension, 2, 3)
self._dimension = dimension
@lower_left.setter
def lower_left(self, lower_left):
check_type('mesh lower_left', lower_left, Sequence, Real)
check_type('mesh lower_left', lower_left, Iterable, Real)
check_length('mesh lower_left', lower_left, 2, 3)
self._lower_left = lower_left
@upper_right.setter
def upper_right(self, upper_right):
check_type('mesh upper_right', upper_right, Sequence, Real)
check_type('mesh upper_right', upper_right, Iterable, Real)
check_length('mesh upper_right', upper_right, 2, 3)
self._upper_right = upper_right
@width.setter
def width(self, width):
check_type('mesh width', width, Sequence, Real)
check_type('mesh width', width, Iterable, Real)
check_length('mesh width', width, 2, 3)
self._width = width

View file

@ -1,4 +1,4 @@
from collections import Sequence
from collections import Iterable
from numbers import Real, Integral
from xml.etree import ElementTree as ET
import sys
@ -40,9 +40,9 @@ class Plot(object):
Unique identifier
name : str
Name of the plot
width : Sequence of float
width : Iterable of float
Width of the plot in each basis direction
pixels : Sequence of int
pixels : Iterable of int
Number of pixels to use in each basis direction
origin : tuple or list of ndarray
Origin (center) of the plot
@ -56,9 +56,9 @@ class Plot(object):
The basis directions for the plot
background : tuple or list of ndarray
Color of the background defined by RGB
mask_components : Sequence of int
mask_components : Iterable of int
Unique id numbers of the cells or materials to plot
mask_background : Sequence of int
mask_background : Iterable of int
Color to apply to all cells/materials not listed in mask_components
defined by RGB
col_spec : dict
@ -156,19 +156,19 @@ class Plot(object):
@width.setter
def width(self, width):
check_type('plot width', width, Sequence, Real)
check_type('plot width', width, Iterable, Real)
check_length('plot width', width, 2, 3)
self._width = width
@origin.setter
def origin(self, origin):
check_type('plot origin', origin, Sequence, Real)
check_type('plot origin', origin, Iterable, Real)
check_length('plot origin', origin, 3)
self._origin = origin
@pixels.setter
def pixels(self, pixels):
check_type('plot pixels', pixels, Sequence, Integral)
check_type('plot pixels', pixels, Iterable, Integral)
check_length('plot pixels', pixels, 2, 3)
for dim in pixels:
if dim < 0:
@ -202,7 +202,7 @@ class Plot(object):
@background.setter
def background(self, background):
check_type('plot background', background, Sequence, Integral)
check_type('plot background', background, Iterable, Integral)
check_length('plot background', background, 3)
for rgb in background:
if rgb < 0 or rgb > 255:
@ -230,9 +230,9 @@ class Plot(object):
'which is less than 0'.format(self._id, key)
raise ValueError(msg)
elif not isinstance(col_spec[key], Sequence):
elif not isinstance(col_spec[key], Iterable):
msg = 'Unable to create Plot ID={0} with col_spec RGB values' \
' {1} which is not a sequence'.format(self._id, col_spec[key])
' {1} which is not iterable'.format(self._id, col_spec[key])
raise ValueError(msg)
elif len(col_spec[key]) != 3:
@ -245,7 +245,7 @@ class Plot(object):
@mask_componenets.setter
def mask_components(self, mask_components):
check_type('plot mask_components', mask_components, Sequence, Integral)
check_type('plot mask_components', mask_components, Iterable, Integral)
for component in mask_components:
if component < 0:
msg = 'Unable to create Plot ID={0} with mask component {1} ' \
@ -255,7 +255,7 @@ class Plot(object):
@mask_background.setter
def mask_background(self, mask_background):
check_type('plot mask background', mask_background, Sequence, Integral)
check_type('plot mask background', mask_background, Iterable, Integral)
check_length('plot mask background', mask_background, 3)
for rgb in mask_background:
if rgb < 0 or rgb > 255:

View file

@ -1,4 +1,4 @@
from collections import Sequence
from collections import Iterable
from numbers import Real, Integral
import warnings
from xml.etree import ElementTree as ET
@ -43,11 +43,11 @@ class SettingsFile(object):
Path to write output to
verbosity : int
Verbosity during simulation between 1 and 10
statepoint_batches : Sequence of int
statepoint_batches : Iterable of int
List of batches at which to write statepoint files
statepoint_interval : int
Number of batches after which a new statepoint file should be written
sourcepoint_batches : Sequence of int
sourcepoint_batches : Iterable of int
List of batches at which to write source files
sourcepoint_interval : int
Number of batches after which a new source file should be written
@ -480,7 +480,7 @@ class SettingsFile(object):
distribution samples locations from a "box" distribution but only
locations in fissionable materials are accepted. A "point" spatial
distribution has coordinates specified by a triplet.
params : Sequence of float
params : Iterable of float
For a "box" or "fission" spatial distribution, ``params`` should be
given as six real numbers, the first three of which specify the
lower-left corner of a parallelepiped and the last three of which
@ -495,7 +495,7 @@ class SettingsFile(object):
check_type('source space type', stype, basestring)
check_value('source space type', stype, ['box', 'fission', 'point'])
check_type('source space parameters', params, Sequence, Real)
check_type('source space parameters', params, Iterable, Real)
if stype in ['box', 'fission'] and len(params) != 6:
check_length('source space parameters for a '
'box/fission distribution', params, 6)
@ -517,7 +517,7 @@ class SettingsFile(object):
site is isotropic if the "isotropic" option is given. The angle of
the particle emitted from a source site is the direction specified
in ``params`` if the "monodirectional" option is given.
params : Sequence of float
params : Iterable of float
For an "isotropic" angular distribution, ``params`` should not
be specified.
@ -530,7 +530,7 @@ class SettingsFile(object):
check_type('source angle type', stype, basestring)
check_value('source angle type', stype,
['isotropic', 'monodirectional'])
check_type('source angle parameters', params, Sequence, Real)
check_type('source angle parameters', params, Iterable, Real)
if stype == 'isotropic' and params is not None:
msg = 'Unable to set source angle parameters since they are not ' \
'it is not supported for isotropic type sources'
@ -554,7 +554,7 @@ class SettingsFile(object):
whose energy is sampled from a Watt fission spectrum. The "maxwell"
option produce source sites whose energy is sampled from a Maxwell
fission spectrum.
params : Sequence of float
params : Iterable of float
For a "monoenergetic" energy distribution, ``params`` should be
given as the energy in MeV of the source sites.
@ -571,7 +571,7 @@ class SettingsFile(object):
check_type('source energy type', stype, basestring)
check_value('source energy type', stype,
['monoenergetic', 'watt', 'maxwell'])
check_type('source energy parameters', params, Sequence, Real)
check_type('source energy parameters', params, Iterable, Real)
if stype in ['monoenergetic', 'maxwell']:
check_length('source energy parameters for a monoenergetic '
'or Maxwell source', params, 1)
@ -619,7 +619,7 @@ class SettingsFile(object):
@statepoint_batches.setter
def statepoint_batches(self, batches):
check_type('statepoint batches', batches, Sequence, Integral)
check_type('statepoint batches', batches, Iterable, Integral)
for batch in batches:
if batch <= 0:
msg = 'Unable to set statepoint batches with {0} which is ' \
@ -634,7 +634,7 @@ class SettingsFile(object):
@sourcepoint_batches.setter
def sourcepoint_batches(self, batches):
check_type('sourcepoint batches', batches, Sequence, Integral)
check_type('sourcepoint batches', batches, Iterable, Integral)
for batch in batches:
if batch <= 0:
msg = 'Unable to set sourcepoint batches with {0} which is ' \
@ -721,21 +721,21 @@ class SettingsFile(object):
@entropy_dimension.setter
def entropy_dimension(self, dimension):
check_type('entropy mesh dimension', dimension, Sequence, Integral)
check_type('entropy mesh dimension', dimension, Iterable, Integral)
check_length('entropy mesh dimension', dimension, 3)
self._entropy_dimension = dimension
@entropy_lower_left.setter
def entropy_lower_left(self, lower_left):
check_type('entropy mesh lower left corner', lower_left,
Sequence, Real)
Iterable, Real)
check_length('entropy mesh lower left corner', lower_left, 3)
self._entropy_lower_left = lower_left
@entropy_upper_right.setter
def entropy_upper_right(self, upper_right):
check_type('entropy mesh upper right corner', upper_right,
Sequence, Real)
Iterable, Real)
check_length('entropy mesh upper right corner', upper_right, 3)
self._entropy_upper_right = upper_right
@ -778,7 +778,7 @@ class SettingsFile(object):
@trace.setter
def trace(self, trace):
check_type('trace', trace, Sequence, Integral)
check_type('trace', trace, Iterable, Integral)
check_length('trace', trace, 3)
if trace[0] < 1:
msg = 'Unable to set the trace batch to {0} since it must be ' \
@ -796,7 +796,7 @@ class SettingsFile(object):
@track.setter
def track(self, track):
check_type('track', track, Sequence, Integral)
check_type('track', track, Iterable, Integral)
if len(track) % 3 != 0:
msg = 'Unable to set the track to {0} since its length is ' \
'not a multiple of 3'.format(track)
@ -818,7 +818,7 @@ class SettingsFile(object):
@ufs_dimension.setter
def ufs_dimension(self, dimension):
check_type('UFS mesh dimension', dimension, Sequence, Integral)
check_type('UFS mesh dimension', dimension, Iterable, Integral)
check_length('UFS mesh dimension', dimension, 3)
for dim in dimension:
if dim < 1:
@ -829,13 +829,13 @@ class SettingsFile(object):
@ufs_lower_left.setter
def ufs_lower_left(self, lower_left):
check_type('UFS mesh lower left corner', lower_left, Sequence, Real)
check_type('UFS mesh lower left corner', lower_left, Iterable, Real)
check_length('UFS mesh lower left corner', lower_left, 3)
self._ufs_lower_left = lower_left
@ufs_upper_right.setter
def ufs_upper_right(self, upper_right):
check_type('UFS mesh upper right corner', upper_right, Sequence, Real)
check_type('UFS mesh upper right corner', upper_right, Iterable, Real)
check_length('UFS mesh upper right corner', upper_right, 3)
self._ufs_upper_right = upper_right
@ -845,7 +845,7 @@ class SettingsFile(object):
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
check_type('DD mesh dimension', dimension, Sequence, Integral)
check_type('DD mesh dimension', dimension, Iterable, Integral)
check_length('DD mesh dimension', dimension, 3)
self._dd_mesh_dimension = dimension
@ -856,7 +856,7 @@ class SettingsFile(object):
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
check_type('DD mesh lower left corner', lower_left, Sequence, Real)
check_type('DD mesh lower left corner', lower_left, Iterable, Real)
check_length('DD mesh lower left corner', lower_left, 3)
self._dd_mesh_lower_left = lower_left
@ -867,7 +867,7 @@ class SettingsFile(object):
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
check_type('DD mesh upper right corner', upper_right, Sequence, Real)
check_type('DD mesh upper right corner', upper_right, Iterable, Real)
check_length('DD mesh upper right corner', upper_right, 3)
self._dd_mesh_upper_right = upper_right
@ -878,7 +878,7 @@ class SettingsFile(object):
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
check_type('DD nodemap', nodemap, Sequence)
check_type('DD nodemap', nodemap, Iterable)
nodemap = np.array(nodemap).flatten()

View file

@ -1,4 +1,4 @@
from collections import Sequence
from collections import Iterable
import copy
import os
import pickle
@ -387,12 +387,12 @@ class Tally(object):
@sum.setter
def sum(self, sum):
check_type('sum', sum, Sequence)
check_type('sum', sum, Iterable)
self._sum = sum
@sum_sq.setter
def sum_sq(self, sum_sq):
check_type('sum_sq', sum_sq, Sequence)
check_type('sum_sq', sum_sq, Iterable)
self._sum_sq = sum_sq
def remove_score(self, score):

View file

@ -1,5 +1,5 @@
import abc
from collections import OrderedDict, Sequence
from collections import OrderedDict, Iterable
from numbers import Real, Integral
from xml.etree import ElementTree as ET
import sys
@ -151,19 +151,19 @@ class Cell(object):
@rotation.setter
def rotation(self, rotation):
check_type('cell rotation', rotation, Sequence, Real)
check_type('cell rotation', rotation, Iterable, Real)
check_length('cell rotation', rotation, 3)
self._rotation = rotation
@translation.setter
def translation(self, translation):
check_type('cell translation', translation, Sequence, Real)
check_type('cell translation', translation, Iterable, Real)
check_length('cell translation', translation, 3)
self._translation = translation
@offsets.setter
def offsets(self, offsets):
check_type('offsets', offsets, Sequence)
check_type('offsets', offsets, Iterable)
self._offsets = offsets
def add_surface(self, surface, halfspace):
@ -477,9 +477,9 @@ class Universe(object):
"""
if not isinstance(cells, Sequence):
if not isinstance(cells, Iterable):
msg = 'Unable to add Cells to Universe ID={0} since {1} is not ' \
'a sequence'.format(self._id, cells)
'iterable'.format(self._id, cells)
raise ValueError(msg)
for cell in cells:
@ -696,7 +696,7 @@ class Lattice(object):
@universes.setter
def universes(self, universes):
check_type('lattice universes', universes, Sequence)
check_type('lattice universes', universes, Iterable)
self._universes = np.asarray(universes, dtype=Universe)
def get_unique_universes(self):
@ -834,7 +834,7 @@ class RectLattice(Lattice):
@dimension.setter
def dimension(self, dimension):
check_type('lattice dimension', dimension, Sequence, Integral)
check_type('lattice dimension', dimension, Iterable, Integral)
check_length('lattice dimension', dimension, 2, 3)
for dim in dimension:
if dim < 0:
@ -845,18 +845,18 @@ class RectLattice(Lattice):
@lower_left.setter
def lower_left(self, lower_left):
check_type('lattice lower left corner', lower_left, Sequence, Real)
check_type('lattice lower left corner', lower_left, Iterable, Real)
check_length('lattice lower left corner', lower_left, 2, 3)
self._lower_left = lower_left
@offsets.setter
def offsets(self, offsets):
check_type('offsets', offsets, Sequence)
check_type('offsets', offsets, Iterable)
self._offsets = offsets
@Lattice.pitch.setter
def pitch(self, pitch):
check_type('lattice pitch', pitch, Sequence, Real)
check_type('lattice pitch', pitch, Iterable, Real)
check_length('lattice pitch', pitch, 2, 3)
for dim in pitch:
if dim < 0:
@ -1073,13 +1073,13 @@ class HexLattice(Lattice):
@center.setter
def center(self, center):
check_type('lattice center', center, Sequence, Real)
check_type('lattice center', center, Iterable, Real)
check_length('lattice center', center, 2, 3)
self._center = center
@Lattice.pitch.setter
def pitch(self, pitch):
check_type('lattice pitch', pitch, Sequence, Real)
check_type('lattice pitch', pitch, Iterable, Real)
check_length('lattice pitch', pitch, 2, 3)
for dim in pitch:
if dim < 0: