parse_expr¶
- sherpa.utils.parse_expr(expr)[source] [edit on github]¶
Convert a filter expression into its parts.
This is intended for parsing a notice or ignore expression given as a string.
- Parameters
expr (str) – The filter expression, of the form ‘a:b’ or a single number, separated by commas, and white space is ignored. The upper or lower limit of a pair may be ignored (e.g. ‘a:’ or ‘:b’).
- Returns
filters – Each pair gives the lower- and upper-edge of the filter, using
None
to represent no limit.- Return type
list of pairs
Notes
There is no attempt to validate that the expression contains strictly ordered pairs, or that the pairs do not overlap, or that the lower- and upper-limits are in increasing numerical order. That is, the expression ‘5:7,:2,4:6,5:3’ is allowed.
Examples
>>> parse_expr('0.5:7') [(0.5, 7.0)]
>>> parse_expr('0.5:') [(0.5, None)]
>>> parse_expr(':7') [(None, 7.0)]
>>> parse_expr(':2, 4 : 5 ,7:8,10:') [(None, 2.0), (4.0, 5.0), (7.0, 8.0), (10.0, None)]
>>> parse_expr('4') [(4.0, 4.0)]
>>> parse_expr(' ') [(None, None)]