Data2DInt
- class sherpa.data.Data2DInt(name: str, x0lo: Sequence[float] | ndarray | None, x1lo: Sequence[float] | ndarray | None, x0hi: Sequence[float] | ndarray | None, x1hi: Sequence[float] | ndarray | None, y: Sequence[float] | ndarray | None, shape: Sequence[int] | None = None, staterror: Sequence[float] | ndarray | None = None, syserror: Sequence[float] | ndarray | None = None)[source] [edit on github]
Bases:
Data2D2-D integrated data set
This class represents a 2D data set. It is desigend to work with flattened arrays for coordinates and independent variables, which makes it easy to deal with filters and sparse or irregularly-placed grids.
Of course, the same structure can also be used for regularly-gridded data, it just has to be passed in as a flattened array. However, in this case the more specialiazed
DataIMGIntclass might be more appropriate.- Parameters:
- name
str name of this dataset
- x0loarray_like
Lower bounds of the bins in the first dimension of the independent coordinate
- x1loarray_like
Lower bound of the bins in the second dimension of the independent coordinate
- x0hiarray_like
Upper bound of the bins in the first dimension of the independent coordinate
- x1hiarray_like
Upper bound of the bins in the second dimension of the independent coordinate
- yarray_like
The values of the dependent observable. If this is a numpy masked array, the mask will be used to initialize a mask.
- shape
tuple Shape of the data grid for regularly gridded data (optional). This is used return the data as an image e.g. for display, but it not needed for fitting and modelling. For irregularly gridded data, shape must be
None.- 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.
x0kept for compatibility
x0hiProperty kept for compatibility
x0loProperty kept for compatibility
x1kept for compatibility
x1hiProperty kept for compatibility
x1loProperty 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_img([yfunc])Return the dependent axis as a 2D array.
get_indep([filter])Return the independent axes of a data set.
get_max_pos([dep])Return the coordinates of the maximum value.
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.
Return label for first dimension in 2-D view of independent axis/axes.
Return label for second dimension in 2-D view of independent axis/axes.
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.
set_dep(val)Set the dependent variable values.
set_x0label(label)Set the label for the first independent axis.
set_x1label(label)Set the label for the second independent axis.
set_ylabel(label)Set the label for the dependent axis.
apply_filter
get_filter
get_filter_expr
get_imgerr
get_x0
get_x1
ignore
notice
set_indep
to_contour
to_fit
to_guess
Examples
Create an irregularly-gridded 2D dataset that has measurements in three areas of different size. The first is in a box of size 10 centered on (-15, -20), the second is a small rectangle centered on (0, 0), and the third another rectangle. The measured data values in these areas are 12, 15 and 23.
>>> x0lo = [-20, -1, 10] >>> x1lo = [-25, -1, -10] >>> x0hi = [-10, 1, 15] >>> x1hi = [-10, 1, -8] >>> y = [12, 15, 23] >>> three_rect = Data2DInt("irregular2d_binned", x0lo=x0lo, x1lo=x1lo, ... x0hi=x0hi, x1hi=x1hi, y=y)
The regular version of this might represent a binned image, here with square pixels. In this example, we create
x1, x0arrays that represent the pixel center, but need to pass in the pixel edges to make the data object:>>> import numpy as np >>> x1, x0 = np.mgrid[20:30, 5:20] >>> datashape = x0.shape >>> y = np.sqrt((x0 - 10)**2 + (x1 - 31)**2) >>> x0 = x0.flatten() >>> x1 = x1.flatten() >>> y = y.flatten() >>> image = Data2DInt("binned_image", x0lo=x0 - 0.5, x1lo=x1 - 0.5, ... x0hi=x0 + 0.5, x1hi=x1 + 0.5, y=y, shape=datashape)
Note
Sherpa provides the
DataIMGIntclass to make it easier to work with regularly-gridded data.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.
kept for compatibility
Property kept for compatibility
Property kept for compatibility
kept for compatibility
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_img([yfunc])Return the dependent axis as a 2D array.
get_indep([filter])Return the independent axes of a data set.
get_max_pos([dep])Return the coordinates of the maximum value.
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_x0([filter])Return label for first dimension in 2-D view of independent axis/axes.
get_x1([filter])Return label for second dimension in 2-D view of independent axis/axes.
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([x0lo, x0hi, x1lo, x1hi, ignore])set_dep(val)Set the dependent variable values.
set_indep(val)set_x0label(label)Set the label for the first independent axis.
set_x1label(label)Set the label for the second independent axis.
set_ylabel(label)Set the label for the dependent axis.
to_contour([yfunc])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
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.
- x0
kept for compatibility
- x0hi
Property kept for compatibility
- x0lo
Property kept for compatibility
- x1
kept for compatibility
- x1hi
Property kept for compatibility
- x1lo
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_filter() str [edit on github]
- get_filter_expr() str [edit on github]
- get_img(yfunc=None) [edit on github]
Return the dependent axis as a 2D array.
The data is not filtered.
- Parameters:
- yfunc
sherpa.models.model.ModelinstanceorNone,optional If set then it is a model that is evaluated on the data grid and returned along with the dependent axis.
- 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_max_pos(dep: ndarray | None = None) tuple[float, float] | list[tuple[float, float]] [edit on github]
Return the coordinates of the maximum value.
- Parameters:
- Returns:
- 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_x0label() str [edit on github]
Return label for first dimension in 2-D view of independent axis/axes.
- Returns:
- label:
str
- label:
See also
- get_x1(filter=False) ndarray | None[source] [edit on github]
- get_x1label() str [edit on github]
Return label for second dimension in 2-D view of independent axis/axes. Returns ——- label: str
See also
- get_y(filter=False, yfunc=None, use_evaluation_space=False) [edit on github]
Return dependent axis in N-D view of dependent variable
- 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(x0lo: float | None = None, x0hi: float | None = None, x1lo: float | None = None, x1hi: float | None = None, ignore: bool = False) None[source] [edit on github]
- 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_x0label(label: str) None [edit on github]
Set the label for the first independent axis.
Added in version 4.17.0.
- Parameters:
- label: str
See also
- set_x1label(label: str) None [edit on github]
Set the label for the second independent axis.
Added in version 4.17.0.
- Parameters:
- label: str
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_contour(yfunc=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]