The sherpa.data module

Tools for creating, storing, inspecting, and manipulating data sets.

The main classes for representing data sets are Data1D, Data1DInt, and Data2D, to handle (x, y), (xlo, xhi, y), and (x1, x2, y) data, although there are also more-specialized cases, such as Data1DAsymmetricErrs. These classes build on the Data class, which supports dynamic filtering of data - to select a subset of the data range - as well as data access and model evaluation to match the data range.

The Filter class is used to handle data filtering - that is, to combine filters such as selecting the range a to b (notice) and hiding the range c to d (ignore). This is used with the DataSpace1D and DataSpace2D classes to handle evaluating models on different grids to the data, and then converting back to the data space, whether by rebinning or interpolation.

Design

The design for the Data class assumes

  • the basic fields are the independent axis - which is thought of as a tuple of arrays - and the dependent axis, where normally the independent axis is labelled starting with x, and the dependent axis y.

  • there are a number of related fields - such as the statistical and systematic errors - that follow the same behavior as the independent and dependent axes.

  • fields are converted to ndarray when read in.

  • the independent axes can either be points (PointAxis) or integrated (IntegratedAxis). There is currently no support for an object with a combination of point and integrated axes but it could be added.

  • the independent axis is mediated by a “Data Space” (DataSpaceND, DataSpace1D, IntegratedDataSpace1D, DataSpace2D, and IntegratedDataSpace2D).

  • Data objects contain the ndim field to indicate the number of independent axes it supports.

  • to support arbitrary dimensions, the data is treated as one-dimensional arrays.

  • Data objects can be created with no data, but are fixed once an axis - expected to be the independent axis but it need not be - is set (see the size attribute). In general the data is assumed to be set when the object is created.

  • there are checks to ensure that the data has the correct size, shape, and potentially data type, but this is not intended to catch all possible problems.

  • Numpy masked arrays can be used to initialize the dependent variable and the mask is converted to the format of the mask attribute of the Data object, taking into account that for Sherpa a value of True indicates a valid quantity, while the opposite is true in numpy.

    In general, it is expected that any filtering has been applied before the Data object is created.

  • the independent axes are marked as read-only, so the only way to change a value is to replace the whole axis, in which case any existing filter will be removed.

Notebook support

The Data objects support the rich display protocol of IPython, with HTML display of a table of information highlighting the relevant data. Examples can be found at [NoteBook].

References

Examples

Create a data set representing the independent axis (x) and dependent axis (y) then filter to select only those values between 500-520 and 530-700:

>>> import numpy as np
>>> x = np.arange(1000)
>>> y = np.random.normal(size=1000)
>>> d1 = Data1D('example', x, y)
>>> d1.notice(500, 700)
>>> d1.ignore(520, 530)

Classes

Data(name, indep, y[, staterror, syserror])

Generic, N-Dimensional data sets.

Data1D(name, x, y[, staterror, syserror])

Dateset for 1D data.

Data1DAsymmetricErrs(name, x, y, elo, ehi[, ...])

1-D data set with asymmetric errors

Data1DInt(name, xlo, xhi, y[, staterror, ...])

1-D integrated data set.

Data2D(name, x0, x1, y[, shape, staterror, ...])

2D data set

Data2DInt(name, x0lo, x1lo, x0hi, x1hi, y[, ...])

2-D integrated data set

DataSimulFit(name, datasets[, numcores])

Store multiple data sets.

BaseData()

Base class for all data classes.

DataSpace1D(filter, x)

Class for representing 1-D Data Space.

DataSpace2D(filter, x0, x1)

Class for representing 2-D Data Spaces.

DataSpaceND(filter, indep)

Class for representing arbitray N-Dimensional data domains

Filter()

A class for representing filters of N-Dimensional datasets.

IntegratedDataSpace1D(filter, xlo, xhi)

Same as DataSpace1D, but for supporting integrated data sets.

IntegratedDataSpace2D(filter, x0lo, x1lo, ...)

Same as DataSpace2D, but for supporting integrated data sets.

Class Inheritance Diagram

Inheritance diagram of BaseData, Data, Data1D, Data1DAsymmetricErrs, Data1DInt, Data2D, Data2DInt, DataSimulFit

Inheritance diagram of DataSpace1D, DataSpace2D, DataSpaceND, IntegratedDataSpace1D, IntegratedDataSpace2D