Filter
- class sherpa.data.Filter[source] [edit on github]
Bases:
object
A class for representing filters of N-Dimensional datasets.
The filter does not know the size of the dataset or the values of the independent axes.
Attributes Summary
Mask array for dependent variable
Methods Summary
apply
()Apply this filter to an array
notice
(mins, maxes, axislist[, ignore, ...])Select a range to notice or ignore (remove).
Attributes Documentation
- mask
Mask array for dependent variable
- Returns:
mask
- Return type:
Methods Documentation
- apply(array: None) None [source] [edit on github]
- apply(array: Sequence[float] | ndarray) ndarray
Apply this filter to an array
- Parameters:
array (array_like or None) – Array to be filtered
- Returns:
array_like
- Return type:
ndarray or None
- Raises:
sherpa.utils.err.DataErr – The filter has removed all elements or there is a mismatch between the
mask
and thearray
argument.
See also
- notice(mins: Sequence[float] | ndarray, maxes: Sequence[float] | ndarray, axislist: Sequence[Sequence[float] | ndarray], ignore: bool = False, integrated: bool = False) None [source] [edit on github]
Select a range to notice or ignore (remove).
The
axislist
argument is expected to be sent the independent axis of aData
object - so(x, )
for one-dimensional data,(xlo, xhi)
for integrated one-dimensional data,(x0, x1)
for two-dimensional data, and(x0lo, x1lo, x0hi, x1hi)
for integrated two-dimensinal data. Themins
andmaxes
must then be set to match this ordering.- Parameters:
mins (sequence of values) – The minimum value of the valid range (elements may be None to indicate no lower bound). When not None, it is treated as an inclusive limit, so points >= min are included.
maxes (sequence of values) – The maximum value of the valid range (elements may be None to indicate no upper bound). It is treated as an inclusive limit (points <= max) when integrated is False, and an exclusive limit (points < max) when integrated is True.
axislist (sequence of arrays) – The axis to apply the range to. There must be the same number of elements in mins, maxes, and axislist. The number of elements of each element of axislist must also agree (the cell values do not need to match).
ignore (bool, optional) – If True the range is to be ignored, otherwise it is included. The default is to include the range.
integrated (bool, optional) – Is the data integrated (we have low and high bin edges)? The default is False. When True it is expected that axislist contains a even number of rows, where the odd values are the low edges and the even values the upper edges, and that the mins and maxes only ever contain a single value, given in (None, hi) and (lo, None) ordering.
See also
Examples
Select points in xs which are in the range 1.5 <= x <= 4:
>>> f = Filter() >>> f.mask True >>> xs = [1, 2, 3, 4, 5] >>> f.notice([1.5], [4], (xs, )) >>> f.mask array([False, True, True, True, False])
Filter the data to select all points with x0 >= 1.5 and x1 <= 4:
>>> f = Filter() >>> x0 = [1, 1.4, 1.6, 2, 3] >>> x1 = [2, 2, 4, 4, 6] >>> f.notice([1.5, None], [None, 4], (x0, x1)) >>> f.mask array([False, False, True, True, False])
For integrated data sets the lower and upper edges should be sent separately with the max and min limits, along with setting the integrated flag. The following selects the bins that cover the range 2 to 4 and 1.5 to 3.5:
>>> xlo = [1, 2, 3, 4, 5] >>> xhi = [2, 3, 4, 5, 6] >>> f = Filter() >>> f.notice([None, 2], [4, None], (xlo, xhi), integrated=True) >>> f.mask array([False, True, True, False, False]) >>> f.notice([None, 1.5], [3.5, None], (xlo, xhi), integrated=True) >>> f.mask array([ True, True, True, False, False])