Skip to content

Commit

Permalink
q matrix and b matrix update
Browse files Browse the repository at this point in the history
  • Loading branch information
Bengoechea Aitor authored and Bengoechea Aitor committed Oct 20, 2021
1 parent 0e0ad84 commit 6a45cce
Show file tree
Hide file tree
Showing 3 changed files with 2,343 additions and 52 deletions.
71 changes: 62 additions & 9 deletions sandy/core/endf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
URL_NFPY_JENDL_40U_IAEA,
NFPY_FILES_JENDL_40U_IAEA,
URL_NFPY_JEFF_33_IAEA,
URL_NFPY_JEFF_33_IAEA_ALL,
NFPY_FILES_JEFF_33_IAEA,
URL_DECAY_ENDFB_71_IAEA,
DECAY_FILES_ENDFB_71_IAEA,
URL_DECAY_ENDFB_80_IAEA,
DECAY_FILES_ENDFB_80_IAEA,
URL_DECAY_JEFF_33_IAEA,
DECAY_FILES_JEFF_33_IAEA,
URL_DECAY_JEFF_33_IAEA_ALL,
)


Expand Down Expand Up @@ -87,12 +89,17 @@ def get_endf6_file(library, kind, zam, to_file=False):
* 'nfpy' is a Neutron-Induced Fission Product Yields nuclear data
file
* 'decay' is a Radioactive Decay Data nuclear data file
zam : `int`
ZAM nuclide identifier $Z \\times 10000 + A \\times 10 + M$ where:
* $Z$ is the charge number
* $A$ is the mass number
* $M$ is the metastate level (0=ground, 1=1st level)
zam : `int` or 'all'
zam = 'int' (individual nuclides)
ZAM nuclide identifier $Z \\times 10000 + A \\times 10 + M$ where:
* $Z$ is the charge number
* $A$ is the mass number
* $M$ is the metastate level (0=ground, 1=1st level)
zam = 'all'
We obtain the information of all the library. Actually,
the only all libraries available are:
* for 'nfpy': 'jeff_33'
* for 'decay': 'jeff_33'
Raises
------
ValueError
Expand Down Expand Up @@ -153,8 +160,16 @@ def get_endf6_file(library, kind, zam, to_file=False):
Import Radioactive Decay Data for H-1 from ENDF/B-VIII.0.
>>> tape = sandy.get_endf6_file("endfb_80", 'decay', 10010)
>>> assert type(tape) is sandy.Endf6
Import all Radioactive Decay Data from JEFF-3.3
>>> tape = sandy.get_endf6_file("jeff_33", 'decay', 'all')
>>> assert type(tape) is sandy.Endf6
Import all Neutron-Induced Fission Product Yields from JEFF-3.3
>>> tape = sandy.get_endf6_file("jeff_33", 'nfpy', 'all')
>>> assert type(tape) is sandy.Endf6
"""
if kind == 'xs':
if kind == 'xs' and type(zam) == int:
available_libs = (
"jeff_32".upper(),
"jeff_33".upper(),
Expand Down Expand Up @@ -188,7 +203,7 @@ def get_endf6_file(library, kind, zam, to_file=False):
Available libraries are: {available_libs}
"""
)
elif kind == 'nfpy':
elif kind == 'nfpy' and type(zam) == int:
available_libs = (
"endfb_71".upper(),
"endfb_80".upper(),
Expand All @@ -214,7 +229,22 @@ def get_endf6_file(library, kind, zam, to_file=False):
Available libraries are: {available_libs}
"""
)
elif kind == 'decay':
elif kind == 'nfpy' and zam == 'all':
available_libs = (
"jeff_33".upper(),
)
library_ = library.lower()
if library_ == "jeff_33":
filename = URL_NFPY_JEFF_33_IAEA_ALL
tape = Endf6.from_url_all(filename)
else:
raise ValueError(
f"""library '{library}' is not available.
Available libraries are: {available_libs}
"""
)

elif kind == 'decay' and type(zam) == int:
available_libs = (
"endfb_71".upper(),
"endfb_80".upper(),
Expand All @@ -236,6 +266,20 @@ def get_endf6_file(library, kind, zam, to_file=False):
Available libraries are: {available_libs}
"""
)
elif kind == 'decay' and zam == 'all':
available_libs = (
"jeff_33".upper(),
)
library_ = library.lower()
if library_ == "jeff_33":
filename = URL_DECAY_JEFF_33_IAEA_ALL
tape = Endf6.from_url_all(filename)
else:
raise ValueError(
f"""library '{library}' is not available.
Available libraries are: {available_libs}
"""
)
if to_file:
basename = sandy.zam.zam2nuclide(zam, atomic_number=True, sep="-")
filename = f"{basename}.{library_}"
Expand Down Expand Up @@ -384,6 +428,15 @@ def kind(self):
kind == "unkwown"
return kind

@classmethod
def from_url_all(cls, url):
# set a known browser user agent to ensure access
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'},)
with urlopen(req) as f:
text = f.read().decode('utf-8')
tape = cls.from_text(text)
return tape

