Skip to content

Commit c4b8ee6

Browse files
authored
Merge pull request #456 from drewejohnson/drewj/xsplot-2-1-32-454
BUG Support more values like psepc on xsplot reader
2 parents e8cd094 + d8c9d8c commit c4b8ee6

File tree

5 files changed

+121
-4
lines changed

5 files changed

+121
-4
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Changelog
1616

1717
.. _v0.9.4:
1818

19+
0.9.4rc1
20+
========
21+
* Support for reading ``pspec`` fields in xsplot files
22+
1923
:release-tag:`0.9.4rc0`
2024
====================
2125

serpentTools/data/plut_xs0.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,35 @@
277277
2.93887E-01
278278
];
279279

280+
i94239_03c_pspec = [
281+
1.36082E-02 1.47639E-02
282+
3.27184E-03 5.25321E-03
283+
1.64140E-02 3.43399E-03
284+
1.37229E-02 1.50625E-03
285+
1.29750E-02 3.69478E-04
286+
5.16240E-02 2.72200E-04
287+
3.86610E-02 1.04400E-04
288+
1.29296E-01 6.31000E-05
289+
9.89280E-02 5.69788E-05
290+
3.75054E-01 1.55400E-05
291+
4.13713E-01 1.46600E-05
292+
9.87800E-02 1.46500E-05
293+
1.11820E-01 1.29767E-05
294+
5.68280E-02 1.15200E-05
295+
1.10928E-01 6.61565E-06
296+
2.03550E-01 5.69000E-06
297+
9.92700E-01 2.70000E-10
298+
8.16000E-01 2.40000E-10
299+
7.63600E-01 2.20000E-10
300+
9.86900E-01 2.10000E-10
301+
6.93200E-01 2.00000E-10
302+
7.92900E-01 2.00000E-10
303+
4.12300E-01 1.80000E-10
304+
1.00570E+00 1.80000E-10
305+
7.62600E-01 1.00000E-10
306+
6.70800E-01 9.00000E-11
307+
6.70990E-01 9.00000E-11
308+
9.18700E-01 8.40000E-11
309+
1.72560E-01 3.00000E-11
310+
1.23228E-01 1.60000E-11
311+
];

serpentTools/objects/xsdata.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class XSData(NamedObject):
4444
metadata : dict
4545
File-wide metadata from the reader. Alias for accessing
4646
:attr:`energies`. Will be removed in the future
47+
misc : dict of str to numpy.ndarray
48+
Other arrays that do not have a dedicated attribute, e.g.,
49+
``pspec`` for photon line spectrum
4750
4851
"""
4952

@@ -89,6 +92,8 @@ def __init__(self, name, metadata, isIso=False):
8992
# whether nu data present for fissionables
9093
self.hasNuData = False
9194

95+
self.misc = {}
96+
9297
def __len__(self):
9398
"""Number of reactions stored"""
9499
return len(self.MT)

serpentTools/parsers/xsplot.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"""Parser responsible for reading the ``*_xsplot.m`` files"""
2+
import warnings
3+
import re
4+
25
from numpy import array, float64
36

47
from serpentTools.messages import error, warning
@@ -44,6 +47,7 @@ class XSPlotReader(BaseReader):
4447
likely be removed in the future
4548
4649
"""
50+
_misc = {"pspec", }
4751

4852
def __init__(self, filePath):
4953
super().__init__(filePath, 'xsplot')
@@ -146,7 +150,22 @@ def _read(self):
146150
self.xsections[xsname].setData(chunk)
147151

148152
else:
149-
raise ValueError("Unidentifiable entry\n{}".format(chunk))
153+
self._processMisc(lead, data)
154+
155+
def _processMisc(self, lead, data):
156+
variable = lead.split()[0]
157+
for key in self._misc:
158+
start = variable.find(key)
159+
if start == -1:
160+
continue
161+
xsname = re.sub("_$", "", variable[:start])
162+
cleaned = list(map(str.split, data))
163+
self.xsections[xsname].misc[key] = array(cleaned, dtype=float)
164+
return
165+
166+
warnings.warn(
167+
"Unidentifiable entry in {}: {}".format(self.filePath, lead)
168+
)
150169

