Skip to content

Commit 410e893

Browse files
committed
Add five tests for endf.Evaluation functionality
1 parent 6826a21 commit 410e893

File tree

1 file changed

+222
-57
lines changed

1 file changed

+222
-57
lines changed

tests/test_endf.py

Lines changed: 222 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import os
22
import io
33
import warnings
4-
try:
5-
from StringIO import StringIO
6-
except ImportError:
7-
from io import StringIO
84
from math import e
5+
from hashlib import md5
96

107
import numpy as np
118
from numpy.testing import assert_array_equal, assert_allclose, \
@@ -14,7 +11,7 @@
1411
from pyne.utils import QAWarning
1512
warnings.simplefilter("ignore", QAWarning)
1613

17-
from pyne.endf import Library
14+
from pyne.endf import Library, Evaluation
1815
from pyne.utils import endftod
1916
from pyne.rxdata import DoubleSpinDict
2017
from pyne.xs.data_source import ENDFDataSource
@@ -52,6 +49,25 @@ def array_from_ENDF(fh):
5249
3: endftod, 4: endftod, 5: endftod})
5350

5451

52+
def download_file(url, localfile, md5_hash):
53+
"""Donwload a file and make sure its MD5 hash matches."""
54+
try:
55+
assert(os.path.isfile(localfile))
56+
except AssertionError:
57+
try:
58+
import urllib.request as urllib
59+
except ImportError:
60+
import urllib
61+
urllib.urlretrieve(url, localfile)
62+
with open(localfile, "rb") as f:
63+
obs_hash = md5(f.read()).hexdigest()
64+
try:
65+
assert_equal(obs_hash, md5_hash)
66+
except AssertionError:
67+
raise AssertionError("{} hash check failed; please try redownloading "
68+
"the U235 data file.".format(localfile))
69+
70+
5571
def test_endftod():
5672
from pyne._utils import endftod
5773
obs = [endftod(" 3.28559+12"),
@@ -79,23 +95,8 @@ def test_endftod():
7995
assert_allclose(obs, exp, rtol = 1e-8)
8096

8197
def test_loadtape():
82-
try:
83-
assert(os.path.isfile('endftape.100'))
84-
except AssertionError:
85-
try:
86-
import urllib.request as urllib
87-
except ImportError:
88-
import urllib
89-
urllib.urlretrieve("http://www.nndc.bnl.gov/endf/b6.8/tapes/tape.100",
90-
"endftape.100")
91-
from hashlib import md5
92-
with open("endftape.100", "rb") as f:
93-
obs_hash = md5(f.read()).hexdigest()
94-
exp_hash = "b56dd0aee38bd006c58181e473232776"
95-
try:
96-
assert_equal(obs_hash, exp_hash)
97-
except AssertionError:
98-
raise AssertionError("endftape.100 hash check failed; please try redownloading the endftape.100 data file.")
98+
download_file("http://www.nndc.bnl.gov/endf/b6.8/tapes/tape.100",
99+
"endftape.100", "b56dd0aee38bd006c58181e473232776")
99100
testlib = Library("endftape.100")
100101
exp_nuclides = [10010000, 30060000, 40090000, 50110000, 30070000, 60000000, 50100000]
101102
obs_nuclides = list(map(int, testlib.structure.keys()))
@@ -303,14 +304,14 @@ def test_resolved_r_matrix_kbk_kps():
303304
0.000000+0 0.000000+0 0 0 1 1
304305
0.000000+0 0.000000+0 0.000000+0 0.000000+0 0.000000+0 0.000000+0
305306
0.000000+0 0.000000+0 0 0 1 3
306-
3 2
307+
3 2
307308
4.016335+2 2.076736-3 4.668090-5 9.776415+2-3.940740+2-2.296483+8
308309
0.000000+0 0.000000+0 0 0 3 10
309310
3 1 6 2 10 3
310311
-4.803282+6-1.114539-5 9.465304+2-1.436769-9 7.889727+2 4.824983+9
311312
4.020763+6 2.308443-6-4.188441-2 1.778263+8-3.408683+7 2.845463+7
312313
3.371147+1 2.054714+3-2.746606-3-9.635977-6-1.387257-2 7.042637+0
313-
6.917628+9-2.912896-7
314+
6.917628+9-2.912896-7
314315
"""))
315316

316317

@@ -355,9 +356,9 @@ def test_resolved_r_matrix_kbk_kps():
355356
0.000000+0 0.000000+0 0.000000+0 0.000000+0 0.000000+0 0.000000+0
356357
0.000000+0 0.000000+0 0 0 4 5
357358
1 2 2 1 3 3
358-
5 4
359+
5 4
359360
0.000000+0 0.000000+0 0 0 2 6
360-
4 1 6 2
361+
4 1 6 2
361362
1.960831+3-1.053619+4 0 0 2 1
362363
1.298772+5-2.834965+3 8.381641-6 3.338353+5-1.012675-7 0.000000+0
363364
"""))
@@ -498,25 +499,10 @@ def test_isomeric():
498499
library._read_res(nuc61148m)
499500
assert (library.structure[nuc61148m]['matflags']['LIS0'] == 1)
500501
assert (nuc61148m in library.structure)
501-
502+
502503
def test_u235():
503-
try:
504-
assert(os.path.isfile('U235.txt'))
505-
except AssertionError:
506-
try:
507-
import urllib.request as urllib
508-
except ImportError:
509-
import urllib
510-
urllib.urlretrieve("http://t2.lanl.gov/nis/data/data/ENDFB-VII.1-neutron/U/235",
511-
"U235.txt")
512-
from hashlib import md5
513-
with open("U235.txt", "rb") as f:
514-
obs_hash = md5(f.read()).hexdigest()
515-
exp_hash = "1b71da3769d8b1e675c3c579ba5cb2d3"
516-
try:
517-
assert_equal(obs_hash, exp_hash)
518-
except AssertionError:
519-
raise AssertionError("U235.txt hash check failed; please try redownloading the U235 data file.")
504+
download_file("http://t2.lanl.gov/nis/data/data/ENDFB-VII.1-neutron/U/235",
505+
"U235.txt", "1b71da3769d8b1e675c3c579ba5cb2d3")
520506

