From 09a35ea1cdce15e0a09ed7cf5f6e94c0da95f2b5 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Sun, 4 Dec 2016 16:44:20 -0500 Subject: [PATCH] Remove Tally.export_results() method --- openmc/tallies.py | 140 ---------------------------------------------- 1 file changed, 140 deletions(-) diff --git a/openmc/tallies.py b/openmc/tallies.py index b7d33b13f..8eb654b4a 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -1703,146 +1703,6 @@ class Tally(object): data = np.reshape(data, new_shape) return data - def export_results(self, filename='tally-results', directory='.', - format='hdf5', append=True): - """Exports tallly results to an HDF5 or Python pickle binary file. - - Parameters - ---------- - filename : str - The name of the file for the results (default is 'tally-results') - directory : str - The name of the directory for the results (default is '.') - format : str - The format for the exported file - HDF5 ('hdf5', default) and - Python pickle ('pkl') files are supported - append : bool - Whether or not to append the results to the file (default is True) - - Raises - ------ - KeyError - When this method is called before the Tally is populated with data. - - """ - - # Ensure that the tally has data - if self._sum is None or self._sum_sq is None and not self.derived: - msg = 'The Tally ID="{0}" has no data to export'.format(self.id) - raise KeyError(msg) - - if not isinstance(filename, string_types): - msg = 'Unable to export the results for Tally ID="{0}" to ' \ - 'filename="{1}" since it is not a ' \ - 'string'.format(self.id, filename) - raise ValueError(msg) - - elif not isinstance(directory, string_types): - msg = 'Unable to export the results for Tally ID="{0}" to ' \ - 'directory="{1}" since it is not a ' \ - 'string'.format(self.id, directory) - raise ValueError(msg) - - elif format not in ['hdf5', 'pkl', 'csv']: - msg = 'Unable to export the results for Tally ID="{0}" to format ' \ - '"{1}" since it is not supported'.format(self.id, format) - raise ValueError(msg) - - elif not isinstance(append, bool): - msg = 'Unable to export the results for Tally ID="{0}" since the ' \ - 'append parameter is not True/False'.format(self.id) - raise ValueError(msg) - - # Make directory if it does not exist - if not os.path.exists(directory): - os.makedirs(directory) - - # HDF5 binary file - if format == 'hdf5': - filename = directory + '/' + filename + '.h5' - - if append: - tally_results = h5py.File(filename, 'a') - else: - tally_results = h5py.File(filename, 'w') - - # Create an HDF5 group within the file for this particular Tally - tally_group = tally_results.create_group('Tally-{0}'.format(self.id)) - - # Add basic Tally data to the HDF5 group - tally_group.create_dataset('id', data=self.id) - tally_group.create_dataset('name', data=self.name) - tally_group.create_dataset('estimator', data=self.estimator) - tally_group.create_dataset('scores', data=np.array(self.scores)) - - # Add a string array of the nuclides to the HDF5 group - nuclides = [] - - for nuclide in self.nuclides: - nuclides.append(nuclide.name) - - tally_group.create_dataset('nuclides', data=np.array(nuclides)) - - # Create an HDF5 sub-group for the Filters - filter_group = tally_group.create_group('filters') - - for self_filter in self.filters: - filter_group.create_dataset(self_filter.type, - filter=self_filter.bins) - - # Add all results to the main HDF5 group for the Tally - tally_group.create_dataset('sum', data=self.sum) - tally_group.create_dataset('sum_sq', data=self.sum_sq) - tally_group.create_dataset('mean', data=self.mean) - tally_group.create_dataset('std_dev', data=self.std_dev) - - # Close the Tally results HDF5 file - tally_results.close() - - # Python pickle binary file - elif format == 'pkl': - # Load the dictionary from the Pickle file - filename = directory + '/' + filename + '.pkl' - - if os.path.exists(filename) and append: - tally_results = pickle.load(open(filename, 'rb')) - else: - tally_results = {} - - # Create a nested dictionary within the file for this particular Tally - tally_results['Tally-{0}'.format(self.id)] = {} - tally_group = tally_results['Tally-{0}'.format(self.id)] - - # Add basic Tally data to the nested dictionary - tally_group['id'] = self.id - tally_group['name'] = self.name - tally_group['estimator'] = self.estimator - tally_group['scores'] = np.array(self.scores) - - # Add a string array of the nuclides to the HDF5 group - nuclides = [] - - for nuclide in self.nuclides: - nuclides.append(nuclide.name) - - tally_group['nuclides'] = np.array(nuclides) - - # Create a nested dictionary for the Filters - tally_group['filters'] = {} - filter_group = tally_group['filters'] - - for self_filter in self.filters: - filter_group[self_filter.type] = self_filter.bins - - # Add all results to the main sub-dictionary for the Tally - tally_group['sum'] = self.sum - tally_group['sum_sq'] = self.sum_sq - tally_group['mean'] = self.mean - tally_group['std_dev'] = self.std_dev - - # Pickle the Tally results to a file - pickle.dump(tally_results, open(filename, 'wb')) - def hybrid_product(self, other, binary_op, filter_product=None, nuclide_product=None, score_product=None): """Combines filters, scores and nuclides with another tally.