Data

class sherpa.data.Data(name, indep, y, staterror=None, syserror=None)[source] [edit on github]

Bases: NoNewAttributesAfterInit, BaseData

Generic, N-Dimensional data sets.

A data class is the collection of a data space and a number of data arrays for the dependent variable and associated errors.

Parameters:
  • name (string) – name of this dataset

  • indep (tuple of array_like) – the tuple of independent arrays.

  • y (array_like) – The values of the dependent observable. If this is a numpy masked array, the mask will used to initialize a mask.

  • staterror (array_like) – the statistical error associated with the data

  • syserror (array_like) – the systematic error associated with the data

Notes

This class can be extended by classes definining data sets of specific dimensionality. Extending classes should override the _init_data_space method.

This class provides most of the infrastructure for extending classes for free.

Data classes contain a mask attribute, which can be used ignore certain values in the array when fitting or plotting that data. The convention in Sherpa is that True marks a values as valid and False as invalid (note that this is opposite to the numpy convention). When a Data instance is initialized with a dependent array that has a mask attribute (e.g. numpy masked array), it will attempt to convert that mask to the Sherpa convention and raise a warning otherwise. In any case, the user can set data.mask after initialization if that conversion does not yield the expected result.

Attributes Summary

dep

Left for compatibility with older versions

indep

The grid of the data space associated with this data set.

mask

Mask array for dependent variable

ndim

The dimensionality of the dataset, if defined, or None.

size

The number of elements in the data set.

staterror

The statistical error on the dependent axis, if set.

syserror

The systematic error on the dependent axis, if set.

y

The dependent axis.

Methods Summary

apply_filter(data)

eval_model(modelfunc)

Evaluate the model on the independent axis.

eval_model_to_fit(modelfunc)

Evaluate the model on the independent axis after filtering.

get_dep([filter])

Return the dependent axis of a data set.

get_dims()

Return the dimensions of this data space as a tuple of tuples.

get_error([filter, staterrfunc])

Return the total error on the dependent variable.

get_indep([filter])

Return the independent axes of a data set.

get_staterror([filter, staterrfunc])

Return the statistical error on the dependent axis of a data set.

get_syserror([filter])

Return the statistical error on the dependent axis of a data set.

get_y([filter, yfunc, use_evaluation_space])

Return dependent axis in N-D view of dependent variable

get_yerr([filter, staterrfunc])

Return errors in dependent axis in N-D view of dependent variable

get_ylabel([yfunc])

Return label for dependent axis in N-D view of dependent variable"

ignore(*args, **kwargs)

notice(mins, maxes[, ignore, integrated])

set_dep(val)

Set the dependent variable values.

set_indep(val)

to_fit([staterrfunc])

to_guess()

Attributes Documentation

dep

Left for compatibility with older versions

indep

The grid of the data space associated with this data set.

When set, the field must be set to a tuple, even for a one-dimensional data set. The “related” fields such as the dependent axis and the error fields are set to None if their size does not match.

Changed in version 4.14.1: The filter created by notice and ignore is now cleared when the independent axis is changed.

Return type:

tuple of array_like

mask

Mask array for dependent variable

Returns:

mask

Return type:

bool or numpy.ndarray

ndim = None

The dimensionality of the dataset, if defined, or None.

size

The number of elements in the data set.

Returns:

size – If the size has not been set then None is returned.

Return type:

int or None

staterror

The statistical error on the dependent axis, if set.

This must match the size of the independent axis.

syserror

The systematic error on the dependent axis, if set.

This must match the size of the independent axis.

y

The dependent axis.

If set, it must match the size of the independent axes.

Methods Documentation

apply_filter(data)[source] [edit on github]
eval_model(modelfunc)[source] [edit on github]

Evaluate the model on the independent axis.

eval_model_to_fit(modelfunc)[source] [edit on github]

Evaluate the model on the independent axis after filtering.

