Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get_errorr update #187

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions sandy/core/endf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ def get_errorr(self,
processing for resonance parameter covariances
(default is 1, 1% sensitivity method)
mt: `int` or iterable of `int`, optional
list of MT reactions to be processed
list of xs MT reactions to be processed

.. note:: this list will be used for all covariance types, i.e.,
MF31, MF33, MF34, MF35.
Expand Down Expand Up @@ -1868,7 +1868,13 @@ def get_errorr(self,
12 /
1.00000e-05 3.00000e-02 5.80000e-02 1.40000e-01 2.80000e-01 3.50000e-01 6.25000e-01 4.00000e+00 4.80520e+01 5.53000e+03 8.21000e+05 2.23100e+06 1.00000e+07 /
3/
3 452 'nu' /
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no test for MT and groupr together

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the method get_gendf: Line 2339
Bad mt selection in _errorr_input: line 761
Bad mt selection in _groupr_input: line 1044

The only missing test is on get_errorr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 2021: Keywords mt and groupr are incompatible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most logical option, in my opinion, is to process all the mt and do the following: a warning saying that the mt will have to be processed by the user or create lines of code at the end that filter the mt

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's just make a test showing the incompatibility and let it be for the moment

3 455 'nu' /
3 456 'nu' /
3 251 'mubar' /
3 252 'xi' /
3 253 'gamma' /
3 259 '1_v' /
5/
5 18 'chi' /
0/
Expand Down Expand Up @@ -2116,7 +2122,7 @@ def get_gendf(self,
mubar : `bool`, optional
Proccess multigroup mubar (default is `False`)
mt: `int` or iterable of `int`, optional
run groupr only for the selected MT numbers
run groupr for xs for the selected MT numbers
nubar : `bool`, optional
Proccess multigroup nubar (default is `False`)
nuclide_production : `bool`, optional
Expand Down Expand Up @@ -2314,7 +2320,54 @@ def get_gendf(self,
12 /
1.00000e-05 3.00000e-02 5.80000e-02 1.40000e-01 2.80000e-01 3.50000e-01 6.25000e-01 4.00000e+00 4.80520e+01 5.53000e+03 8.21000e+05 2.23100e+06 1.00000e+07 /
3/
3 452 'nu' /
3 455 'nu' /
3 456 'nu' /
3 251 'mubar' /
3 252 'xi' /
3 253 'gamma' /
3 259 '1_v' /
5/
5 18 'chi' /
0/
0/
moder
-24 32 /
stop

U-238 for selected mt:
>>> out = endf6.get_gendf(mt=[18, 102], ek_groupr=sandy.energy_grids.CASMO12, verbose=True, err=1, nubar=True, mubar=True, chi=True)
moder
20 -21 /
reconr
-21 -22 /
'sandy runs njoy'/
9237 0 0 /
1 0. /
0/
broadr
-21 -22 -23 /
9237 1 0 0 0. /
1 /
293.6 /
0 /
groupr
-21 -23 0 -24 /
9237 1 0 2 0 1 1 0 /
'sandy runs groupr' /
293.6/
10000000000.0/
12 /
1.00000e-05 3.00000e-02 5.80000e-02 1.40000e-01 2.80000e-01 3.50000e-01 6.25000e-01 4.00000e+00 4.80520e+01 5.53000e+03 8.21000e+05 2.23100e+06 1.00000e+07 /
3 18 /
3 102 /
3 452 'nu' /
3 455 'nu' /
3 456 'nu' /
3 251 'mubar' /
3 252 'xi' /
3 253 'gamma' /
3 259 '1_v' /
5/
5 18 'chi' /
0/
Expand Down
125 changes: 105 additions & 20 deletions sandy/errorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,34 @@ def get_xs(self, **kwargs):
data = pd.concat(data, axis=1).fillna(0)
return sandy.Xs(data)

def get_cov(self, multigroup=True):
def get_cov(self, multigroup=True, mf=None):
"""
Extract cross section/nubar covariance from `Errorr` instance.

Parameters
----------
multigroup : `bool`, optional
Option that allows to show the results in multigroup structure. The
default is True.
mf : `int` or `list`, optional
MF number. The default are the available in the `Errorr` object.

Returns
-------
data : `sandy CategoryCov`
xs/nubar covariance matrix for all cross section/nubar
MAT/MT in ERRORR file.
data : `sandy.CategoryCov` or `dict`
covariance matrix for the selected mf. If more thant one mf is
selected, it returns a `dict` with mf number as key and the
`sandy.CategoryCov` as value.

Notes
-----
..note:: The method reads mf=34 and mf=35 but are not tested.
AitorBengoechea marked this conversation as resolved.
Show resolved Hide resolved

Examples
--------
>>> endf6 = sandy.get_endf6_file("jeff_33", "xs", 10010)
>>> err = endf6.get_errorr(ek_errorr=[1e-2, 1e1, 2e7], err=1)
>>> err.get_cov().data
>>> err.get_cov(mf=33).data
MAT1 125
MT1 1 2 102
E1 (0.01, 10.0] (10.0, 20000000.0] (0.01, 10.0] (10.0, 20000000.0] (0.01, 10.0] (10.0, 20000000.0]
Expand All @@ -157,7 +170,7 @@ def get_cov(self, multigroup=True):
102 (0.01, 10.0] 1.07035e-06 7.58742e-09 0.00000e+00 0.00000e+00 6.51764e-04 3.40163e-04
(10.0, 20000000.0] 5.58627e-07 1.49541e-06 0.00000e+00 0.00000e+00 3.40163e-04 6.70431e-02

>>> err.get_cov(multigroup=False).data
>>> err.get_cov(multigroup=False, mf=33).data
MAT1 125
MT1 1 2 102
E1 1.00000e-02 1.00000e+01 2.00000e+07 1.00000e-02 1.00000e+01 2.00000e+07 1.00000e-02 1.00000e+01 2.00000e+07
Expand All @@ -170,37 +183,110 @@ def get_cov(self, multigroup=True):
2.00000e+07 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
102 1.00000e-02 1.07035e-06 7.58742e-09 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 6.51764e-04 3.40163e-04 0.00000e+00
1.00000e+01 5.58627e-07 1.49541e-06 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 3.40163e-04 6.70431e-02 0.00000e+00
2.00000e+07 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
2.00000e+07 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00

Selected mf:
>>> endf6 = sandy.get_endf6_file('jeff_33','xs', 922350)
>>> out = endf6.get_errorr(err=1, xs=False, mubar=False, chi=False, nubar=True, ek_groupr=[1e-2, 1e1, 2e7], ek_errorr=[1e-2, 1e1, 2e7])
>>> nubar = out.get_cov(mf=[31]).data
>>> nubar
MAT1 9228
MT1 456
E1 (0.01, 10.0] (10.0, 20000000.0]
MAT MT E
9228 456 (0.01, 10.0] 3.15367e-05 1.41334e-05
(10.0, 20000000.0] 1.41334e-05 1.64304e-05

Automatic mf selection:
>>> assert out.get_cov().data.equals(nubar)

mf=[31, 33]:
>>> out = endf6.get_errorr(err=1, xs=True, mubar=False, chi=False, nubar=True, ek_groupr=[1e-2, 1e1, 2e7], ek_errorr=[1e-2, 1e1, 2e7])
>>> cov = out.get_cov()
>>> assert cov[31].data.equals(nubar)
>>> cov[33].data.loc[(9228, 2), (9228, 18)]
E1 (0.01, 10.0] (10.0, 20000000.0]
E
(0.01, 10.0] -4.49435e-05 -2.13654e-08
(10.0, 20000000.0] -4.86857e-10 -2.68869e-05


Test all the mf:
>>> endf6 = sandy.get_endf6_file('jeff_33','xs', 922380)
>>> out = endf6.get_errorr(err=1, ek_groupr=[1e-2, 1e1, 2e7], ek_errorr=[1e-2, 1e1, 2e7])
>>> cov = out.get_cov()
>>> cov.keys()
dict_keys([33, 34, 35, 31])

mt=[452, 455, 456]:
>>> endf6 = sandy.get_endf6_file("jeff_33", "xs", 942410)
>>> out = endf6.get_errorr(err=1, xs=False, mubar=False, chi=False, nubar=True, ek_groupr=[1e-2, 1e1, 2e7], ek_errorr=[1e-2, 1e1, 2e7])
>>> out.get_cov().data
MAT1 9443
MT1 452 455 456
E1 (0.01, 10.0] (10.0, 20000000.0] (0.01, 10.0] (10.0, 20000000.0] (0.01, 10.0] (10.0, 20000000.0]
MAT MT E
9443 452 (0.01, 10.0] 3.14218e-05 3.23619e-06 1.35750e-05 3.39374e-06 3.15192e-05 3.23578e-06
(10.0, 20000000.0] 3.23619e-06 2.75936e-05 1.62044e-06 3.32191e-05 3.24501e-06 2.75789e-05
455 (0.01, 10.0] 1.35750e-05 1.62044e-06 2.50000e-03 6.24999e-04 0.00000e+00 0.00000e+00
(10.0, 20000000.0] 3.39374e-06 3.32191e-05 6.24999e-04 1.28125e-02 0.00000e+00 0.00000e+00
456 (0.01, 10.0] 3.15192e-05 3.24501e-06 0.00000e+00 0.00000e+00 3.16913e-05 3.25345e-06
(10.0, 20000000.0] 3.23578e-06 2.75789e-05 0.00000e+00 0.00000e+00 3.25345e-06 2.76506e-05
"""
eg = self.get_energy_grid()
if multigroup:
eg = pd.IntervalIndex.from_breaks(eg)
data = []
for mat, mf, mt in self.filter_by(listmf=[31, 33]).data:
mf33 = sandy.errorr.read_mf33(self, mat, mt)
for mt1, cov in mf33["COVS"].items():

# Select the mf:
if mf is not None:
listmf_ = [mf] if isinstance(mf, int) else mf
else:
listmf_ = list(self.to_series().index.get_level_values("MF")
.intersection([33, 34, 35]))

data = {mf_: [] for mf_ in listmf_}
# Nubar is in mf=33, so if mf=31 is in the list, mf=33 has to be there
if 31 in listmf_ and 33 not in listmf_:
listmf_.append(33)
listmf_.remove(31)
for mat_, mf_, mt_ in self.filter_by(listmf=listmf_).data:
cov_mf = sandy.errorr.read_cov_mf(self, mat_, mt_, mf_)
for mt1, cov in cov_mf["COVS"].items():
if not multigroup:
# add zero row and column at the end of the matrix
# (this must be done for ERRORR covariance matrices)
cov = np.insert(cov, cov.shape[0], [0]*cov.shape[1], axis=0)
cov = np.insert(cov, cov.shape[1], [0]*cov.shape[0], axis=1)
idx = pd.MultiIndex.from_product(
[[mat], [mt], eg],
[[mat_], [mt_], eg],
names=["MAT", "MT", "E"],
)
idx1 = pd.MultiIndex.from_product(
[[mat], [mt1], eg],
[[mat_], [mt1], eg],
names=["MAT1", "MT1", "E1"],
)
df = pd.DataFrame(cov, index=idx, columns=idx1) \
.stack(level=["MAT1", "MT1", "E1"]) \
.rename("VAL") \
.reset_index()
data.append(df)
data = pd.concat(data)
return sandy.CategoryCov.from_stack(data, index=["MAT", "MT", "E"],
columns=["MAT1", "MT1", "E1"],
values='VAL')
if mt_ == 452 or mt_ == 455 or mt_ == 456:
if 31 in data:
data[31].append(df)
else:
data[31] = [df]
else:
data[mf_].append(df)
cov_dict = {key: sandy.CategoryCov.from_stack(
pd.concat(value),
index=["MAT", "MT", "E"],
columns=["MAT1", "MT1", "E1"],
values='VAL')
for key, value in data.items() if len(value) > 0}

# If only one mf is calculated, the return is directly the `CategoryCov` object
if len(cov_dict) == 1:
[(key, cov_dict)] = cov_dict.items()
return cov_dict


def read_mf1(tape, mat):
Expand Down Expand Up @@ -277,7 +363,7 @@ def read_mf3(tape, mat, mt):
return out


def read_mf33(tape, mat, mt):
def read_cov_mf(tape, mat, mt, mf):
"""
Parse MAT/MF=33/MT section from `sandy.Errorr` object and return
structured content in nested dcitionaries.
Expand All @@ -294,7 +380,6 @@ def read_mf33(tape, mat, mt):
out : `dict`
Content of the ENDF-6 tape structured as nested `dict`.
"""
mf = 33
df = tape._get_section_df(mat, mf, mt)
out = {
"MAT": mat,
Expand Down
Loading