create_expr¶
-
sherpa.utils.
create_expr
(vals, mask=None, format='%s', delim='-')[source] [edit on github]¶ Create a string representation of a filter.
Use the mask to convert the input values into a set of comma-separated filters - low value and high value, separated by the delimeter - that represent the data. If the mask is not given then the values must be “channel” values (that is, two values are consecutive if there difference is 1).
- Parameters
vals (sequence) – The values that represent the sequence if mask is not None, otherwise the selected channel numbers (in this case integer values).
mask (sequence of bool or None, optional) – The mask setting for the full dataset, without any filtering applied. A value of True indicates the element is included and False means it is excluded.
format (str, optional) – The format used to display each value.
delim (str, optional) – The separator for a range.
- Raises
ValueError – If the
vals
andmask
sequences do not match: the length ofvals
must equal the number of True values inmask
.
Examples
>>> create_expr([1, 2, 3, 4]) '1-4'
>>> create_expr([1, 2, 4, 5, 7]) '1-2,4-5,7'
>>> create_expr([1, 2, 3, 4], [True, True, True, True]) '1-4'
>>> create_expr([0.1, 0.2, 0.4, 0.8], [True, True, True, True]) '0.1-0.8'
>>> create_expr([0.1, 0.2, 0.4, 0.8], [True, True, True, False, False, True]) '0.1-0.4,0.8'