From 1dde47a2e136fbe5da6bb1ac8aa996c4a960c3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sierro?= Date: Wed, 16 Aug 2023 16:07:42 +0200 Subject: [PATCH] change: improved Spectrum robustness --- src/scgenerator/spectra.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/scgenerator/spectra.py b/src/scgenerator/spectra.py index 6ecb6b8..a76841d 100644 --- a/src/scgenerator/spectra.py +++ b/src/scgenerator/spectra.py @@ -37,6 +37,12 @@ class Spectrum(np.ndarray): obj.l = params.compute("l") obj.ifft = params.compute("ifft") + if not (len(obj.w) == len(obj.t) == len(obj.l) == obj.shape[-1]): + raise ValueError( + f"shape mismatch when creating Spectrum object. input shape: {obj.shape}, " + f"len(w) = {len(obj.w)}, len(t) = {len(obj.t)}, len(l) = {len(obj.l)}" + ) + # Finally, we must return the newly created object: return obj @@ -117,6 +123,10 @@ class Spectrum(np.ndarray): return np.array([s.wl_max for s in self]) def mask_wl(self, pos: float, width: float) -> Spectrum: + """ + Filters the spectrum with a bandpass centered at `pos` of FWHM `width`. + The FWHM is taken on the intensity profile, not on the complex amplitude + """ return self * np.exp(-(((self.l - pos) / (pulse.fwhm_to_T0_fac["gaussian"] * width)) ** 2)) def measure(self) -> tuple[float, float, float]: