From 036535361e769c899bb2e2d94cd83b946c48c852 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Fri, 29 May 2015 07:57:19 -0700 Subject: [PATCH] Now throw exception when requesting Summary info in Pandas DF without calling StatePoint.link_with_summary(...) --- src/utils/openmc/statepoint.py | 3 ++- src/utils/openmc/tallies.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/utils/openmc/statepoint.py b/src/utils/openmc/statepoint.py index 74b3554b3d..b4e49987cb 100644 --- a/src/utils/openmc/statepoint.py +++ b/src/utils/openmc/statepoint.py @@ -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 diff --git a/src/utils/openmc/tallies.py b/src/utils/openmc/tallies.py index b11fabba2e..1fbada0467 100644 --- a/src/utils/openmc/tallies.py +++ b/src/utils/openmc/tallies.py @@ -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 ' \