Now throw exception when requesting Summary info in Pandas DF without calling StatePoint.link_with_summary(...)

This commit is contained in:
Will Boyd 2015-05-29 07:57:19 -07:00
parent 7b8da9c7e2
commit 036535361e
2 changed files with 30 additions and 1 deletions

View file

@ -691,6 +691,7 @@ class StatePoint(object):
# Get the Tally name from the summary file
tally.name = summary.tallies[tally_id].name
tally.with_summary = True
nuclide_zaids = copy.deepcopy(tally.nuclides)
@ -727,7 +728,7 @@ class StatePoint(object):
for bin in filter.bins:
material_ids.append(summary.materials[bin].id)
filter.bins = material_ids
self._with_summary = True

View file

@ -35,6 +35,7 @@ class Tally(object):
self._num_score_bins = 0
self._num_realizations = 0
self._with_summary = False
self._sum = None
self._sum_sq = None
@ -224,6 +225,11 @@ class Tally(object):
return self._num_realizations
@property
def with_summary(self):
return self._with_summary
@property
def sum(self):
return self._sum
@ -352,6 +358,17 @@ class Tally(object):
self._num_realizations = num_realizations
@with_summary.setter
def with_summary(self, with_summary):
if not is_bool(with_summary):
msg = 'Unable to set with_summary to a non-boolean ' \
'value "{0}"'.format(with_summary)
raise ValueError(msg)
self._with_summary = with_summary
def set_results(self, sum, sum_sq):
if not isinstance(sum, (tuple, list, np.ndarray)):
@ -731,6 +748,7 @@ class Tally(object):
is populated with data by the StatePoint.read_results() routine.
"""
# Ensure that StatePoint.read_results() was called first
if not (self._sum and self._sum_sq):
msg = 'The Tally ID={0} has no data to return. Call the ' \
'StatePoint.read_results() routine before using ' \
@ -879,12 +897,21 @@ class Tally(object):
is populated with data by the StatePoint.read_results() routine.
"""
# Ensure that StatePoint.read_results() was called first
if not (self._sum and self._sum_sq):
msg = 'The Tally ID={0} has no data to return. Call the ' \
'StatePoint.read_results() routine before using ' \
'Tally.get_pandas_dataframe(...)'.format(self.id)
raise KeyError(msg)
# If using Summary, ensure StatePoint.link_with_summary(...) was called
if summary and not self.with_summary:
msg = 'The Tally ID={0} has not been linked with the Summary. ' \
'Call the StatePoint.link_with_summary(...) routine ' \
'before using Tally.get_pandas_dataframe(...) with ' \
'Summary info'.format(self.id)
raise KeyError(msg)
# Attempt to import the pandas package
try:
import pandas as pd
@ -1169,6 +1196,7 @@ class Tally(object):
is populated with data by the StatePoint.read_results() routine.
"""
# Ensure that StatePoint.read_results() was called first
if not (self._sum and self._sum_sq):
msg = 'The Tally ID={0} has no data to export. Call the ' \
'StatePoint.read_results() routine before using ' \