serpentTools.objects.XSData

class serpentTools.objects.XSData(name, metadata, isIso=False)

Base class for storing cross section data an xsplot file

Parameters
  • name (str) – Name of this material

  • metadata (dict) – Dictionary with file metadata. Expects egrid as a key at least

  • isIso (bool, optional) – Flag indicating if this data section is for a single isotope or for a material

isIso

Whether this describes individual isotope XS, or whole-material XS

Type

bool

MT

Macroscopic cross section integers

Type

list

MTdescip

Descriptions of reactions in MT

Type

list

xsdata

Array of xs data. Rows correspond to items in MT

Type

numpy.ndarray

hasNuData

True if nu data is present

Type

bool

energies

Energy grid [MeV]

Type

numpy.ndarray

metadata

File-wide metadata from the reader. Alias for accessing energies. Will be removed in the future

Type

dict

__getitem__(mt)

Return data corresponding to a given mt

Parameters

mt (int) – Integer MT reaction number

Returns

Cross section data for this mt

Return type

numpy.ndarray

Raises
__len__()

Number of reactions stored

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

describe(mt)

Return the description for any reaction MT

Parameters

mt (int) – Integer reaction number, e.g. 102 or -8. Assumes neutrons only

Returns

Description for this reaction

Return type

str

get(mt, default=None)

Return data corresponding to a given mt or a default

Parameters
  • mt (int) – Integer MT reaction number

  • default (object) – Object to be returned in mt is not found

Returns

numpy.ndarray if mt is found. Otherwise default

Return type

object

Raises

AttributeError – If xsdata is empty

hasExpectedData()

Check that the expected data (MT numbers, an energy grid, etc) were collected.

static negativeMTDescription(mt)

Descriptions for Serpent negative MT numbers

These correspond to macroscopic properties, like fission energy production, and for neutrons only. From Serpent Wiki

Parameters

mt (int) – Macroscopic reaction MT. Must be negative

Returns

Description

Return type

str

plot(mts='all', ax=None, loglog=False, xlabel=None, ylabel=None, logx=True, logy=False, title=None, legend=None, ncol=1, labels=None, **kwargs)

Plot XS corresponding to their MTs.

Parameters
  • mts (int, string, or list of ints) – If it’s a string, it should be ‘all’. A single int indicates one MT reaction number. A list should be a list of MT numbers to plot.

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

  • loglog (bool) – Apply a log scale to both axes.

  • logx (bool) – Apply a log scale to x axis.

  • logy (bool) – Apply a log scale to y axis.

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

  • title (str) – Title to apply to the figure.

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

  • labels (str or list of str or dict {int: str}) – Labels to apply to the plot. Defaults to labeling by MT description. If a string, then mts must be a single integer. If a list of strings, each label will be applied to each entry in mts. If a dictionary, keys must be mts and their labels as values. The number of keys do not have to align with the number of MTs

  • kwargs (dict, optional) – Addition keyword arguments to pass to matplotlib.pyplot.plot()

Returns

Ax on which the data was plotted.

Return type

matplotlib.axes.Axes

Raises

TypeError – If MT numbers that don’t make sense come up

setData(chunk)

Parse data from chunk to np array.

setMTs(chunk)

Parse chunk to MT numbers and descriptions

setNuData(chunk)

Add fission neutrons per fission data

showMT(retstring=False)

Create a pretty-print style string of the MT values avaialable

Parameters

retstring (bool) – Return a string if true. Otherwise, print it

tabulate(mts='all', colnames=None)

Returns a pandas table, for pretty tabulation in Jupyter notebooks.

Parameters
  • mts (int, string, or list of ints) – If it’s a string, it should be ‘all’, which is default. A single int indicates one MT reaction number. A list should be a list of MT numbers to plot.

  • colnames (any type with string representation) – Column names for each MT number, if you’d like to change them.

Returns

Tabulated representation of the cross section data

Return type

pandas.DataFrame

Raises
  • ImportError – If pandas is not installed

  • TypeError – if MT numbers that don’t make sense come up