@classmethod
def from_url(cls, filename, rooturl):
url = f"{rooturl}/{filename}"
Expand Down
81 changes: 38 additions & 43 deletions sandy/decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,26 +202,21 @@ def get_bmatrix(self, **kwargs):
270600 0.00000e+00 0.00000e+00 0.00000e+00
280600 0.00000e+00 1.00000e+00 0.00000e+00
>>> import urllib
>>> import pandas as pd
>>> url = "https://www.oecd-nea.org/dbdata/jeff/jeff33/downloads/JEFF33-rdd_all.asc"
>>> with urllib.request.urlopen(url) as f: text_fy = f.read().decode('utf-8')
>>> tape = sandy.Endf6.from_text(text_fy)
>>> information = sandy.DecayData.from_endf6(tape)
>>> b_matrix_total = information.get_bmatrix()
>>> index_pd = pd.Index([551480,551490,561480,561490,571480,571490,581480,591480,591481,601480])
>>> b_matrix_total.loc[index_pd, index_pd]
551480 551490 561480 561490 571480 571490 581480 591480 591481 601480
551480 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 0.00000e+00
551490 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 0.00000e+00
561480 7.49000e-01 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
561490 0.00000e+00 1.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
571480 0.00000e+00 0.00000e+00 9.96000e-01 4.30000e-03 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
571490 0.00000e+00 0.00000e+00 0.00000e+00 9.95700e-01 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
581480 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 1.00000e+00 1.40000e-02 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
591480 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
591481 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 0.00000e+00
601480 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 1.00000e+00 1.00000e+00 0.00000e+00
>>> h1 = sandy.endf6.get_endf6_file("endfb_71","decay",551480)
>>> h2 = sandy.endf6.get_endf6_file("endfb_71","decay",551490)
>>> h3 = h1.merge(h2)
>>> rdd = sandy.DecayData.from_endf6(h3)
>>> rdd.get_bmatrix()
PARENT 10 551480 551490 561460 561470 561480 561490
DAUGHTER
10 0.00000e+00 2.18793e-01 6.88450e-01 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
551480 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
551490 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
561460 0.00000e+00 1.72560e-04 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
561470 0.00000e+00 2.18447e-01 4.09780e-07 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
561480 0.00000e+00 7.81380e-01 6.88450e-01 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
561490 0.00000e+00 0.00000e+00 3.11550e-01 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
"""
B = self.get_decay_chains(**kwargs) \
.pivot_table(
Expand All @@ -233,14 +228,20 @@ def get_bmatrix(self, **kwargs):
)\
.astype(float)\
.fillna(0)
data_endf6 = B.reindex(B.index.values, fill_value=0.0, axis=1)
np.fill_diagonal(data_endf6.values, 0)
return data_endf6
B_reindex = B.reindex(B.index.values, fill_value=0.0, axis=1)
np.fill_diagonal(B_reindex.values, 0)
return B_reindex

def get_qmatrix(self, keep_neutrons=False, threshold=None, **kwargs):
"""
Extract Q-matrix dataframe.
Optional argument
-------
Thereshold: 'int'
Optional argument to avoid numerical fluctuations or
values so small that they do not have to be taken into
account.
Returns
-------
`pandas.DataFrame`
Expand All @@ -260,26 +261,20 @@ def get_qmatrix(self, keep_neutrons=False, threshold=None, **kwargs):
>>> comp.columns.name = "PARENT"
>>> pd.testing.assert_frame_equal(comp, out)
>>> import urllib
>>> import pandas as pd
>>> url = "https://www.oecd-nea.org/dbdata/jeff/jeff33/downloads/JEFF33-rdd_all.asc"
>>> with urllib.request.urlopen(url) as f: text_fy = f.read().decode('utf-8')
>>> tape = sandy.Endf6.from_text(text_fy)
>>> information = sandy.DecayData.from_endf6(tape)
>>> index_pd = pd.Index([551480,551490,561480,561490,571480,571490,581480,591480,591481,601480])
>>> q_matrix = information.get_qmatrix()
>>> q_matrix.loc[601480, index_pd]
551480 7.46004e-01
551490 1.82398e-02
561480 9.96000e-01
561490 1.82398e-02
571480 1.00000e+00
571490 1.40000e-02
581480 1.00000e+00
591480 1.00000e+00
591481 1.00000e+00
601480 1.00000e+00
Name: 601480, dtype: float64
>>> h1 = sandy.endf6.get_endf6_file("endfb_71","decay",551480)
>>> h2 = sandy.endf6.get_endf6_file("endfb_71","decay",551490)
>>> h3 = h1.merge(h2)
>>> rdd = sandy.DecayData.from_endf6(h3)
>>> rdd.get_qmatrix()
PARENT 551480 551490 561460 561470 561480 561490
DAUGHTER
551480 1.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
551490 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
561460 1.72560e-04 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
561470 2.18447e-01 4.09780e-07 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
561480 7.81380e-01 6.88450e-01 0.00000e+00 0.00000e+00 1.00000e+00 0.00000e+00
561490 0.00000e+00 3.11550e-01 0.00000e+00 0.00000e+00 0.00000e+00 1.00000e+00
"""
B = self.get_bmatrix(**kwargs)
if not keep_neutrons:
Expand Down

0 comments on commit 6a45cce

Please sign in to comment.