Calculate summed spectrum according to starting and ending positions.
| 928 | |
| 929 | |
| 930 | class SpectrumCalculator(object): |
| 931 | """ |
| 932 | Calculate summed spectrum according to starting and ending positions. |
| 933 | |
| 934 | """ |
| 935 | |
| 936 | def __init__(self, *, pt_start=None, pt_end=None, mask=None): |
| 937 | """ |
| 938 | Initialize the class. The spatial ROI selection and the mask are applied |
| 939 | to the data. |
| 940 | |
| 941 | Parameters |
| 942 | ---------- |
| 943 | pt_start: iterable(int) or None |
| 944 | indexes of the beginning of the selection: `(row_start, col_start)`. |
| 945 | `row_start` is in the range `0..n_rows-1`, |
| 946 | `col_start` is in the range `0..n_cols-1`. |
| 947 | The point `col_start` is not included in the selection |
| 948 | pt_end: iterable(int) or None |
| 949 | indexes of the beginning of the selection: `(row_end, col_end)`. |
| 950 | `row_end` is in the range `1..n_rows`, |
| 951 | `col_end` is in the range `1..n_cols`. |
| 952 | The point `col_end` is not included in the selection. |
| 953 | If `pt_end` is None, then `pt_start` MUST be None. |
| 954 | mask: ndarray(float) or None |
| 955 | the mask that is applied to the data, shape (n_rows, n_cols) |
| 956 | """ |
| 957 | |
| 958 | def _validate_point(v): |
| 959 | v_out = None |
| 960 | if v is not None: |
| 961 | if isinstance(v, Iterable) and len(list(v)) == 2: |
| 962 | v_out = list(v) |
| 963 | else: |
| 964 | logger.warning( |
| 965 | "SpectrumCalculator.__init__(): Spatial ROI selection " |
| 966 | f"point '{v}' is invalid. Using 'None' instead." |
| 967 | ) |
| 968 | return v_out |
| 969 | |
| 970 | self._pt_start = _validate_point(pt_start) |
| 971 | self._pt_end = _validate_point(pt_end) |
| 972 | |
| 973 | # Validate 'mask' |
| 974 | if mask is not None: |
| 975 | if not isinstance(mask, np.ndarray): |
| 976 | logger.warning( |
| 977 | f"SpectrumCalculator.__init__(): type of parameter 'mask' must by np.ndarray, " |
| 978 | f"type(mask) = {type(mask)}. Using mask=None instead." |
| 979 | ) |
| 980 | mask = None |
| 981 | elif mask.ndim != 2: |
| 982 | logger.warning( |
| 983 | f"SpectrumCalculator.__init__(): the number of dimensions " |
| 984 | "in ndarray 'mask' must be 2, " |
| 985 | f"mask.ndim = {mask.ndim}. Using mask=None instead." |
| 986 | ) |
| 987 | mask = None |