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

ENH: Support providing detector names at construction #519

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Changelog

* Depletion reader settings can be provided at construction - :pull:`516`
* Support ``numpy`` 2.0 - :pull:`524`
* Names of detectors to read can be provided at construction of the detector
reader - :pull:`519`

.. _v0.10.1:

Expand Down
9 changes: 7 additions & 2 deletions src/serpentTools/parsers/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class DetectorReader(BaseReader):
----------
filePath : str
path to the depletion file
names : list of string, optional
Names of any detectors to process. If not given, fall back
to the ``detector.names``.

Attributes
----------
Expand All @@ -31,9 +34,11 @@ class DetectorReader(BaseReader):
# Update this if new detector grids are introduced
_KNOWN_GRIDS = ("E", "X", "Y", "Z", "T", "COORD", "R", "PHI", "THETA")

def __init__(self, filePath):
BaseReader.__init__(self, filePath, 'detector')
def __init__(self, filePath, names=None):
BaseReader.__init__(self, filePath, "detector")
self.detectors = {}
if names is not None:
self.settings["names"] = names

def __getitem__(self, name):
"""Retrieve a detector from :attr:`detectors`"""
Expand Down
17 changes: 16 additions & 1 deletion tests/test_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from numpy import arange, array
from numpy.testing import assert_equal
from serpentTools.parsers import read
from serpentTools.parsers import read, DetectorReader
from serpentTools.data import getFile
from serpentTools.detectors import (
CartesianDetector, HexagonalDetector, CylindricalDetector)
Expand Down Expand Up @@ -336,3 +336,18 @@ def test_timeDetector(self):
assert_equal(self.timeDet.tallies, expTallies)
assert_equal(self.timeDet.errors, expErrors)
assert_equal(self.timeDet.grids['T'], expTimeGrid)


def test_defaultSettings():
fp = getFile("ref_det0.m")
reader = DetectorReader(fp)
assert reader.settings["names"] == []


def test_filteredInitSettings():
fp = getFile("bwr_det0.m")
reader = DetectorReader(fp, names=["spectrum"])
assert reader.settings["names"] == ["spectrum"]
reader.read()
assert len(reader) == 1
assert "spectrum" in reader
Loading