521507
u235 = Library('U235.txt')
522508
nuc = 922350000
@@ -525,7 +511,7 @@ def test_u235():
525511
exp_a = array_from_ENDF(io.BytesIO
526512
(b""" 9.223500+4 2.330248+2 0 0 0 0
527513
-1.788560+7-1.788560+7 0 0 1 6
528-
6 2
514+
6 2
529515
1.796240+7 5.05980-10 1.800000+7 3.810030-7 1.850000+7 8.441785-5
530516
1.900000+7 2.387410-4 1.950000+7 1.348763-3 2.000000+7 4.785594-3
531517
"""))
@@ -670,7 +656,7 @@ def test_discretize():
670656
import urllib.request as urllib
671657
except ImportError:
672658
import urllib
673-
659+
674660
if not isfile("Ni59.txt"):
675661
urllib.urlretrieve("http://t2.lanl.gov/nis/data/data/ENDFB-VII.1-neutron/Ni/59",
676662
"Ni59.txt")
@@ -694,30 +680,209 @@ def test_discretize():
694680

695681

696682
def test_photoatomic():
697-
try:
698-
assert(os.path.isfile('Zn.txt'))
699-
except AssertionError:
700-
try:
701-
import urllib.request as urllib
702-
except ImportError:
703-
import urllib
704-
urllib.urlretrieve("https://www-nds.iaea.org/fendl30/data/atom/endf/ph_3000_30-Zn.txt",
705-
"Zn.txt")
683+
download_file("https://www-nds.iaea.org/fendl30/data/atom/endf/ph_3000_30-Zn.txt",
684+
"Zn.txt", 'e6bda2fe6125ad9a8d51a6405ae9cc2a')
706685
photondata = Library('Zn.txt')
707686
xs_data = photondata.get_xs(300000000, 501)[0]
708687
Eints, sigmas = xs_data['e_int'], xs_data['xs']
709688
assert_equal(len(Eints),1864)
710689
assert_equal(len(sigmas),1864)
711690
assert_array_equal(Eints[0:5],[1., 1.109887, 1.217224,
712691
1.2589, 1.334942])
713-
assert_array_equal(Eints[-5:],[6.30960000e+10, 7.94328000e+10,
714-
7.94330000e+10, 8.00000000e+10,
692+
assert_array_equal(Eints[-5:],[6.30960000e+10, 7.94328000e+10,
693+
7.94330000e+10, 8.00000000e+10,
715694
1.00000000e+11])
716695
assert_array_almost_equal(sigmas[0:5],[0.00460498, 0.00710582,
717696
0.01047864, 0.01210534,
718697
0.01556538])
719698
assert_array_almost_equal(sigmas[-5:],[ 6.71525 , 6.716781, 6.716781,
720699
6.716829, 6.717811])
721700

701+
702+
def test_evaluation_neutron():
703+
download_file('http://t2.lanl.gov/nis/data/data/ENDFB-VII.1-neutron/U/235',
704+
'U235.txt', "1b71da3769d8b1e675c3c579ba5cb2d3")
705+
u235 = Evaluation('U235.txt', verbose=False)
706+
u235.read()
707+
708+
# Check descriptive data
709+
assert hasattr(u235, 'info')
710+
assert u235.info['library'] == (u'ENDF/B', 7, 1)
711+
assert u235.info['sublibrary'] == 10
712+
assert u235.info['format'] == 6
713+
assert u235.material == 9228
714+
assert u235.projectile['mass'] == 1.0
715+
assert u235.target['fissionable']
716+
assert u235.target['mass'] == 233.0248
717+
assert u235.target['zsymam'] == u' 92-U -235 '
718+
assert not u235.target['stable']
719+
assert u235.target['isomeric_state'] == 0
720+
721+
# Check components of fission energy release
722+
delayed_betas = np.array([[6.5e+06, -7.5e-02, 0.0],
723+
[5.0e+04, 7.5e-03, 0.0]])
724+
assert_array_almost_equal(u235.fission['energy_release']['delayed_betas'],
725+
delayed_betas)
726+
727+
# Check prompt, delayed, and total nu
728+
E = np.logspace(-4, 6, 10)
729+
nu_t = np.array([2.4367, 2.4367, 2.4367, 2.4367, 2.4367,
730+
2.43586422, 2.4338, 2.4338, 2.43001824, 2.532706])
731+
nu_p = np.array([2.42085, 2.42085, 2.42085, 2.42085, 2.42085,
732+
2.42001364, 2.41794193, 2.41784842, 2.41331824, 2.516006])
733+
nu_d = np.array([0.01585, 0.01585, 0.01585, 0.01585, 0.01585005,
734+
0.01585061, 0.01585789, 0.01595191, 0.0167, 0.0167])
735+
assert_array_almost_equal(u235.fission['nu']['total'](E), nu_t)
736+
assert_array_almost_equal(u235.fission['nu']['prompt'](E), nu_p)
737+
assert_array_almost_equal(u235.fission['nu']['delayed']['values'](E), nu_d)
738+
739+
# Reactions
740+
assert 37 in u235.reactions
741+
assert 38 in u235.reactions
742+
assert 89 in u235.reactions
743+
744+
# Check reaction cross section
745+
r = u235.reactions[80] # (n,n30)
746+
assert r.xs.x[0] == 2309870.0
747+
E = np.linspace(r.xs.x[0], r.xs.x[-1], 10)
748+
sigma = np.array([0., 0.01433554, 0.01672903, 0.01649244, 0.01556801,
749+
0.01457872, 0.01341327, 0.01215489, 0.01094848,
750+
0.00987096])
751+
assert_array_almost_equal(r.xs(E), sigma)
752+
753+
# Check reaction angular distribution
754+
assert r.angular_distribution.center_of_mass
755+
assert r.angular_distribution.type == u'legendre'
756+
assert len(r.angular_distribution.energy) == 14
757+
mu = np.linspace(-1., 1., 10)
758+
p = np.array([0.22002253, 0.40547169, 0.45029205, 0.59018363, 0.6086658,
759+
0.48871545, 0.45452016, 0.55752484, 0.55576971, 0.51885337])
760+
assert_array_almost_equal(r.angular_distribution.probability[5](mu), p)
761+
762+
763+
def test_evaluation_decay():
764+
download_file('https://t2.lanl.gov/nis/data/endf/decayVII.1/092_U_233',
765+
'U233-decay.endf', '3db23dc650bae28eabb92942dd7d0de5')
766+
u233 = Evaluation('U233-decay.endf', verbose=False)
767+
u233.read()
768+
769+
assert hasattr(u233, 'info')
770+
assert u233.info['library'] == (u'ENDF/B', 7, 1)
771+
assert u233.info['sublibrary'] == 4
772+
assert u233.material == 3513
773+
assert u233.target['mass'] == 231.0377
774+
assert u233.target['zsymam'] == u' 92-U -233 '
775+
assert not u233.target['stable']
776+
777+
assert u233.decay['half_life'] == (5023970000000.0, 6311520000.0)
778+
assert u233.decay['energies'] == [(5043.237, 536.3191),
779+
(1110.218, 107.6781),
780+
(4888351.0, 28967.6)]
781+
assert len(u233.decay['modes']) == 1
782+
assert u233.decay['modes'][0]['branching_ratio'] == (1.0, 0.0)
783+
assert u233.decay['modes'][0]['energy'] == (4908500.0, 1200.0)
784+
assert u233.decay['modes'][0]['type'] == u'alpha'
785+
786+
for s in ['e-', 'alpha', 'xray', 'gamma']:
787+
assert s in u233.decay['spectra']
788+
assert u233.decay['spectra']['e-']['energy_average'] == (5043.237,
789+
536.3191)
790+
alpha_spectrum = u233.decay['spectra']['alpha']['discrete']
791+
assert alpha_spectrum[-1]['energy'] == (4824200.0, 1200.0)
792+
assert alpha_spectrum[-1]['intensity'] == (0.843, 0.006)
793+
794+
795+
def test_evaluation_photoatomic():
796+
download_file('https://www-nds.iaea.org/fendl30/data/atom/endf/ph_3000_30-Zn.txt',
797+
'Zn.txt', 'e6bda2fe6125ad9a8d51a6405ae9cc2a')
798+
zn = Evaluation('Zn.txt', verbose=False)
799+
zn.read()
800+
801+
assert zn.info['library'] == (u'ENDF/B', 6, 0)
802+
assert zn.info['sublibrary'] == 3
803+
assert zn.info['format'] == 6
804+
assert zn.projectile['mass'] == 0.0
805+
806+
assert 501 in zn.reactions
807+
assert 515 in zn.reactions
808+
assert 540 in zn.reactions
809+
810+
# Check cross section
811+
coherent = zn.reactions[502]
812+
assert len(coherent.xs.x) == 788
813+
E = np.logspace(0, 11, 10)
814+
xs = np.array([4.60408600e-03, 2.87607904e+00, 3.00145792e+02,
815+
3.43420255e+02, 8.18532007e+00, 3.58892209e-02,
816+
1.29382964e-04, 4.64984378e-07, 1.67106649e-09,
817+
6.00550000e-12])
818+
assert_array_almost_equal(coherent.xs(E), xs)
819+
820+
# Check scattering factor
821+
ff = coherent.scattering_factor
822+
x = np.logspace(-3, 9, 10)
823+
y = np.array([3.00000000e+01, 2.98789879e+01, 1.54855832e+01,
824+
4.24200000e-01, 1.40737115e-05, 7.34268836e-10,
825+
8.06893048e-14, 1.06881338e-17, 1.27450979e-21,
826+
1.40780000e-25])
827+
assert_array_almost_equal(ff(x), y)
828+
829+
830+
def test_evaluation_electroatomic():
831+
download_file('https://t2.lanl.gov/nis/data/data/ENDFB-VII-electroatomic/Mo/nat',
832+
'Mo.txt', '2139a23258c517ae3bfa5f2cc346da4c')
833+
mo = Evaluation('Mo.txt', verbose=False)
834+
mo.read()
835+
836+
assert mo.info['laboratory'].startswith('LLNL')
837+
assert 'Cullen' in mo.info['author']
838+
assert mo.info['library'] == (u'ENDF/B', 6, 0)
839+
assert mo.info['sublibrary'] == 113
840+
841+
assert 526 in mo.reactions
842+
assert 527 in mo.reactions
843+
assert 543 in mo.reactions
844+
845+
# Check bremsstrahlung cross section
846+
brem = mo.reactions[527]
847+
E = np.logspace(1, 11, 10)
848+
xs = np.array([4276.9, 6329.94427327, 5350.43318579, 1818.71320602,
849+
467.65208672, 376.17541997, 434.15352828, 484.99421137,
850+
535.39666445, 591.138])
851+
assert_array_almost_equal(brem.xs(E), xs)
852+
853+
# Check bremsstrahlung secondary distributions
854+
assert brem.products[0]['za'] == 11 # electrons
855+
E = np.logspace(1, 11)
856+
assert np.all(brem.products[0]['yield'](E) == 1.0)
857+
eout = np.array([0.1, 0.133352, 0.165482, 0.228757, 0.316228,
858+
0.421697, 0.523299, 0.723394, 1., 1.41421,
859+
2., 2.82843, 4., 5.65685, 8., 9.9, 10.])
860+
assert_array_almost_equal(brem.products[0]['energy_out'][0], eout)
861+
862+
863+
def test_evaluation_relaxation():
864+
download_file('https://t2.lanl.gov/nis/data/endf/relaxation/Xe-relax',
865+
'Xe.txt', '40ecb69da6a45f992918a98da4d98ba0')
866+
xe = Evaluation('Xe.txt', verbose=False)
867+
xe.read()
868+
869+
assert xe.info['laboratory'].startswith('LLNL')
870+
assert 'Cullen' in xe.info['author']
871+
assert xe.info['library'] == (u'ENDF/B', 6, 0)
872+
assert xe.info['sublibrary'] == 6
873+
874+
# Levels
875+
data = xe.atomic_relaxation
876+
assert len(data) == 17
877+
assert 'K' in data
878+
assert 'O3' in data
879+
880+
assert data['K']['binding_energy'] == 34556.0
881+
assert data['M5']['number_electrons'] == 6.0
882+
assert data['L1']['transitions'][6] == (u'N2', None, 5256.21, 0.00299258)
883+
assert data['N2']['transitions'][12] == (u'N5', u'O3', 81.95, 0.00224012)
884+
assert data['O3']['transitions'] == []
885+
886+
722887
if __name__ == "__main__":
723888
nose.runmodule()

0 commit comments

Comments
 (0)