Data1DInt
- class sherpa.data.Data1DInt(name: str, xlo: Sequence[float] | ndarray | None, xhi: Sequence[float] | ndarray | None, y: Sequence[float] | ndarray | None, staterror: Sequence[float] | ndarray | None = None, syserror: Sequence[float] | ndarray | None = None)[source] [edit on github]
Bases:
Data1D1-D integrated data set.
This class is designed to handle non-consecutive bins.
- Parameters:
- name
str name of this dataset
- xloarray_like
lower bounds of the bins of the independent coordinates
- xhiarray_like
Upper bound of the bins of the independent coordinates
- yarray_like
The values of the dependent observable. If this is a numpy masked array, the mask will used to initialize a mask.
- staterrorarray_like
the statistical error associated with the data
- syserrorarray_like
the systematic error associated with the data
- name
- Attributes:
depLeft for compatibility with older versions
indepThe grid of the data space associated with this data set.
maskMask array for dependent variable
sizeThe number of elements in the data set.
staterrorThe statistical error on the dependent axis, if set.
syserrorThe systematic error on the dependent axis, if set.
xUsed for compatibility, in particular for __str__ and __repr__
xhiProperty kept for compatibility
xloProperty kept for compatibility
yThe dependent axis.
Methods
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([filter])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_filter([format, delim])Return the data filter as a string.
Return the data filter as a string along with the units.
get_img([yfunc])Return 1D dependent variable as a 1 x N image.
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 systematic error on the dependent axis of a data set.
get_xerr([filter, model])Returns an X "error".
Return label for linear view of independent axis/axes
get_y([filter, yfunc, use_evaluation_space])Return the dependent axis.
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.
notice([xlo, xhi, ignore])Notice or ignore the given range.
set_dep(val)Set the dependent variable values.
set_xlabel(label)Set the label for the independent axis.
set_ylabel(label)Set the label for the dependent axis.
to_component_plot([yfunc, staterrfunc])to_plot([yfunc, staterrfunc])Get arrays required to make plots
apply_filter
get_bounding_mask
get_evaluation_indep
get_imgerr
get_x
ignore
set_indep
to_fit
to_guess
Attributes Summary
Left for compatibility with older versions
The grid of the data space associated with this data set.
Mask array for dependent variable
The dimensionality of the dataset, if defined, or None.
The number of elements in the data set.
The statistical error on the dependent axis, if set.
The systematic error on the dependent axis, if set.
Used for compatibility, in particular for __str__ and __repr__
Property kept for compatibility
Property kept for compatibility
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([filter])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_evaluation_indep([filter, model, ...])get_filter([format, delim])Return the data filter as a string.
Return the data filter as a string along with the units.
get_img([yfunc])Return 1D dependent variable as a 1 x N image.
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 systematic error on the dependent axis of a data set.
get_x([filter, model, use_evaluation_space])get_xerr([filter, model])Returns an X "error".
Return label for linear view of independent axis/axes
get_y([filter, yfunc, use_evaluation_space])Return the dependent axis.
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([xlo, xhi, ignore])Notice or ignore the given range.
set_dep(val)Set the dependent variable values.
set_indep(val)set_xlabel(label)Set the label for the independent axis.
set_ylabel(label)Set the label for the dependent axis.
to_component_plot([yfunc, staterrfunc])to_fit([staterrfunc])to_guess()to_plot([yfunc, staterrfunc])Get arrays required to make plots
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
noticeandignoreis now cleared when the independent axis is changed.- Returns:
tupleofarray_like orNone
- mask
Mask array for dependent variable
- Returns:
- maskbool or
numpy.ndarray
- maskbool or
- size
The number of elements in the data set.
- 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.
- x
Used for compatibility, in particular for __str__ and __repr__
- xhi
Property kept for compatibility
- xlo
Property kept for compatibility
- y
The dependent axis.
If set, it must match the size of the independent axes.
Methods Documentation
- eval_model(modelfunc: Callable[[...], Sequence[float] | ndarray]) Sequence[float] | ndarray [edit on github]
Evaluate the model on the independent axis.
- eval_model_to_fit(modelfunc: Callable[[...], Sequence[float] | ndarray]) Sequence[float] | ndarray [edit on github]
Evaluate the model on the independent axis after filtering.
- get_dep(filter: bool = False) ndarray | None [edit on github]
Return the dependent axis of a data set.
- Parameters:
- Returns:
- axis:
array The dependent axis values for the data set. This gives the value of each point in the data set.
- axis:
See also
get_indepReturn the independent axis of a data set.
get_errorReturn the errors on the dependent axis of a data set.
get_staterrorReturn the statistical errors on the dependent axis of a data set.
get_syserrorReturn the systematic errors on the dependent axis of a data set.
- get_dims(filter: bool = False) tuple[int, ...] [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.
- Returns:
- get_error(filter=False, staterrfunc=None) [edit on github]
Return the total error on the dependent variable.
- Parameters:
- Returns:
See also
get_depReturn the independent axis of a data set.
get_staterrorReturn the statistical errors on the dependent axis of a data set.
get_syserrorReturn the systematic errors on the dependent axis of a data set.
- get_evaluation_indep(filter: bool = False, model: Callable[[...], Sequence[float] | ndarray] | None = None, use_evaluation_space: bool = False) ndarray | None [edit on github]
- get_filter(format='%.4f', delim=':') str[source] [edit on github]
Return the data filter as a string.
For each noticed range the filter is reported as starting at the low edge of the first bin and ends at the upper edge of the last bin in the range.
Changed in version 4.14.0: Prior to 4.14.0 the filter used the mid-point of the bin, not its low or high value.
- Parameters:
- Returns:
- filter
str The filter, represented as a collection of ranges separated by commas.
- filter
See also
Examples
>>> import numpy as np >>> xlo = np.asarray([1, 2, 3, 5, 6]) >>> xhi = xlo + 1 >>> y = np.ones(5) >>> d = Data1DInt('example', xlo, xhi, y) >>> d.get_filter() '1.0000:7.0000' >>> d.ignore(2.5, 4.5) >>> d.get_filter() '1.0000:2.0000,5.0000:7.0000'
>>> d.get_filter(format='%i', delim='-') '1-2,5-7'
- get_filter_expr() str [edit on github]
Return the data filter as a string along with the units.
This is a specialised version of get_filter which adds the axis units.
- Returns:
- filter
str The filter, represented as a collection of single values or ranges, separated by commas.
- filter
See also
Examples
>>> d = Data1D('example', [1., 2., 3., 5., 6., 7.], [0, .4, .5, .6, .7, .8]) >>> d.notice(1., 6.) >>> d.ignore(2.5, 4.) >>> d.get_filter_expr() '1.0000-2.0000,5.0000-6.0000 x'
Note that the expression lists the valid data points. While we ignore only the range 2.5-4.0, there is no data point between 4. and 5., so the second part of the valid range is 5.0 to 6.0.
- get_img(yfunc=None) [edit on github]
Return 1D dependent variable as a 1 x N image.
- Parameters:
- yfunc
- Returns:
- get_imgerr() [edit on github]
- get_indep(filter: bool = False) tuple[ndarray, ...] | tuple[None, ...] [edit on github]
Return the independent axes of a data set.
- Parameters:
- Returns:
- axis:
tupleofarrays The independent axis values for the data set. This gives the coordinates of each point in the data set.
- axis:
See also
get_depReturn the dependent axis of a data set.
- get_staterror(filter: bool = False, staterrfunc: Callable[[Sequence[float] | ndarray], Sequence[float] | ndarray] | None = None) Sequence[float] | ndarray | None [edit on github]
Return the statistical error on the dependent axis of a data set.
- Parameters:
- Returns:
See also
get_errorReturn the errors on the dependent axis of a data set.
get_indepReturn the independent axis of a data set.
get_syserrorReturn the systematic errors on the dependent axis of a data set.
- get_syserror(filter: bool = False) ndarray | None [edit on github]
Return the systematic error on the dependent axis of a data set.
- Parameters:
- Returns:
See also
get_errorReturn the errors on the dependent axis of a data set.
get_indepReturn the independent axis of a data set.
get_staterrorReturn the statistical errors on the dependent axis of a data set.
- get_x(filter: bool = False, model: Callable[[...], Sequence[float] | ndarray] | None = None, use_evaluation_space: bool = False) ndarray[source] [edit on github]
- get_xerr(filter: bool = False, model: Callable[[...], Sequence[float] | ndarray] | None = None) ndarray | None[source] [edit on github]
Returns an X “error”.
The error value for the independent axis is not well defined in Sherpa.
Changed in version 4.16.1: The return value is now half the bin width instead of the full bin width.
- get_xlabel() str [edit on github]
Return label for linear view of independent axis/axes
- Returns:
- label
str
- label
See also
- get_y(filter=False, yfunc=None, use_evaluation_space=False) [edit on github]
Return the dependent axis.
- get_yerr(filter=False, staterrfunc=None) [edit on github]
Return errors in dependent axis in N-D view of dependent variable.
- Parameters:
- filter
- staterrfunc
- Returns:
- get_ylabel(yfunc=None) str [edit on github]
Return label for dependent axis in N-D view of dependent variable.
- Parameters:
- yfunc
Unused.
- Returns:
- label:
str The label.
- label:
See also
- ignore(*args, **kwargs) None [edit on github]
- notice(xlo: float | None = None, xhi: float | None = None, ignore: bool = False) None[source] [edit on github]
Notice or ignore the given range.
Ranges are inclusive for the lower limit and exclusive for the upper limit.
Changed in version 4.14.0: Filtering Data1DInt datasets has been improved to fix a number of corner cases. As part of this the upper limit has been changed to be exclusive whereas previously it was not obvious what the filter was doing.
- Parameters:
See also
Notes
If no ranges have been ignored then a call to
noticewithignore=Falsewill select just thelotohirange, and exclude any bins outside this range. If there has been a filter applied then the rangelotohiwill be added to the range of noticed data (whenignore=False).Examples
>>> import numpy as np >>> edges = np.arange(0.4, 2.6, 0.2) >>> xlo, xhi = edges[:-1], edges[1:] >>> y = np.ones_like(xlo) >>> d = Data1DInt('example', xlo, xhi, y) >>> print(d.xlo[0], d.xhi[-1]) 0.4 2.400000000000001 >>> d.get_filter(format='%.1f') '0.4:2.4' >>> d.notice(0.8, 1.9) >>> d.get_filter(format='%.1f') '0.8:2.0'
>>> d.notice() >>> d.get_filter(format='%.1f') '0.4:2.4'
- set_dep(val: Sequence[float] | ndarray | float) None [edit on github]
Set the dependent variable values.
- Parameters:
- valsequence or
number If a number then it is used for each element.
- valsequence or
- set_xlabel(label: str) None [edit on github]
Set the label for the independent axis.
Added in version 4.17.0.
- Parameters:
- label
str The new label.
- label
See also
- set_ylabel(label: str) None [edit on github]
Set the label for the dependent axis.
Added in version 4.17.0.
- Parameters:
- label: str
The new label.
See also
- to_component_plot(yfunc: Callable[[...], Sequence[float] | ndarray] | None = None, staterrfunc: Callable[[Sequence[float] | ndarray], Sequence[float] | ndarray] | None = None) [edit on github]
- to_fit(staterrfunc: Callable[[Sequence[float] | ndarray], Sequence[float] | ndarray] | None = None) tuple[ndarray | None, Sequence[float] | ndarray | None, ndarray | None] [edit on github]
- to_guess() tuple[ndarray | None, ...] [edit on github]
- to_plot(yfunc: Callable[[...], Sequence[float] | ndarray] | None = None, staterrfunc: Callable[[Sequence[float] | ndarray], Sequence[float] | ndarray] | None = None) [edit on github]
Get arrays required to make plots
This method returns all the ingredients to make a plot of the data. It’s used internally in Sherpa in the plotting functions, but can also be called by users to obtain just the arrays to perform the plotting themselves, for example with a different plotting package than supported by Sherpa.
- Parameters:
- yfunc
callable()orNone,optional If
Nonethe binned and filtered data values are returned. Ifyfuncis a function, this function is called with the bin positions and the return values of that function are also returned. The purpose of this is to obtain model values evaluated on the data grid.- staterrfunc
callable()orNone,optional If no statistical error has been set, the errors will be calculated by applying this function to the dependent axis of the data set.
- yfunc
- Returns:
- x
ndarray Bin mid-points after applying the filter
- y
ndarrayortupleoftwoarrays Values in each bin for data. If
yfuncis given, then this is a tuple of two arrays, where the first array holds the data and the second array the evaluatedyfunc.- yerr
ndarray Uncertainties for the data values
- xerr
ndarray Half-width of each bin
- xlabel
str Label for the x axis
- ylabel
str Label for the y axis
- x