Skip to content

Commit

Permalink
Fixing bug in addDummyNuclidesToLibrary (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Apr 30, 2022
1 parent b47186e commit bbec775
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -434,6 +434,6 @@ only use third-party Python libraries that have MIT or BSD licenses.
.. |Build Status| image:: https://github.com/terrapower/armi/actions/workflows/unittests.yaml/badge.svg?branch=master
:target: https://github.com/terrapower/armi/actions/workflows/unittests.yaml

.. |Code Coverage| image:: https://coveralls.io/repos/github/terrapower/armi/badge.svg?branch=master&kill_cache=3
.. |Code Coverage| image:: https://coveralls.io/repos/github/terrapower/armi/badge.svg?branch=master&kill_cache=0
:target: https://coveralls.io/github/terrapower/armi?branch=master

21 changes: 14 additions & 7 deletions armi/nuclearDataIO/cccc/gamiso.py
Expand Up @@ -77,27 +77,34 @@ def addDummyNuclidesToLibrary(lib, dummyNuclides):
if not dummyNuclides:
runLog.important("No dummy nuclide data provided to be added to {}".format(lib))
return False
if len(lib.xsIDs) > 1:
elif len(lib.xsIDs) > 1:
runLog.warning(
"Cannot add dummy nuclide data to GAMISO library {} containing data for more than 1 XS ID.".format(
lib
)
)
return False

dummyNuclideKeysAddedToLibrary = []
for dummyNuclide in dummyNuclides:
dummyKey = dummyNuclide.nucLabel + lib.xsIDs[0]
dummyKey = dummyNuclide.nucLabel
if len(lib.xsIDs):
dummyKey += xsIDs[0]
if dummyKey in lib:
continue

runLog.debug("Adding {} nuclide data to {}".format(dummyKey, lib))
newDummy = xsNuclides.XSNuclide(lib, dummyKey)

# Copy gamiso metadata from the isotxs metadata of the given dummy nuclide
for kk, vv in dummyNuclide.isotxsMetadata.items():
if vv in ["jj", "jband"]:
newDummy.gamisoMetadata[vv] = {}
for mm in dummyNuclide.isotxsMetadata[vv]:
newDummy.gamisoMetadata[vv][mm] = 1
newDummy.gamisoMetadata[kk] = dummyNuclide.isotxsMetadata[kk]
if kk in ["jj", "jband"]:
newDummy.gamisoMetadata[kk] = {}
for mm in vv:
newDummy.gamisoMetadata[kk][mm] = 1
else:
newDummy.gamisoMetadata[kk] = vv

lib[dummyKey] = newDummy
dummyNuclideKeysAddedToLibrary.append(dummyKey)

Expand Down
49 changes: 49 additions & 0 deletions armi/nuclearDataIO/cccc/tests/test_gamiso.py
@@ -0,0 +1,49 @@
# Copyright 2022 TerraPower, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test GAMISO reading and writing"""

from copy import deepcopy
import os
import unittest

from armi.nuclearDataIO import xsLibraries
from armi.nuclearDataIO.cccc import gamiso
from armi.nuclearDataIO.xsNuclides import XSNuclide

THIS_DIR = os.path.dirname(__file__)
FIXTURE_DIR = os.path.join(THIS_DIR, "..", "..", "tests", "fixtures")
GAMISO_AA = os.path.join(FIXTURE_DIR, "mc2v3-AA.gamiso")


class TestGamiso(unittest.TestCase):
def setUp(self):
self.xsLib = xsLibraries.IsotxsLibrary()

def test_compare(self):
gamisoAA = gamiso.readBinary(GAMISO_AA)
self.xsLib.merge(deepcopy(gamisoAA))
self.assertTrue(gamiso.compare(self.xsLib, gamisoAA))

def test_addDummyNuclidesToLibrary(self):
dummyNuclides = [XSNuclide(None, "U238AA")]
before = self.xsLib.getNuclides("")
self.assertTrue(gamiso.addDummyNuclidesToLibrary(self.xsLib, dummyNuclides))

after = self.xsLib.getNuclides("")
self.assertGreater(len(after), len(before))

diff = set(after).difference(set(before))
self.assertEqual(len(diff), 1)
self.assertEqual(list(diff)[0].xsId, "38")
2 changes: 1 addition & 1 deletion armi/nuclearDataIO/xsNuclides.py
Expand Up @@ -247,7 +247,7 @@ def plotScatterMatrix(scatterMatrix, scatterTypeLabel="", fName=None):
pyplot.show()


def compareScatterMatrix(scatterMatrix1, scatterMatrix2, fName=None):
def plotCompareScatterMatrix(scatterMatrix1, scatterMatrix2, fName=None):
"""Compares scatter matrices graphically between libraries."""
from matplotlib import pyplot

Expand Down
2 changes: 1 addition & 1 deletion armi/utils/codeTiming.py
Expand Up @@ -290,7 +290,7 @@ def timeline(base_file_name, inclusion_cutoff=0.1, total_time=False):
_loc, labels = plt.yticks()
for tick in labels:
tick.set_fontsize(40)
# plt.grid(True, axis='x')

plt.tight_layout()

# plot content draw
Expand Down
2 changes: 0 additions & 2 deletions armi/utils/iterables.py
Expand Up @@ -233,7 +233,6 @@ def select(self, pred):
newseq = seq.select(...).drop(...).transform(...)
"""
# self._iter = (i for i in self if pred(i))
self._iter = filter(pred, self._iter)
return self

Expand All @@ -244,7 +243,6 @@ def drop(self, pred):
newseq = seq.select(...).drop(...).transform(...)
"""
# self._iter = (i for i in self if not pred(i))
self._iter = filterfalse(pred, self._iter)
return self

Expand Down

0 comments on commit bbec775

Please sign in to comment.