(self, *, client=None)
| 870 | return self.raw_data.shape |
| 871 | |
| 872 | def _get_sum(self, *, client=None): |
| 873 | # Only the values of 'mask', 'pos1' and 'pos2' will be cached |
| 874 | mask = self.mask if self.mask_active else None |
| 875 | pt_start = self.sel_pt_start if self.selection_active else None |
| 876 | pt_end = self.sel_pt_end if self.selection_active else None |
| 877 | |
| 878 | def _compare_cached_settings(cache, pt_start, pt_end, mask): |
| 879 | if not cache: |
| 880 | return False |
| 881 | |
| 882 | # Verify that all necessary keys are in the dictionary |
| 883 | if not all([_ in cache.keys() for _ in ("pt_start", "pt_end", "mask", "spec")]): |
| 884 | return False |
| 885 | |
| 886 | if (cache["pt_start"] != pt_start) or (cache["pt_end"] != pt_end): |
| 887 | return False |
| 888 | |
| 889 | mask_none = [_ is None for _ in (mask, cache["mask"])] |
| 890 | if all(mask_none): # Mask is not applied in both cases |
| 891 | return True |
| 892 | elif any(mask_none): # Mask is applied only in one cases |
| 893 | return False |
| 894 | |
| 895 | # Mask is applied in both cases, so compare the masks |
| 896 | if not (cache["mask"] == mask).all(): |
| 897 | return False |
| 898 | |
| 899 | return True |
| 900 | |
| 901 | cache_valid = _compare_cached_settings(self._cached_spectrum, pt_start=pt_start, pt_end=pt_end, mask=mask) |
| 902 | |
| 903 | if cache_valid: |
| 904 | # We create copy to make sure that cache remains intact |
| 905 | logger.debug(f"Dataset '{self.filename}': using cached copy of the averaged spectrum ...") |
| 906 | # The following are references to cached objects. Care should be taken not to modify them. |
| 907 | spec = self._cached_spectrum["spec"] |
| 908 | count = self._cached_spectrum["count"] |
| 909 | else: |
| 910 | logger.debug( |
| 911 | f"Dataset '{self.filename}': computing the total spectrum and total count map from raw data ..." |
| 912 | ) |
| 913 | |
| 914 | SC = SpectrumCalculator(pt_start=pt_start, pt_end=pt_end, mask=mask) |
| 915 | spec, count = SC.get_spectrum(self.raw_data, client=client) |
| 916 | |
| 917 | # Save cache the computed spectrum (with all settings) |
| 918 | self._cached_spectrum["pt_start"] = pt_start.copy() if pt_start is not None else None |
| 919 | self._cached_spectrum["pt_end"] = pt_end.copy() if pt_end is not None else None |
| 920 | self._cached_spectrum["mask"] = mask.copy() if mask is not None else None |
| 921 | self._cached_spectrum["spec"] = spec.copy() |
| 922 | self._cached_spectrum["count"] = count.copy() |
| 923 | |
| 924 | self.data_ready = True |
| 925 | |
| 926 | # Return the 'sum' spectrum as regular 64-bit float (raw data is in 'np.float32') |
| 927 | return spec.astype(np.float64, copy=False), count.astype(np.float64, copy=False) |
| 928 | |
| 929 |
no test coverage detected