serpentTools.next.DetectorReader

class serpentTools.next.DetectorReader(names=None)

Class for reading Serpent detector files

Creating one of these manually may not always be necessary. However, it can be useful if repeated files are to be read, as a fresh reader is created for each call to DetectorFile.fromSerpent().

Parameters

names (str or iterable of str, optional) – Initial names of detectors to add to names

names

Names of detectors that, if found when reading, should be processed. Any other detectors will not be processed and stored

Type

set of str

read(source, sourcename=None, postcheck=True, strict=True)

Process detectors from a Serpent output file

Parameters
  • source (str or pathlib.Path or io.IOBase) – Filenames can be provided as strings or pathlib.Path and will be opened accordingly. Otherwise read directly from this argument

  • sourcename (str, optional) – Additional descriptor of the data source. If not provided, and source is a string or pathlib.Path, use the name of the file

  • postcheck (bool, optional) – Check if any detectors have been found after reading. Default: True

  • strict (bool, optional) – Raise errors if no detectors are found during post-read check. Otherwise warn if none are found. Default : True

Returns

Mapping of detector names and their corresponding instances.

Return type

DetectorFile

Raises

SerpentToolsException – If postcheck and strict and no detectors were found

Warns

UserWarning – if postcheck and not strict and no detectors were found

readTextStream(stream, sourcename=None, postcheck=True, strict=True)

Process detectors from a stream of text data

Differs from read() as this method only handles readable io.TextIOBase instances, like opened files. read() relies on this method for processing of the file data, but handles more input types.

Parameters
  • source (io.TextIOBase) – readable() buffer of text data corresponding to a Serpent output file.

  • sourcename (str, optional) – Additional descriptor of the data source. If not provided, and source is a string or pathlib.Path, use the name of the file

  • postcheck (bool, optional) – Check if any detectors have been found after reading. Default: True

  • strict (bool, optional) – Raise errors if no detectors are found during post-read check. Otherwise warn if none are found. Default : True

Returns

Mapping of detector names and their corresponding instances.

Return type

DetectorFile

Raises

SerpentToolsException – If postcheck and strict and no detectors were found

Warns

UserWarning – if postcheck and not strict and no detectors were found