serpentTools.samplers.SampledDetector¶
-
class
serpentTools.samplers.
SampledDetector
(name, allTallies, allErrors, indexes=None, grids=None)¶ Class to store aggregated detector data
- Parameters
name (str) – Name of the detector to be sampled
allTallies (numpy.ndarray or iterable of arrays) – Array of tally data for each individual detector
allErrors (numpy.ndarray or iterable of arrays) – Array of absolute tally errors for individual detectors
indexes (iterable of string, optional) – Iterable naming the bins that correspond to reshaped
tally
anderrors
.grids (dict, optional) – Additional grid information, like spatial or energy-wise grid information.
-
tallies
¶ Average of tallies from all detectors
- Type
-
deviation
¶ Deviation across all tallies
- Type
-
allTallies
¶ Array of tally data from sampled detectors. First dimension is the file index
i
, followed by the tally array for detectori
.- Type
-
allErrors
¶ Array of uncertainties for sampled detectors. Structure is identical to
allTallies
- Type
-
indexes
¶ Iterable naming the bins that correspond to reshaped
tally
anderrors
. The tuple(energy, ymesh, xmesh)
indicates thattallies
should have three dimensions corresponding to various energy, y-position, and x-position bins. Must be set aftertallies
orerrors
and agree with the shape of each
See also
-
compare
(other, lower=0, upper=10, sigma=2, verbosity=None)¶ Compare the results of this reader to another.
For values without uncertainties, the upper and lower arguments control what passes and what messages get raised. If a quantity in
other
is less thanlower
percent different that the same quantity on this object, consider this allowable and make no messages. Quantities that are greater thanupper
percent different will have a error messages printed and the comparison will returnFalse
, but continue. Quantities with difference between these ranges will have warning messages printed.- Parameters
other – Other reader instance against which to compare. Must be a similar class as this one.
lower (float or int) – Lower limit for relative tolerances in percent Differences below this will be considered allowable
upper (float or int) – Upper limit for relative tolerances in percent. Differences above this will be considered failure and errors messages will be raised
sigma (int) – Size of confidence interval to apply to quantities with uncertainties. Quantities that do not have overlapping confidence intervals will fail
verbosity (None or str) – If given, update the verbosity just for this comparison.
- Returns
True
if the objects are in agreement with each other according to the parameters specified- Return type
- Raises
TypeError – If
other
is not of the same class as this class nor a subclass of this classValueError – If upper > lower, If sigma, lower, or upper are negative
-
classmethod
fromDetectors
(name, detectors)¶ Create a
SampledDetector
from similar detectors- Parameters
name (str) – Name of this detector
detectors (iterable of
serpentTools.Detector
) – Iterable that contains detectors to be averaged. These should be structured identically, in shape of the tally data and the underlying grids and indexes.
- Returns
- Return type
- Raises
TypeError – If something other than a
serpentTools.Detector
is foundValueError – If tally data are not shaped consistently
KeyError – If some grid or index information is missing
AttributeError – If one detector is missing grids entirely but grids are present on other grids
-
classmethod
fromTallyBins
(name, bins, grids=None)¶ Create a detector instance from 2D detector data
- Parameters
name (str) – Name of this detector
bins (numpy.ndarray) – 2D array taken from Serpent. Expected to have either 12 or 13 columns, where the latter indicates a time bin has been added.
grids (dict, optional) – Dictionary of underlying energy, space, and/or time data.
- Returns
- Return type
- Raises
ValueError – If the tally data does not appear to be Serpent 2 tally data
-
meshPlot
(xdim, ydim, what='tallies', fixed=None, ax=None, cmap=None, cbarLabel=None, logColor=False, xlabel=None, ylabel=None, logx=False, logy=False, loglog=False, title=None, thresh=None, **kwargs)¶ Plot tally data as a function of two bin types on a cartesian mesh.
- Parameters
xdim (str) – Primary dimension - will correspond to x-axis on plot
ydim (str) – Secondary dimension - will correspond to y-axis on plot
what ({'tallies', 'errors'}) – Color meshes from tally data or uncertainties
fixed (None or dict) – Dictionary controlling the reduction in data down to one dimension
ax (
matplotlib.axes.Axes
, optional) – Ax on which to plot the data. If not provided, create a new plotcmap (str, optional) – Valid Matplotlib colormap to apply to the plot.
logColor (bool) – If true, apply a logarithmic coloring to the data positive data
xlabel (str or bool, optional) – Label to apply to the x-axis. If given as
None
, a label will be determined from other arguments. If notNone
but evaluates toFalse
, do not label.ylabel (str or bool, optional) – Label to apply to the y-axis. If given as
None
, a label will be determined from other arguments. If notNone
but evaluates toFalse
, do not label.logx (bool) – Apply a log scale to x axis.
logy (bool) – Apply a log scale to y axis.
loglog (bool) – Apply a log scale to both axes.
title (str) – Title to apply to the figure.
thresh (float) – Do not plot data less than or equal to this value.
cbarLabel (str) – Label to apply to colorbar. If not given, infer from
what
kwargs (dict, optional) – Addition keyword arguments to pass to
pcolormesh()
- Returns
Ax on which the data was plotted.
- Return type
- Raises
serpentTools.SerpentToolsException – If data to be plotted, with or without constraints, is not 1D
KeyError – If
fixed
is given andxdim
orydim
are contained infixed
AttributeError – If the data set by
what
not in the allowed selectionValueError – If the data contains negative quantities and
logColor
isTrue
See also
-
plot
(xdim=None, what='tallies', sigma=None, fixed=None, ax=None, xlabel=None, ylabel=None, steps=False, labels=None, logx=False, logy=False, loglog=False, legend=None, ncol=1, title=None, **kwargs)¶ Simple plot routine for 1- or 2-D data
- Parameters
xdim (str, optional) – Plot the data corresponding to changing this bin, e.g.
"energy"
. Must exist inindexes
what ({'tallies', 'errors'}) – Primary data to plot
sigma (int) – Confidence interval to apply to errors. If not given or
0
, no errors will be drawn.fixed (None or dict) – Dictionary controlling the reduction in data down to one dimension
ax (
matplotlib.axes.Axes
, optional) – Ax on which to plot the data. If not provided, create a new plotxlabel (str or bool, optional) – Label to apply to the x-axis. If given as
None
, a label will be determined from other arguments. If notNone
but evaluates toFalse
, do not label. Ifxdim
is given andxlabel
isNone
, thenxdim
will be applied to the x-axis.ylabel (str or bool, optional) – Label to apply to the y-axis. If given as
None
, a label will be determined from other arguments. If notNone
but evaluates toFalse
, do not label.steps (bool) – If true, plot the data as constant inside the respective bins. Sets
drawstyle
to besteps-post
unlessdrawstyle
given inkwargs
labels (None or iterable) – Labels to apply to each line drawn. This can be used to identify which bin is plotted as what line.
logx (bool) – Apply a log scale to x axis.
logy (bool) – Apply a log scale to y axis.
loglog (bool) – Apply a log scale to both axes.
legend (bool or str or None) – Automatically label the plot. No legend will be made if a single item is plotted. Pass one of the following values to place the legend outside the plot: above, right
ncol (int) – Integer number of columns to apply to the legend.
title (str) – Title to apply to the figure.
kwargs (dict, optional) – Addition keyword arguments to pass to
plot()
orerrorbar()
function.
- Returns
Ax on which the data was plotted.
- Return type
- Raises
SerpentToolsException – If data contains more than 2 dimensions
AttributeError – If plot data or
indexes
set up.
See also
spectrumPlot()
better options for plotting energy spectra
-
reshapedBins
()¶ Obtain multi-dimensional tally, error, and index data
- Returns
tallies (numpy.ndarray) – Potentially multi-dimensional array corresponding to tally data along each bin index
errors (numpy.ndarray) – Potentially multi-dimensional array corresponding to tally relative error along each bin index
indexes (list of str) – Ordering of named bin information, e.g.
"xmesh"
,"energy"
, corresponding to axis intallies
anderrors
Examples
A detector is created with a single bin with two bins values. These could represent tallying two different reaction rates
>>> import numpy >>> from serpentTools import Detector >>> bins = numpy.ones((2, 12)) >>> bins[1, 0] = 2 >>> bins[1, 4] = 2 >>> bins[:, -2:] = [ ... [5.0, 0.1], ... [10.0, 0.2]] >>> det = Detector("reshape", bins=bins) >>> tallies, errors, indexes = det.reshapedBins() >>> tallies array([5.0, 10.0]) >>> errors array([0.1, 0.2]) >>> indexes ["reaction", ]
-
slice
(fixed, data='tallies')¶ Return a view of the reshaped array where certain axes are fixed
- Parameters
- Returns
View into the respective data where certain dimensions have been removed
- Return type
- Raises
AttributeError – If
data
is not supported
-
spectrumPlot
(fixed=None, ax=None, normalize=True, xlabel=None, ylabel=None, steps=True, logx=True, logy=False, loglog=False, sigma=3, labels=None, legend=None, ncol=1, title=None, **kwargs)¶ Quick plot of the detector value as a function of energy.
- Parameters
fixed (None or dict) – Dictionary controlling the reduction in data
ax (
matplotlib.axes.Axes
, optional) – Ax on which to plot the data. If not provided, create a new plotnormalize (bool) – Normalize quantities per unit lethargy
xlabel (str or bool, optional) – Label to apply to the x-axis. If given as
None
, a label will be determined from other arguments. If notNone
but evaluates toFalse
, do not label.ylabel (str or bool, optional) – Label to apply to the y-axis. If given as
None
, a label will be determined from other arguments. If notNone
but evaluates toFalse
, do not label.steps (bool) – Plot tally as constant inside bin
logx (bool) – Apply a log scale to x axis.
logy (bool) – Apply a log scale to y axis.
loglog (bool) – Apply a log scale to both axes.
sigma (int) – Confidence interval to apply to errors. If not given or
0
, no errors will be drawn.labels (None or iterable) – Labels to apply to each line drawn. This can be used to identify which bin is plotted as what line.
legend (bool or str or None) – Automatically label the plot. No legend will be made if a single item is plotted. Pass one of the following values to place the legend outside the plot: above, right
ncol (int) – Integer number of columns to apply to the legend.
title (str) – Title to apply to the figure.
kwargs (dict, optional) – Addition keyword arguments to pass to
matplotlib.pyplot.plot()
ormatplotlib.pyplot.errorbar()
- Returns
Ax on which the data was plotted.
- Return type
- Raises
SerpentToolsException – if number of rows in data not equal to number of energy groups
See also
-
spreadPlot
(xdim=None, fixed=None, sampleKwargs=None, meanKwargs=None, ax=None, xlabel=None, ylabel=None, logx=False, logy=False, loglog=False, legend=True)¶ Plot the mean tally value against all sampled detector data.
- Parameters
xdim (str) – Bin index to place on the x-axis
fixed (None or dict) – Dictionary controlling the reduction in data down to one dimension
sampleKwargs (dict, optional) – Additional matplotlib-acceptable arguments to be passed into the plot when plotting data from unique runs, e.g.
{"c": k, "alpha": 0.5}
.meanKwargs (dict, optional) – Additional matplotlib-acceptable argumentst to be used when plotting the mean value, e.g.
{"c": "b", "marker": "o"}
ax (
matplotlib.axes.Axes
, optional) – Ax on which to plot the data. If not provided, create a new plotxlabel (str or bool, optional) – Label to apply to the x-axis. If given as
None
, a label will be determined from other arguments. If notNone
but evaluates toFalse
, do not label.ylabel (str or bool, optional) – Label to apply to the y-axis. If given as
None
, a label will be determined from other arguments. If notNone
but evaluates toFalse
, do not label.logx (bool) – Apply a log scale to x axis.
logy (bool) – Apply a log scale to y axis.
loglog (bool) – Apply a log scale to both axes.
legend (bool or str or None) – Automatically label the plot. No legend will be made if a single item is plotted. Pass one of the following values to place the legend outside the plot: above, right
- Returns
Ax on which the data was plotted.
- Return type
-
toMatlab
(fileP, reconvert=True, append=True, format='5', longNames=True, compress=True, oned='row')¶ Write a binary MATLAB file from the contents of this object
- Parameters
fileP (str or file-like object) – Name of the file to write.
.mat
extension is not needed ifappend==True
reconvert (bool) – If this evaluates to true, convert values back into their original form as they appear in the output file.
append (bool) – If true and a file exists under
output
, append to that file. Otherwise the file will be overwrittenformat ({'5', '4'}) – Format of file to write.
'5'
for MATLAB 5 to 7.2,'4'
for MATLAB 4longNames (bool) – If true, allow variable names to reach 63 characters, which works with MATLAB 7.6+. Otherwise, maximum length is 31 characters
compress (bool) – If true, compress matrices on write
oned ({'row', 'col'}) – Write one-dimensional arrays as row vectors if
oned=='row'
(default), or column vectors
- Raises
ImportError – If scipy is not installed
See also