151170
def _precheck(self):
152171
"""do a quick scan to ensure this looks like a xsplot file."""

tests/test_xsplot.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""Test the xsplot reader."""
22
import unittest
33
from numpy import ndarray, array, newaxis
4-
54
from numpy.testing import assert_array_equal
5+
import pytest
66

77
from serpentTools.parsers.xsplot import XSPlotReader
88
from serpentTools.data import getFile
99

10+
DATA_FILE = getFile("plut_xs0.m")
11+
1012

1113
def findDiff(d1, d2, path=""):
1214
""" Diffs two dictionaries with nested structure
@@ -48,8 +50,7 @@ class XSPlotTester(unittest.TestCase):
4850

4951
@classmethod
5052
def setUpClass(cls):
51-
cls.file = getFile('plut_xs0.m')
52-
cls.reader = XSPlotReader(cls.file)
53+
cls.reader = XSPlotReader(DATA_FILE)
5354
cls.reader.read()
5455

5556
def test1_allXS(self):
@@ -782,3 +783,59 @@ def test2_testPrintMT(self):
782783
"""
783784
actual = self.reader.xsections['mfissile'].showMT(retstring=True)
784785
self.assertEqual(refString.rstrip(), actual.rstrip())
786+
787+
788+
def test_goodMisc():
789+
reader = XSPlotReader(DATA_FILE)
790+
reader.read()
791+
pu = reader["i94239_03c"]
792+
assert "pspec" in pu.misc
793+
actualPspec = array(
794+
[
795+
[1.36082E-02, 1.47639E-02],
796+
[3.27184E-03, 5.25321E-03],
797+
[1.64140E-02, 3.43399E-03],
798+
[1.37229E-02, 1.50625E-03],
799+
[1.29750E-02, 3.69478E-04],
800+
[5.16240E-02, 2.72200E-04],
801+
[3.86610E-02, 1.04400E-04],
802+
[1.29296E-01, 6.31000E-05],
803+
[9.89280E-02, 5.69788E-05],
804+
[3.75054E-01, 1.55400E-05],
805+
[4.13713E-01, 1.46600E-05],
806+
[9.87800E-02, 1.46500E-05],
807+
[1.11820E-01, 1.29767E-05],
808+
[5.68280E-02, 1.15200E-05],
809+
[1.10928E-01, 6.61565E-06],
810+
[2.03550E-01, 5.69000E-06],
811+
[9.92700E-01, 2.70000E-10],
812+
[8.16000E-01, 2.40000E-10],
813+
[7.63600E-01, 2.20000E-10],
814+
[9.86900E-01, 2.10000E-10],
815+
[6.93200E-01, 2.00000E-10],
816+
[7.92900E-01, 2.00000E-10],
817+
[4.12300E-01, 1.80000E-10],
818+
[1.00570E+00, 1.80000E-10],
819+
[7.62600E-01, 1.00000E-10],
820+
[6.70800E-01, 9.00000E-11],
821+
[6.70990E-01, 9.00000E-11],
822+
[9.18700E-01, 8.40000E-11],
823+
[1.72560E-01, 3.00000E-11],
824+
[1.23228E-01, 1.60000E-11],
825+
]
826+
)
827+
assert pu.misc["pspec"] == pytest.approx(actualPspec, rel=0, abs=0)
828+
829+
830+
@pytest.fixture
831+
def xsreaderNoPspec():
832+
reader = XSPlotReader(DATA_FILE)
833+
reader._misc.difference_update({"pspec", })
834+
return reader
835+
836+
837+
def test_missingPspec(xsreaderNoPspec):
838+
with pytest.warns(UserWarning, match="pspec"):
839+
xsreaderNoPspec.read()
840+
pu = xsreaderNoPspec["i94239_03c"]
841+
assert "pspec" not in pu.misc

0 commit comments

Comments
 (0)