change: improved Spectrum robustness

This commit is contained in:
Benoît Sierro
2023-08-16 16:07:42 +02:00
parent 3f64b669d5
commit 1dde47a2e1

View File

@@ -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]: