serpentTools.next.DetectorFile¶
-
class
serpentTools.next.
DetectorFile
(*args, filename=None, **kwargs)¶ Dictionary-like storage of detectors
Inherits from
dict
, but enforces that all values areDetector
or subclasses. Therefore the following are allowedd.get(name, default=None) for k, v in d.items(): pass det = d[name] det = d.pop(name)
- Parameters
args (iterable of key-value pairs or dictionary, optional) – Pre-defined iterable of detectors. Can either be an existing dictionary of the form
{name: detector}
, or an iterable of the form[[name, detector], ...]
filename (str, optional) – Helpful identifier for the source of this data, e.g. file name
kwargs – Additional way to pass detectors to the instance with
`DetectorFile(..., xy=<Detector>, spectrum=<Detector>)
-
filename
¶ Identifier for the source of this data, e.g. a file name. A value of
None
indicates the filename was not passed
See also
-
__contains__
()¶ True if D has a key k, else False.
-
__getitem__
()¶ x.__getitem__(y) <==> x[y]
-
__iter__
()¶ Implement iter(self).
-
__len__
()¶ Return len(self).
-
clear
() → None. Remove all items from D.¶
-
copy
() → a shallow copy of D¶
-
classmethod
fromSerpent
(source, sourcename=None, postcheck=True, strict=True, names=None)¶ Load data from a Serpent output file
- Parameters
source (str or pathlib.Path or io.IOBase) – Source of Serpent output data. File names can be passed as either strings or
pathlib.Path
. Otherwise, source must be readable, e.g. supportsource.read
andsource.readline
sourcename (str, optional) – Alternative identifier for the source. If not provided and
source
is a string orpathlib.Path
, the name will reflect the name of the filepostcheck (bool, optional) – Perform simple checks after the file has been processed. Default is to perform the check
strict (bool, optional) – If simple checks fail during post-check routines, raise an error if
True
or a warning. Default is to raise an errornames (str or iterable of str, optional) – Names of detectors that, if found, will be processed. Detectors not found in
names
will not be included in the returned object
- Returns
Specific subclass corresponding to the file type
- Return type
- Raises
serpentTools.SerpentToolsException – If
postcheck
, a check fails, andstrict
- Warns
UserWarning – If
postcheck
, a check fails, and notstrict
-
fromkeys
()¶ Returns a new dict with keys from iterable and values equal to value.
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised
-
popitem
() → (k, v), remove and return some (key, value) pair as a¶ 2-tuple; but raise KeyError if D is empty.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
(*args, **kwargs)¶ Update with another mapping of detectors
Arguments can be another
DetectorFile
, dictionary of{key: <Detector>}
, or iterable[[key, <Detector>]]
much like the formats expected by the constructor.
-
values
() → an object providing a view on D's values¶