Make filter_strides a property of Tally

This commit is contained in:
Paul Romano 2017-12-19 15:58:14 +07:00
parent e698403076
commit e6b5803f70
5 changed files with 71 additions and 225 deletions

View file

@ -237,9 +237,6 @@ class CrossFilter(object):
left / right filters
num_bins : Integral
The number of filter bins (always 1 if aggregate_filter is defined)
stride : Integral
The number of filter, nuclide and score bins within each of this
crossfilter's bins.
"""
@ -250,7 +247,6 @@ class CrossFilter(object):
self._type = '({0} {1} {2})'.format(left_type, binary_op, right_type)
self._bins = {}
self._stride = None
self._left_filter = None
self._right_filter = None
@ -314,10 +310,6 @@ class CrossFilter(object):
else:
return 0
@property
def stride(self):
return self._stride
@type.setter
def type(self, filter_type):
if filter_type not in _FILTER_TYPES:
@ -347,10 +339,6 @@ class CrossFilter(object):
cv.check_value('binary_op', binary_op, _TALLY_ARITHMETIC_OPS)
self._binary_op = binary_op
@stride.setter
def stride(self, stride):
self._stride = stride
def get_bin_index(self, filter_bin):
"""Returns the index in the CrossFilter for some bin.
@ -611,9 +599,6 @@ class AggregateFilter(object):
The filter bins included in the aggregation
num_bins : Integral
The number of filter bins (always 1 if aggregate_filter is defined)
stride : Integral
The number of filter, nuclide and score bins within each of this
aggregatefilter's bins.
"""
@ -622,7 +607,6 @@ class AggregateFilter(object):
self._type = '{0}({1})'.format(aggregate_op,
aggregate_filter.short_name.lower())
self._bins = None
self._stride = None
self._aggregate_filter = None
self._aggregate_op = None
@ -684,10 +668,6 @@ class AggregateFilter(object):
def num_bins(self):
return len(self.bins) if self.aggregate_filter else 0
@property
def stride(self):
return self._stride
@type.setter
def type(self, filter_type):
if filter_type not in _FILTER_TYPES:
@ -714,10 +694,6 @@ class AggregateFilter(object):
cv.check_value('aggregate_op', aggregate_op, _TALLY_AGGREGATE_OPS)
self._aggregate_op = aggregate_op
@stride.setter
def stride(self, stride):
self._stride = stride
def get_bin_index(self, filter_bin):
"""Returns the index in the AggregateFilter for some bin.
@ -753,7 +729,7 @@ class AggregateFilter(object):
else:
return self.bins.index(filter_bin)
def get_pandas_dataframe(self, data_size, summary=None, **kwargs):
def get_pandas_dataframe(self, data_size, stride, summary=None, **kwargs):
"""Builds a Pandas DataFrame for the AggregateFilter's bins.
This method constructs a Pandas DataFrame object for the AggregateFilter
@ -762,8 +738,10 @@ class AggregateFilter(object):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
summary : None or Summary
An optional Summary object to be used to construct columns for
distribcell tally filters (default is None). NOTE: This parameter
@ -793,7 +771,7 @@ class AggregateFilter(object):
filter_bins[i] = bin
# Repeat and tile bins as needed for DataFrame
filter_bins = np.repeat(filter_bins, self.stride)
filter_bins = np.repeat(filter_bins, stride)
tile_factor = data_size / len(filter_bins)
filter_bins = np.tile(filter_bins, tile_factor)

View file

@ -86,9 +86,6 @@ class Filter(IDManagerMixin):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@ -99,7 +96,6 @@ class Filter(IDManagerMixin):
self.bins = bins
self.id = filter_id
self._num_bins = 0
self._stride = None
def __eq__(self, other):
if type(self) is not type(other):
@ -194,10 +190,6 @@ class Filter(IDManagerMixin):
def num_bins(self):
return self._num_bins
@property
def stride(self):
return self._stride
@bins.setter
def bins(self, bins):
# Format the bins as a 1D numpy array.
@ -214,16 +206,6 @@ class Filter(IDManagerMixin):
cv.check_greater_than('filter num_bins', num_bins, 0, equality=True)
self._num_bins = num_bins
@stride.setter
def stride(self, stride):
cv.check_type('filter stride', stride, Integral)
if stride < 0:
msg = 'Unable to set stride "{0}" for a "{1}" since it ' \
'is a negative value'.format(stride, type(self))
raise ValueError(msg)
self._stride = stride
def check_bins(self, bins):
"""Make sure given bins are valid for this filter.
@ -270,11 +252,7 @@ class Filter(IDManagerMixin):
Whether the filter can be merged
"""
if type(self) is not type(other):
return False
return True
return type(self) is type(other)
def merge(self, other):
"""Merge this filter with another.
@ -402,7 +380,7 @@ class Filter(IDManagerMixin):
# Return a 1-tuple of the bin.
return (self.bins[bin_index],)
def get_pandas_dataframe(self, data_size, **kwargs):
def get_pandas_dataframe(self, data_size, stride, **kwargs):
"""Builds a Pandas DataFrame for the Filter's bins.
This method constructs a Pandas DataFrame object for the filter with
@ -411,13 +389,15 @@ class Filter(IDManagerMixin):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
Keyword arguments
-----------------
paths : bool
Only used for DistirbcellFilter. If True (default), expand
Only used for DistribcellFilter. If True (default), expand
distribcell indices into multi-index columns describing the path
to that distribcell through the CSG tree. NOTE: This option assumes
that all distribcell paths are of the same length and do not have
@ -431,11 +411,6 @@ class Filter(IDManagerMixin):
the total number of bins in the corresponding tally, with the filter
bin appropriately tiled to map to the corresponding tally bins.
Raises
------
ImportError
When Pandas is not installed
See also
--------
Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
@ -444,7 +419,7 @@ class Filter(IDManagerMixin):
# Initialize Pandas DataFrame
df = pd.DataFrame()
filter_bins = np.repeat(self.bins, self.stride)
filter_bins = np.repeat(self.bins, stride)
tile_factor = data_size // len(filter_bins)
filter_bins = np.tile(filter_bins, tile_factor)
df = pd.concat([df, pd.DataFrame(
@ -502,9 +477,6 @@ class UniverseFilter(WithIDFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@property
@ -535,9 +507,6 @@ class MaterialFilter(WithIDFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@property
@ -568,15 +537,12 @@ class CellFilter(WithIDFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@property
def bins(self):
return self._bins
@bins.setter
def bins(self, bins):
self._smart_set_bins(bins, openmc.Cell)
@ -601,15 +567,12 @@ class CellFromFilter(WithIDFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@property
def bins(self):
return self._bins
@bins.setter
def bins(self, bins):
self._smart_set_bins(bins, openmc.Cell)
@ -634,9 +597,6 @@ class CellbornFilter(WithIDFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@property
@ -668,9 +628,6 @@ class SurfaceFilter(Filter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@property
@ -696,7 +653,7 @@ class SurfaceFilter(Filter):
@num_bins.setter
def num_bins(self, num_bins): pass
def get_pandas_dataframe(self, data_size, **kwargs):
def get_pandas_dataframe(self, data_size, stride, **kwargs):
"""Builds a Pandas DataFrame for the Filter's bins.
This method constructs a Pandas DataFrame object for the filter with
@ -705,8 +662,10 @@ class SurfaceFilter(Filter):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
Returns
-------
@ -717,11 +676,6 @@ class SurfaceFilter(Filter):
the corresponding tally, with the filter bin appropriately tiled to
map to the corresponding tally bins.
Raises
------
ImportError
When Pandas is not installed
See also
--------
Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
@ -730,7 +684,7 @@ class SurfaceFilter(Filter):
# Initialize Pandas DataFrame
df = pd.DataFrame()
filter_bins = np.repeat(self.bins, self.stride)
filter_bins = np.repeat(self.bins, stride)
tile_factor = data_size // len(filter_bins)
filter_bins = np.tile(filter_bins, tile_factor)
filter_bins = [_CURRENT_NAMES[x] for x in filter_bins]
@ -760,9 +714,6 @@ class MeshFilter(Filter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@ -854,7 +805,7 @@ class MeshFilter(Filter):
y = bin_index - (x * ny)
return (x, y)
def get_pandas_dataframe(self, data_size, **kwargs):
def get_pandas_dataframe(self, data_size, stride, **kwargs):
"""Builds a Pandas DataFrame for the Filter's bins.
This method constructs a Pandas DataFrame object for the filter with
@ -863,8 +814,10 @@ class MeshFilter(Filter):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
Returns
-------
@ -875,11 +828,6 @@ class MeshFilter(Filter):
corresponding tally, with the filter bin appropriately tiled to map
to the corresponding tally bins.
Raises
------
ImportError
When Pandas is not installed
See also
--------
Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
@ -906,7 +854,7 @@ class MeshFilter(Filter):
# Generate multi-index sub-column for x-axis
filter_bins = np.arange(1, nx + 1)
repeat_factor = ny * nz * self.stride
repeat_factor = ny * nz * stride
filter_bins = np.repeat(filter_bins, repeat_factor)
tile_factor = data_size // len(filter_bins)
filter_bins = np.tile(filter_bins, tile_factor)
@ -914,7 +862,7 @@ class MeshFilter(Filter):
# Generate multi-index sub-column for y-axis
filter_bins = np.arange(1, ny + 1)
repeat_factor = nz * self.stride
repeat_factor = nz * stride
filter_bins = np.repeat(filter_bins, repeat_factor)
tile_factor = data_size // len(filter_bins)
filter_bins = np.tile(filter_bins, tile_factor)
@ -922,7 +870,7 @@ class MeshFilter(Filter):
# Generate multi-index sub-column for z-axis
filter_bins = np.arange(1, nz + 1)
repeat_factor = self.stride
repeat_factor = stride
filter_bins = np.repeat(filter_bins, repeat_factor)
tile_factor = data_size // len(filter_bins)
filter_bins = np.tile(filter_bins, tile_factor)
@ -952,9 +900,6 @@ class RealFilter(Filter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@ -1063,9 +1008,6 @@ class EnergyFilter(RealFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@ -1100,7 +1042,7 @@ class EnergyFilter(RealFilter):
'increasing'.format(bins, type(self))
raise ValueError(msg)
def get_pandas_dataframe(self, data_size, **kwargs):
def get_pandas_dataframe(self, data_size, stride, **kwargs):
"""Builds a Pandas DataFrame for the Filter's bins.
This method constructs a Pandas DataFrame object for the filter with
@ -1109,8 +1051,10 @@ class EnergyFilter(RealFilter):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
Returns
-------
@ -1121,11 +1065,6 @@ class EnergyFilter(RealFilter):
corresponding tally, with the filter bin appropriately tiled to map
to the corresponding tally bins.
Raises
------
ImportError
When Pandas is not installed
See also
--------
Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
@ -1136,8 +1075,8 @@ class EnergyFilter(RealFilter):
# Extract the lower and upper energy bounds, then repeat and tile
# them as necessary to account for other filters.
lo_bins = np.repeat(self.bins[:-1], self.stride)
hi_bins = np.repeat(self.bins[1:], self.stride)
lo_bins = np.repeat(self.bins[:-1], stride)
hi_bins = np.repeat(self.bins[1:], stride)
tile_factor = data_size // len(lo_bins)
lo_bins = np.tile(lo_bins, tile_factor)
hi_bins = np.tile(hi_bins, tile_factor)
@ -1167,9 +1106,6 @@ class EnergyoutFilter(EnergyFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@ -1229,9 +1165,6 @@ class DistribcellFilter(Filter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
paths : list of str
The paths traversed through the CSG tree to reach each distribcell
instance (for 'distribcell' filters only)
@ -1296,7 +1229,7 @@ class DistribcellFilter(Filter):
# the Cell in the Geometry (consecutive integers starting at 0).
return filter_bin
def get_pandas_dataframe(self, data_size, **kwargs):
def get_pandas_dataframe(self, data_size, stride, **kwargs):
"""Builds a Pandas DataFrame for the Filter's bins.
This method constructs a Pandas DataFrame object for the filter with
@ -1305,8 +1238,10 @@ class DistribcellFilter(Filter):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
Keyword arguments
-----------------
@ -1331,11 +1266,6 @@ class DistribcellFilter(Filter):
of bins in the corresponding tally, with the filter bin
appropriately tiled to map to the corresponding tally bins.
Raises
------
ImportError
When Pandas is not installed
See also
--------
Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
@ -1418,7 +1348,7 @@ class DistribcellFilter(Filter):
# Tile the Multi-index columns
for level_key, level_bins in level_dict.items():
level_bins = np.repeat(level_bins, self.stride)
level_bins = np.repeat(level_bins, stride)
tile_factor = data_size // len(level_bins)
level_bins = np.tile(level_bins, tile_factor)
level_dict[level_key] = level_bins
@ -1434,7 +1364,7 @@ class DistribcellFilter(Filter):
# NOTE: This is performed regardless of whether the user
# requests Summary geometric information
filter_bins = np.arange(self.num_bins)
filter_bins = np.repeat(filter_bins, self.stride)
filter_bins = np.repeat(filter_bins, stride)
tile_factor = data_size // len(filter_bins)
filter_bins = np.tile(filter_bins, tile_factor)
df = pd.DataFrame({self.short_name.lower() : filter_bins})
@ -1474,9 +1404,6 @@ class MuFilter(RealFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@ -1504,7 +1431,7 @@ class MuFilter(RealFilter):
'increasing'.format(bins, type(self))
raise ValueError(msg)
def get_pandas_dataframe(self, data_size, **kwargs):
def get_pandas_dataframe(self, data_size, stride, **kwargs):
"""Builds a Pandas DataFrame for the Filter's bins.
This method constructs a Pandas DataFrame object for the filter with
@ -1513,8 +1440,10 @@ class MuFilter(RealFilter):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
Returns
-------
@ -1525,11 +1454,6 @@ class MuFilter(RealFilter):
corresponding tally, with the filter bin appropriately tiled to map
to the corresponding tally bins.
Raises
------
ImportError
When Pandas is not installed
See also
--------
Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
@ -1540,8 +1464,8 @@ class MuFilter(RealFilter):
# Extract the lower and upper energy bounds, then repeat and tile
# them as necessary to account for other filters.
lo_bins = np.repeat(self.bins[:-1], self.stride)
hi_bins = np.repeat(self.bins[1:], self.stride)
lo_bins = np.repeat(self.bins[:-1], stride)
hi_bins = np.repeat(self.bins[1:], stride)
tile_factor = data_size // len(lo_bins)
lo_bins = np.tile(lo_bins, tile_factor)
hi_bins = np.tile(hi_bins, tile_factor)
@ -1579,9 +1503,6 @@ class PolarFilter(RealFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@ -1609,7 +1530,7 @@ class PolarFilter(RealFilter):
'increasing'.format(bins, type(self))
raise ValueError(msg)
def get_pandas_dataframe(self, data_size, **kwargs):
def get_pandas_dataframe(self, data_size, stride, **kwargs):
"""Builds a Pandas DataFrame for the Filter's bins.
This method constructs a Pandas DataFrame object for the filter with
@ -1618,8 +1539,10 @@ class PolarFilter(RealFilter):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
Returns
-------
@ -1630,11 +1553,6 @@ class PolarFilter(RealFilter):
corresponding tally, with the filter bin appropriately tiled to map
to the corresponding tally bins.
Raises
------
ImportError
When Pandas is not installed
See also
--------
Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
@ -1645,8 +1563,8 @@ class PolarFilter(RealFilter):
# Extract the lower and upper angle bounds, then repeat and tile
# them as necessary to account for other filters.
lo_bins = np.repeat(self.bins[:-1], self.stride)
hi_bins = np.repeat(self.bins[1:], self.stride)
lo_bins = np.repeat(self.bins[:-1], stride)
hi_bins = np.repeat(self.bins[1:], stride)
tile_factor = data_size // len(lo_bins)
lo_bins = np.tile(lo_bins, tile_factor)
hi_bins = np.tile(hi_bins, tile_factor)
@ -1684,9 +1602,6 @@ class AzimuthalFilter(RealFilter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@ -1714,7 +1629,7 @@ class AzimuthalFilter(RealFilter):
'increasing'.format(bins, type(self))
raise ValueError(msg)
def get_pandas_dataframe(self, data_size, paths=True):
def get_pandas_dataframe(self, data_size, stride, paths=True):
"""Builds a Pandas DataFrame for the Filter's bins.
This method constructs a Pandas DataFrame object for the filter with
@ -1723,8 +1638,10 @@ class AzimuthalFilter(RealFilter):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
Returns
-------
@ -1735,11 +1652,6 @@ class AzimuthalFilter(RealFilter):
corresponding tally, with the filter bin appropriately tiled to map
to the corresponding tally bins.
Raises
------
ImportError
When Pandas is not installed
See also
--------
Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
@ -1750,8 +1662,8 @@ class AzimuthalFilter(RealFilter):
# Extract the lower and upper angle bounds, then repeat and tile
# them as necessary to account for other filters.
lo_bins = np.repeat(self.bins[:-1], self.stride)
hi_bins = np.repeat(self.bins[1:], self.stride)
lo_bins = np.repeat(self.bins[:-1], stride)
hi_bins = np.repeat(self.bins[1:], stride)
tile_factor = data_size // len(lo_bins)
lo_bins = np.tile(lo_bins, tile_factor)
hi_bins = np.tile(hi_bins, tile_factor)
@ -1785,9 +1697,6 @@ class DelayedGroupFilter(Filter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@property
@ -1840,9 +1749,6 @@ class EnergyFunctionFilter(Filter):
Unique identifier for the filter
num_bins : Integral
The number of filter bins (always 1 for this filter)
stride : Integral
The number of filter, nuclide and score bins within each of this
filter's bins.
"""
@ -1850,7 +1756,6 @@ class EnergyFunctionFilter(Filter):
self.energy = energy
self.y = y
self.id = filter_id
self._stride = None
def __eq__(self, other):
if type(self) is not type(other):
@ -2006,7 +1911,7 @@ class EnergyFunctionFilter(Filter):
"""This function is invalid for EnergyFunctionFilters."""
raise RuntimeError('EnergyFunctionFilters have no get_bin() method')
def get_pandas_dataframe(self, data_size, **kwargs):
def get_pandas_dataframe(self, data_size, stride, **kwargs):
"""Builds a Pandas DataFrame for the Filter's bins.
This method constructs a Pandas DataFrame object for the filter with
@ -2015,8 +1920,10 @@ class EnergyFunctionFilter(Filter):
Parameters
----------
data_size : Integral
data_size : int
The total number of bins in the tally corresponding to this filter
stride : int
Stride in memory for the filter
Returns
-------
@ -2027,11 +1934,6 @@ class EnergyFunctionFilter(Filter):
EnergyFunctionFilters. The number of rows in the DataFrame is the
same as the total number of bins in the corresponding tally.
Raises
------
ImportError
When Pandas is not installed
See also
--------
Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
@ -2052,7 +1954,7 @@ class EnergyFunctionFilter(Filter):
# hex characters) of the digest are probably sufficient.
out = out[:14]
filter_bins = np.repeat(out, self.stride)
filter_bins = np.repeat(out, stride)
tile_factor = data_size // len(filter_bins)
filter_bins = np.tile(filter_bins, tile_factor)
df = pd.concat([df, pd.DataFrame(

View file

@ -2751,7 +2751,6 @@ class TransportXS(MGXS):
# Switch EnergyoutFilter to EnergyFilter.
old_filt = self.tallies['scatter-1'].filters[-1]
new_filt = openmc.EnergyFilter(old_filt.bins)
new_filt.stride = old_filt.stride
self.tallies['scatter-1'].filters[-1] = new_filt
self._rxn_rate_tally = \
@ -2771,7 +2770,6 @@ class TransportXS(MGXS):
# Switch EnergyoutFilter to EnergyFilter.
old_filt = self.tallies['scatter-1'].filters[-1]
new_filt = openmc.EnergyFilter(old_filt.bins)
new_filt.stride = old_filt.stride
self.tallies['scatter-1'].filters[-1] = new_filt
# Compute total cross section

View file

@ -415,9 +415,6 @@ class StatePoint(object):
tally.scores.append(score)
# Compute and set the filter strides
tally._update_filter_strides()
# Add Tally to the global dictionary of all Tallies
tally.sparse = self.sparse
self._tallies[tally_id] = tally

View file

@ -78,6 +78,8 @@ class Tally(IDManagerMixin):
shape : 3-tuple of int
The shape of the tally data array ordered as the number of filter bins,
nuclide bins and score bins
filter_strides : list of int
Stride in memory for each filter
num_realizations : int
Total number of realizations
with_summary : bool
@ -818,10 +820,6 @@ class Tally(IDManagerMixin):
# Differentiate Tally with a new auto-generated Tally ID
merged_tally.id = None
# If the two tallies are equal, simply return copy
if self == other:
return merged_tally
# Create deep copy of other tally to use for array concatenation
other_copy = copy.deepcopy(other)
@ -877,9 +875,6 @@ class Tally(IDManagerMixin):
else:
self._derived = True
# Update filter strides in merged tally
merged_tally._update_filter_strides()
# Concatenate sum arrays if present in both tallies
if self.sum is not None and other_copy.sum is not None:
self_sum = self.get_reshaped_data(value='sum')
@ -1538,11 +1533,10 @@ class Tally(IDManagerMixin):
# Build DataFrame columns for filters if user requested them
if filters:
# Append each Filter's DataFrame to the overall DataFrame
for self_filter in self.filters:
filter_df = self_filter.get_pandas_dataframe(
data_size, paths=paths)
for f, stride in zip(self.filters, self.filter_strides):
filter_df = f.get_pandas_dataframe(
data_size, stride, paths=paths)
df = pd.concat([df, filter_df], axis=1)
# Include DataFrame column for nuclides if user requested it
@ -1867,20 +1861,16 @@ class Tally(IDManagerMixin):
new_score = cross_score(self_score, other_score, binary_op)
new_tally.scores.append(new_score)
# Update the new tally's filter strides
new_tally._update_filter_strides()
return new_tally
def _update_filter_strides(self):
"""Update each filter's stride based on the tally's nuclides and scores
for derived tallies created by tally arithmetic.
"""
@property
def filter_strides(self):
all_strides = []
stride = self.num_nuclides * self.num_scores
for self_filter in reversed(self.filters):
self_filter.stride = stride
all_strides.append(stride)
stride *= self_filter.num_bins
return all_strides[::-1]
def _align_tally_data(self, other, filter_product, nuclide_product,
score_product):
@ -2019,10 +2009,6 @@ class Tally(IDManagerMixin):
if other_index != i:
other._swap_scores(score, other.scores[i])
# Update the tallies' filter strides
other._update_filter_strides()
self._update_filter_strides()
data = {}
data['self'] = {}
data['other'] = {}
@ -2107,9 +2093,6 @@ class Tally(IDManagerMixin):
self.filters[filter1_index] = filter2
self.filters[filter2_index] = filter1
# Update the tally's filter strides
self._update_filter_strides()
# Realign the data
for i, (bin1, bin2) in enumerate(product(filter1_bins, filter2_bins)):
filter_bins = [(bin1,), (bin2,)]
@ -2861,9 +2844,6 @@ class Tally(IDManagerMixin):
find_filter.bins = np.unique(find_filter.bins[bin_indices])
find_filter.num_bins = num_bins
# Update the new tally's filter strides
new_tally._update_filter_strides()
# If original tally was sparse, sparsify the sliced tally
new_tally.sparse = self.sparse
return new_tally
@ -3010,9 +2990,6 @@ class Tally(IDManagerMixin):
else:
tally_sum._scores = copy.deepcopy(self.scores)
# Update the tally sum's filter strides
tally_sum._update_filter_strides()
# Reshape condensed data arrays with one dimension for all filters
mean = np.reshape(mean, tally_sum.shape)
std_dev = np.reshape(std_dev, tally_sum.shape)
@ -3170,9 +3147,6 @@ class Tally(IDManagerMixin):
else:
tally_avg._scores = copy.deepcopy(self.scores)
# Update the tally avg's filter strides
tally_avg._update_filter_strides()
# Reshape condensed data arrays with one dimension for all filters
mean = np.reshape(mean, tally_avg.shape)
std_dev = np.reshape(std_dev, tally_avg.shape)
@ -3246,9 +3220,6 @@ class Tally(IDManagerMixin):
new_tally._std_dev = np.zeros(new_tally.shape, dtype=np.float64)
new_tally._std_dev[diag_indices, :, :] = self.std_dev
# Update the new tally's filter strides
new_tally._update_filter_strides()
# If original tally was sparse, sparsify the diagonalized tally
new_tally.sparse = self.sparse
return new_tally