Test passes after modifying get_pandas_dataframe

Since the inherted get_pandas_dataframe sorted values by x, y, z, and the current has a different labelling system
(doesn't include z if only 2 dimensional, and then also includes x-in, x-out, y-in, y-out, z-in z-out...)
I had to redefine get_pandas_dataframe in the SurfaceMGXS class and remove the sorting.
This commit is contained in:
Miriam 2020-07-19 14:00:21 +00:00
parent 676bcefb1e
commit 1c7e7fe3f1
2 changed files with 131 additions and 1 deletions

View file

@ -1964,7 +1964,6 @@ class MGXS:
# energy groups such that data is from fast to thermal
if self.domain_type == 'mesh':
mesh_str = 'mesh {0}'.format(self.domain.id)
print("HELLO WORLD", mesh_str)
df.sort_values(by=[(mesh_str, 'x'), (mesh_str, 'y'),
(mesh_str, 'z')] + columns, inplace=True)
else:
@ -6187,6 +6186,103 @@ class SurfaceMGXS(MGXS):
return xs
def get_pandas_dataframe(self, groups='all', nuclides='all',
xs_type='macro', paths=True):
"""Build a Pandas DataFrame for the MGXS data.
This method leverages :meth:`openmc.Tally.get_pandas_dataframe`, but
renames the columns with terminology appropriate for cross section data.
Parameters
----------
groups : Iterable of Integral or 'all'
Energy groups of interest. Defaults to 'all'.
nuclides : Iterable of str or 'all' or 'sum'
The nuclides of the cross-sections to include in the dataframe. This
may be a list of nuclide name strings (e.g., ['U235', 'U238']).
The special string 'all' will include the cross sections for all
nuclides in the spatial domain. The special string 'sum' will
include the cross sections summed over all nuclides. Defaults
to 'all'.
xs_type: {'macro', 'micro'}
Return macro or micro cross section in units of cm^-1 or barns.
Defaults to 'macro'.
paths : bool, optional
Construct columns for distribcell tally filters (default is True).
The geometric information in the Summary object is embedded into
a Multi-index column with a geometric "path" to each distribcell
instance.
Returns
-------
pandas.DataFrame
A Pandas DataFrame for the cross section data.
Raises
------
ValueError
When this method is called before the multi-group cross section is
computed from tally data.
"""
if not isinstance(groups, str):
cv.check_iterable_type('groups', groups, Integral)
if nuclides != 'all' and nuclides != 'sum':
cv.check_iterable_type('nuclides', nuclides, str)
cv.check_value('xs_type', xs_type, ['macro', 'micro'])
# Get a Pandas DataFrame from the derived xs tally
if self.by_nuclide and nuclides == 'sum':
# Use tally summation to sum across all nuclides
xs_tally = self.xs_tally.summation(nuclides=self.get_nuclides())
df = xs_tally.get_pandas_dataframe(paths=paths)
# Remove nuclide column since it is homogeneous and redundant
if self.domain_type == 'mesh':
df.drop('sum(nuclide)', axis=1, level=0, inplace=True)
else:
df.drop('sum(nuclide)', axis=1, inplace=True)
# If the user requested a specific set of nuclides
elif self.by_nuclide and nuclides != 'all':
xs_tally = self.xs_tally.get_slice(nuclides=nuclides)
df = xs_tally.get_pandas_dataframe(paths=paths)
# If the user requested all nuclides, keep nuclide column in dataframe
else:
df = self.xs_tally.get_pandas_dataframe(paths=paths)
# Remove the score column since it is homogeneous and redundant
if self.domain_type == 'mesh':
df = df.drop('score', axis=1, level=0)
else:
df = df.drop('score', axis=1)
# Convert azimuthal, polar, energy in and energy out bin values in to
# bin indices
columns = self._df_convert_columns_to_bins(df)
# Select out those groups the user requested
if not isinstance(groups, str):
if 'group in' in df:
df = df[df['group in'].isin(groups)]
if 'group out' in df:
df = df[df['group out'].isin(groups)]
# If user requested micro cross sections, divide out the atom densities
if xs_type == 'micro' and self._divide_by_density:
if self.by_nuclide:
densities = self.get_nuclide_densities(nuclides)
else:
densities = self.get_nuclide_densities('sum')
densities = np.repeat(densities, len(self.rxn_rate_tally.scores))
tile_factor = int(df.shape[0] / len(densities))
df['mean'] /= np.tile(densities, tile_factor)
df['std. dev.'] /= np.tile(densities, tile_factor)
# Replace NaNs by zeros (happens if nuclide density is zero)
df['mean'].replace(np.nan, 0.0, inplace=True)
df['std. dev.'].replace(np.nan, 0.0, inplace=True)
return df
class Current(SurfaceMGXS):
r"""A current multi-group cross section.

View file

@ -178,6 +178,40 @@
2 1 2 1 1 1 total 0.032188 0.002420
1 2 1 1 1 1 total 0.032304 0.002073
3 2 2 1 1 1 total 0.031336 0.001614
mesh 1 group in nuclide mean std. dev.
x y surf
0 1 1 x-min out 1 total 0.0000 0.000000
1 1 1 x-min in 1 total 0.0000 0.000000
2 1 1 x-max out 1 total 0.2738 0.093735
3 1 1 x-max in 1 total 0.1892 0.011302
4 1 1 y-min out 1 total 0.0000 0.000000
5 1 1 y-min in 1 total 0.0000 0.000000
6 1 1 y-max out 1 total 0.2358 0.041204
7 1 1 y-max in 1 total 0.1724 0.009114
8 2 1 x-min out 1 total 0.1892 0.011302
9 2 1 x-min in 1 total 0.2738 0.093735
10 2 1 x-max out 1 total 0.0000 0.000000
11 2 1 x-max in 1 total 0.0000 0.000000
12 2 1 y-min out 1 total 0.0000 0.000000
13 2 1 y-min in 1 total 0.0000 0.000000
14 2 1 y-max out 1 total 0.2290 0.038756
15 2 1 y-max in 1 total 0.1894 0.012331
16 1 2 x-min out 1 total 0.0000 0.000000
17 1 2 x-min in 1 total 0.0000 0.000000
18 1 2 x-max out 1 total 0.1778 0.010514
19 1 2 x-max in 1 total 0.1822 0.011922
20 1 2 y-min out 1 total 0.1724 0.009114
21 1 2 y-min in 1 total 0.2358 0.041204
22 1 2 y-max out 1 total 0.0000 0.000000
23 1 2 y-max in 1 total 0.0000 0.000000
24 2 2 x-min out 1 total 0.1822 0.011922
25 2 2 x-min in 1 total 0.1778 0.010514
26 2 2 x-max out 1 total 0.0244 0.024400
27 2 2 x-max in 1 total 0.0000 0.000000
28 2 2 y-min out 1 total 0.1894 0.012331
29 2 2 y-min in 1 total 0.2290 0.038756
30 2 2 y-max out 1 total 0.0236 0.023600
31 2 2 y-max in 1 total 0.0000 0.000000
mesh 1 delayedgroup group in nuclide mean std. dev.
x y z
0 1 1 1 1 1 total 0.000007 4.734745e-07