serpentTools.SensitivityReader

class serpentTools.SensitivityReader(filePath)

Class for reading sensitivity files

The arrays that are stored in sensitivities and energyIntegratedSens are stored under converted names. The original names from SERPENT are of the form ADJ_PERT_KEFF_SENS or ADJ_PERT_KEFF_SENS_E_INT, respectively. Since this reader stores the resulting arrays in unique locations, the names are converted to a succint form. The two arrays listed above would be stored both as keff in sensitivities and energyIntegratedSens. All names are converted to mixedCaseNames to fit the style of the project.

Ordered dictionaries materials, zais and perts contain keys of the names of their respective data, and the corresponding index, iSENS_ZAI_zzaaai, in the sensitivity arrays. These arrays are zero-indexed, so the first item will have an index of zero. The data stored in the sensitivities and energyIntegratedSens dictionaries has the exact same structure as if the arrays were loaded into MATLAB/Octave, but with zero-indexing.

The matrices in sensitivities are ordered as they would be in MATLAB. The five dimensions correspond to:

  1. materials that were contained perturbed isotopes

  2. zais that were perturbed

  3. perts - reactions that were perturbed, e.g. 'total xs'

  4. energies - which energy group contained the perturbation. Will have one fewer dimensions than the number of values in energies, corresponding to the number of energy groups.

  5. [value, relative uncertainty] pairs

The matrices in energyIntegratedSens will have the same structure, but with the energies dimension removed.

Note

Arrays generated using the history option sens opt history 1 are not currently stored on the reader. See feature request #367

Parameters

filePath (str) – Path to sensitivity file

nMat

Number of materials

Type

None or int

nZai

Number of perturbed isotopes

Type

None or int

nPert

Number of perturbations

Type

None or int

nEne

Number of energy groups

Type

None or int

nMu

Number of perturbed materials

Type

None or int

materials

Ordered dictionary of materials that have been perturbed.

Type

OrderedDict

zais

Ordered dictionary of nuclides that have been perturbed

Type

OrderedDict

perts

Ordered dictionary of reactions that have been perturbed, e.g ‘total xs’

Type

OrderedDict

latGen

Number of latent generations used to generate these sensitivities

Type

int

energies

Array of energy bounds for the sensitivities, from lowest to highest

Type

None or numpy.array

lethargyWidths

Array of lethargy widths of each energy group.

Type

None or numpy.array

sensitivities

Dictionary of names of sensitivities and their corresponding arrays.

Type

dict

energyIntegratedSens

Dictionary of names of the sensitivities that have been integrated against energy, and their corresponding arrays

Type

dict

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 than lower percent different that the same quantity on this object, consider this allowable and make no messages. Quantities that are greater than upper percent different will have a error messages printed and the comparison will return False, 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

bool

Raises
  • TypeError – If other is not of the same class as this class nor a subclass of this class

  • ValueError – If upper > lower, If sigma, lower, or upper are negative

plot(resp, zai=None, pert=None, mat=None, mevscale=False, egrid=None, sigma=3, normalize=True, ax=None, labelFmt=None, title=None, logx=True, logy=False, loglog=False, xlabel=None, ylabel=None, legend=None, ncol=1)

Plot sensitivities due to some or all perturbations.

Note

Without passing zai, pert, or mat arguments, this method will plot all permutations of sensitivities for a given response.

Parameters
  • resp (str) – Name of the specific response to be examined. Must be a key in sensitivities and energyIntegratedSens

  • zai (None or str or int or iterable) – Plot sensitivities due to these isotopes. Passing None will plot against all isotopes.

  • pert (None or str or list of strings) – Plot sensitivities due to these perturbations. Passing None will plot against all perturbations.

  • mat (None or str or list of strings) – Plot sensitivities due to these materials. Passing None will plot against all materials.

  • mevscale (bool, optional) – Flag for plotting energy grid in MeV units. If True, the energy axis is expressed in MeV. Default is False.

  • egrid (numpy.array, optional) – User-defined energy grid boundaries displayed on the sensitivities as vblack, dashed vertical lines. Default is None.

  • sigma (int) – Confidence interval to apply to errors. If not given or 0, no errors will be drawn.

  • normalize (True) – Normalize plotted data per unit lethargy

  • ax (matplotlib.axes.Axes, optional) – Ax on which to plot the data. If not provided, create a new plot

  • labelFmt (None or str) –

    Formattable string to be applied to the labels. The following entries will be formatted for each plot permuation:

    {m} - name of the material
    {z} - isotope zai
    {p} - specific perturbation
    {r} - response being plotted
    

  • 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.

  • 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 not None but evaluates to False, 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 not None but evaluates to False, do not label.

  • 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.

Returns

Ax on which the data was plotted.

Return type

matplotlib.axes.Axes

Raises

KeyError – If response or any passed perturbation settings are not present on the object

See also

read()

The main method for reading that not only parses data, but also runs pre and post checks.

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 if append==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 overwritten

  • format ({'5', '4'}) – Format of file to write. '5' for MATLAB 5 to 7.2, '4' for MATLAB 4

  • longNames (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