diff --git a/docs/changelog.rst b/docs/changelog.rst index ef0dd7f9..644db99a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,13 @@ Changelog ========= +.. _v0.11.0: + +0.11.0 +====== + +* Depletion reader settings can be provided at construction - :pull:`516` + .. _v0.10.1: :release-tag:`0.10.1` diff --git a/src/serpentTools/parsers/depletion.py b/src/serpentTools/parsers/depletion.py index 18ade582..f30ff960 100644 --- a/src/serpentTools/parsers/depletion.py +++ b/src/serpentTools/parsers/depletion.py @@ -147,6 +147,37 @@ class DepletionReader(DepPlotMixin, MaterialReader): ---------- filePath: str path to the depletion file + materials : list of string, optional + Names and patterns to use when determining if a material found + in the file should be processed or not. ``["fuel"]`` will + result in only the material exactly named ``fuel`` to be processed. + But ``["fuel.*"]`` is a pattern that will match and collect any + material that begins with ``fuel``. If not provided, + pulls from ``depletion.materials`` setting. + + .. versionadded:: 0.11.0 + + materialVariables : list of string, optional + Names of variables to pull for each processed material. List can + contain zero or more entries like ``"ADENS"``, ``"MDENS"``, and + ``"INH_TOX"``. If not provided, pulls from + ``depletion.materialVariables`` setting. + + .. versionadded:: 0.11.0 + + metadataKeys : list of string, optional + Metadata fields to pull from the file. List can contain + zero or more of the following strings: ``"ZAI"``, ``"NAMES"``, + ``"DAYS",`` and ``"BU"`` (case sensitive). If not provided, + pulls from ``depletion.metadataKeys`` setting + + .. versionadded:: 0.11.0 + + processTotal : bool, optional + Flag to process the ``TOTAL`` data section or not. If not given, + pulls from the ``depletion.processTotal`` setting. + + .. versionadded:: 0.11.0 Attributes ---------- @@ -170,6 +201,7 @@ class DepletionReader(DepPlotMixin, MaterialReader): of this reader """ + docAttrs = """materials: dict Dictionary with material names as keys and the corresponding :py:class:`~serpentTools.objects.materials.DepletedMaterial` class @@ -178,9 +210,24 @@ class DepletionReader(DepPlotMixin, MaterialReader): Dictionary with file-wide data names as keys and the corresponding data, e.g. ``'zai'``: [list of zai numbers]""" - def __init__(self, filePath): - MaterialReader.__init__(self, filePath, 'depletion') - patterns = self.settings['materials'] or ['.*'] + def __init__( + self, + filePath, + materials=None, + materialVariables=None, + metadataKeys=None, + processTotal=None, + ): + MaterialReader.__init__(self, filePath, "depletion") + if metadataKeys is not None: + self.settings["metadataKeys"] = metadataKeys + if materials is not None: + self.settings["materials"] = materials + if processTotal is not None: + self.settings["processTotal"] = processTotal + if materialVariables is not None: + self.settings["materialVariables"] = materialVariables + patterns = self.settings["materials"] or [".*"] # match all materials if nothing given self._matPatterns = [re.compile(mat) for mat in patterns] DepPlotMixin.__init__(self) diff --git a/tests/test_depletion.py b/tests/test_depletion.py index 4e2c5d7f..de56a251 100644 --- a/tests/test_depletion.py +++ b/tests/test_depletion.py @@ -1,11 +1,13 @@ """Test the depletion file.""" + from unittest import TestCase from os import remove +from io import BytesIO from numpy import array from numpy.testing import assert_equal +import pytest -from io import BytesIO from serpentTools.data import getFile from serpentTools.settings import rc from serpentTools.parsers.depletion import ( @@ -434,3 +436,41 @@ def constructExpectedVarName(material, variable): del DepMatlabExportHelper + + +def test_defaultSettings(): + """Test behavior of settings if no additional arguments given""" + r = DepletionReader(DEP_FILE_PATH) + assert r.settings["metadataKeys"] == ["ZAI", "NAMES", "DAYS", "BU"] + assert r.settings["materials"] == [] + assert r.settings["processTotal"] + assert r.settings["materialVariables"] == [] + + +def test_simpleOverloadSettings(): + """Test overwritting some settings and the behavior""" + base = DepletionReader(DEP_FILE_PATH) + base.read() + alt = DepletionReader( + DEP_FILE_PATH, + materials=["f.*"], + materialVariables=["ADENS", "INH_TOX"], + metadataKeys=["ZAI"], + processTotal=False, + ) + assert not alt.settings["processTotal"] + alt.read() + assert set(alt.metadata) == { + "zai", + } + assert alt.zais == base.zais + assert set(alt.materials) == { + "fuel", + } + fuel = alt["fuel"] + assert set(fuel.data) == {"adens", "inhTox"} + assert fuel["adens"] == pytest.approx(base["fuel"]["adens"]) + assert fuel["inhTox"] == pytest.approx(base["fuel"]["inhTox"]) + assert alt.days is None + assert alt.burnup is None + assert alt.names is None