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

Sampling using njoy #22

Merged
merged 23 commits into from
May 13, 2019
Prev Previous commit
Next Next commit
update
  • Loading branch information
Luca Fiorito committed Apr 17, 2019
commit 1adeac0b07512673659949a3b5c1c3d5d96a400d
4 changes: 3 additions & 1 deletion sandy/__init__.py
Original file line number Diff line number Diff line change
@@ -29,4 +29,6 @@ def filter(self, record):
logging.basicConfig(format=FORMAT)
logging.getLogger().setLevel(logging.INFO)
logging.getLogger().addHandler(ShutdownHandler(level=40))
#logging.getLogger().addFilter(DuplicateFilter())
#logging.getLogger().addFilter(DuplicateFilter())

__version__ = '0.9.0'
2 changes: 1 addition & 1 deletion sandy/formats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .endf6 import *
from .errorr import *
# from .errorr import *
from .groupr import *
from .utils import *
from .records import *
37 changes: 37 additions & 0 deletions sandy/formats/endf6.py
Original file line number Diff line number Diff line change
@@ -241,6 +241,30 @@ def mf(self):
@property
def mt(self):
return sorted(self.index.get_level_values("MT").unique())

def get_type(self):
"""Determine ENDF-6 format type by reading flag "LRP" of first MAT in file:

* `LRP = 1` : endf6
* `LRP = 2` : pendf
* `LRP = -11 | LRP = -12` : errorr
* `LRP = -1` : gendf

Returns
-------
`str`
type of ENDF-6 format
"""
lrp = self.read_section(self.mat[0], 1, 451)["LRP"]
if lrp == 2:
ftype = "pendf"
elif lrp == -11 or lrp == -12:
ftype = "errorr"
elif lrp == -1:
ftype = "gendf"
else:
ftype = "endf6"
return ftype



@@ -261,6 +285,19 @@ class Endf6(_BaseFile):
-------
"""

def get_nsub(self):
"""Determine ENDF-6 sub-library type by reading flag "NSUB" of first MAT in file:

* `NSUB = 10` : Incident-Neutron Data
* `NSUB = 11` : Neutron-Induced Fission Product Yields

Returns
-------
`int`
NSUB value
"""
return self.read_section(self.mat[0], 1, 451)["NSUB"]

def read_section(self, mat, mf, mt):
"""Parse MAT/MF/MT section.
"""
6 changes: 3 additions & 3 deletions sandy/formats/mf1.py
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ def read_errorr(text):
out = {"MAT" : MAT, "MF" : MF, "MT" : MT}
i = 0
C, i = read_cont(str_list, i)
out.update({"ZA" : C.C1, "AWR" : C.C2, "ERRFLAG" :C.N1})
out.update({"ZA" : C.C1, "AWR" : C.C2, "LRP" :C.N1})
L, i = read_list(str_list, i)
out.update({"EG" : L.B})
return out
@@ -44,7 +44,7 @@ def read_groupr(text):
out = {"MAT" : MAT, "MF" : MF, "MT" : MT}
i = 0
C, i = read_cont(str_list, i)
out.update({"ZA" : C.C1, "AWR" : C.C2, "NZ" : C.L2, "GROUPRFLAG" : C.N1, "NTW" : C.N2})
out.update({"ZA" : C.C1, "AWR" : C.C2, "NZ" : C.L2, "LRP" : C.N1, "NTW" : C.N2})
L, i = read_list(str_list, i)
out.update({"TEMPIN" : L.C1, "NGN" : L.L1, "NGG" : L.L2})
out["TITLE"] = L.B[:out["NTW"]]; del L.B[:out["NTW"]]
@@ -77,7 +77,7 @@ def read_info(text):
TEXT.append(T)
out.update({ "TEXT" : TEXT })
# This part is not given in PENDF files
if out["LRP"] != 2:
if out["LRP"] != 2 and len(TEXT) > 0:
# groups = TEXT[0][:11].split("-")
# out["Z"] = int(groups[0])
# out["SYM"] = groups[1].strip()
2 changes: 1 addition & 1 deletion sandy/formats/utils.py
Original file line number Diff line number Diff line change
@@ -953,7 +953,7 @@ def get_samples(self, nsmp, eig=0, seed=None):
cov = self.to_matrix()
frame = pd.DataFrame(cov.sampling(nsmp, seed=seed) + 1, index=self.index, columns=range(1,nsmp+1))
frame.columns.name = 'SMP'
if eig > 0:
if eig > 0 and nsmp > 1:
eigs = cov.eig()[0]
idxs = np.abs(eigs).argsort()[::-1]
dim = min(len(eigs), eig)
Loading