get_dep(filter=False)[source] [edit on github]

Return the dependent axis of a data set.

Parameters:

filter (bool, optional) – Should the filter attached to the data set be applied to the return value or not. The default is False.

Returns:

axis – The dependent axis values for the data set. This gives the value of each point in the data set.

Return type:

array

See also

get_indep

Return the independent axis of a data set.

get_error

Return the errors on the dependent axis of a data set.

get_staterror

Return the statistical errors on the dependent axis of a data set.

get_syserror

Return the systematic errors on the dependent axis of a data set.

get_dims()[source] [edit on github]

Return the dimensions of this data space as a tuple of tuples. The first element in the tuple is a tuple with the dimensions of the data space, while the second element provides the size of the dependent array.

Return type:

tuple

get_error(filter=False, staterrfunc=None)[source] [edit on github]

Return the total error on the dependent variable.

Parameters:
  • filter (bool, optional) – Should the filter attached to the data set be applied to the return value or not. The default is False.

  • staterrfunc (function) – If no statistical error has been set, the errors will be calculated by applying this function to the dependent axis of the data set.

Returns:

axis – The error for each data point, formed by adding the statistical and systematic errors in quadrature.

Return type:

array or None

See also

get_dep

Return the independent axis of a data set.

get_staterror

Return the statistical errors on the dependent axis of a data set.

get_syserror

Return the systematic errors on the dependent axis of a data set.

get_indep(filter=False)[source] [edit on github]

Return the independent axes of a data set.

Parameters:

filter (bool, optional) – Should the filter attached to the data set be applied to the return value or not. The default is False.

Returns:

axis – The independent axis values for the data set. This gives the coordinates of each point in the data set.

Return type:

tuple of arrays

See also

get_dep

Return the dependent axis of a data set.

get_staterror(filter=False, staterrfunc=None)[source] [edit on github]

Return the statistical error on the dependent axis of a data set.

Parameters:
  • filter (bool, optional) – Should the filter attached to the data set be applied to the return value or not. The default is False.

  • staterrfunc (function) – If no statistical error has been set, the errors will be calculated by applying this function to the dependent axis of the data set.

Returns:

axis – The statistical error for each data point. A value of None is returned if the data set has no statistical error array and staterrfunc is None.

Return type:

array or None

See also

get_error

Return the errors on the dependent axis of a data set.

get_indep

Return the independent axis of a data set.

get_syserror

Return the systematic errors on the dependent axis of a data set.

get_syserror(filter=False)[source] [edit on github]

Return the statistical error on the dependent axis of a data set.

Parameters:

filter (bool, optional) – Should the filter attached to the data set be applied to the return value or not. The default is False.

Returns:

axis – The systematic error for each data point. A value of None is returned if the data set has no systematic errors.

Return type:

array or None

See also

get_error

Return the errors on the dependent axis of a data set.

get_indep

Return the independent axis of a data set.

get_staterror

Return the statistical errors on the dependent axis of a data set.

get_y(filter=False, yfunc=None, use_evaluation_space=False)[source] [edit on github]

Return dependent axis in N-D view of dependent variable

Parameters:
  • filter

  • yfunc

  • use_evaluation_space

get_yerr(filter=False, staterrfunc=None)[source] [edit on github]

Return errors in dependent axis in N-D view of dependent variable

Parameters:
  • filter

  • staterrfunc

get_ylabel(yfunc=None)[source] [edit on github]

Return label for dependent axis in N-D view of dependent variable”

Parameters:

yfunc

ignore(*args, **kwargs)[source] [edit on github]
notice(mins, maxes, ignore=False, integrated=False)[source] [edit on github]
set_dep(val)[source] [edit on github]

Set the dependent variable values.

Parameters:

val (sequence or number) – If a number then it is used for each element.

set_indep(val)[source] [edit on github]
to_fit(staterrfunc=None)[source] [edit on github]
to_guess()[source] [edit on github]