formatting

This commit is contained in:
2024-04-29 08:55:23 +02:00
parent edadb4284b
commit ea65ead188
4 changed files with 24 additions and 31 deletions

View File

@@ -107,6 +107,7 @@ class Cache:
return data return data
wrapped.cached_only = cached_only wrapped.cached_only = cached_only
wrapped.func = func
return wrapped return wrapped

View File

@@ -259,20 +259,28 @@ class NoiseMeasurement:
time = np.arange(len(signal)) / fs time = np.arange(len(signal)) / fs
return time, signal return time, signal
def root_integrated(self) -> np.ndarray: def root_integrated(self, from_right: bool = True) -> np.ndarray:
""" """
returns the sqrt of the integrated spectrum returns the sqrt of the integrated spectrum
The 0th component is the total RIN in the frequency range covered by the measurement The 0th component is the total RIN in the frequency range covered by the measurement
Caution! this may be 0 frequency Caution! this may be 0 frequency
Parameters
----------
from_right : bool, optional
start integration at f[-1], by default True.
""" """
return integrated_noise(self.freq, self.psd) return integrated_noise(self.freq, self.psd, from_right)
def integrated_noise(freq: np.ndarray, psd: np.ndarray) -> float: def integrated_noise(freq: np.ndarray, psd: np.ndarray, from_right: bool = True) -> np.ndarray:
""" """
given a normalized spectrum, computes the total rms RIN in the provided frequency window given a normalized spectrum, computes the total rms RIN in the provided frequency window
""" """
return np.sqrt(cumulative_trapezoid(np.abs(psd)[::-1], -freq[::-1], initial=0)[::-1]) s = slice(None, None, -1) if from_right else slice(None)
return np.sqrt(
cumulative_trapezoid(np.abs(psd)[s], (1 - 2 * from_right) * freq[s], initial=0)[s]
)
def quantum_noise_limit(wavelength: float, power: float) -> float: def quantum_noise_limit(wavelength: float, power: float) -> float:

View File

@@ -58,9 +58,7 @@ def dispersion_parameter_to_beta2(dispersion_parameter: float, wavelength: T) ->
def dispersion_slope_to_beta3( def dispersion_slope_to_beta3(
dispersion_parameter: float, dispersion_slope: float, wavelength dispersion_parameter: float, dispersion_slope: float, wavelength
) -> float: ) -> float:
return (wavelength**2 / pi2c) ** 2 * ( return (wavelength**2 / pi2c) ** 2 * (dispersion_slope + 2 * dispersion_parameter / wavelength)
dispersion_slope + 2 * dispersion_parameter / wavelength
)
def handle_dispersion_parameter( def handle_dispersion_parameter(
@@ -598,18 +596,8 @@ def saitoh_paramters(pcf_pitch_ratio: float) -> tuple[float, float]:
di2 = np.array([9, 6.58, 10, 0.41]) di2 = np.array([9, 6.58, 10, 0.41])
di3 = np.array([10, 24.8, 15, 6]) di3 = np.array([10, 24.8, 15, 6])
A = ( A = ai0 + ai1 * pcf_pitch_ratio**bi1 + ai2 * pcf_pitch_ratio**bi2 + ai3 * pcf_pitch_ratio**bi3
ai0 B = ci0 + ci1 * pcf_pitch_ratio**di1 + ci2 * pcf_pitch_ratio**di2 + ci3 * pcf_pitch_ratio**di3
+ ai1 * pcf_pitch_ratio**bi1
+ ai2 * pcf_pitch_ratio**bi2
+ ai3 * pcf_pitch_ratio**bi3
)
B = (
ci0
+ ci1 * pcf_pitch_ratio**di1
+ ci2 * pcf_pitch_ratio**di2
+ ci3 * pcf_pitch_ratio**di3
)
return A, B return A, B

View File

@@ -179,20 +179,13 @@ class Spectrum(np.ndarray):
@property @property
def wl_amp(self): def wl_amp(self):
return ( return (np.sqrt(units.to_WL(math.abs2(self), self.l)) * self / np.abs(self))[
np.sqrt( ..., self.l_order
units.to_WL( ]
math.abs2(self),
self.l,
)
)
* self
/ np.abs(self)
)[..., self.l_order]
@property @property
def afreq_amp(self): def afreq_amp(self):
return self[..., self.w_order[::-1]] * self.spectrum_factor return self[..., self.w_order] * self.spectrum_factor
@property @property
def time_amp(self): def time_amp(self):
@@ -242,7 +235,10 @@ class Spectrum(np.ndarray):
band = peak * np.exp(-(((self.l - pos) / (pulse.fwhm_to_T0_fac["gaussian"] * width)) ** 2)) band = peak * np.exp(-(((self.l - pos) / (pulse.fwhm_to_T0_fac["gaussian"] * width)) ** 2))
if shot_noise: if shot_noise:
sn = np.reshape( sn = np.reshape(
[pulse.shot_noise(self.w, *shot_noise) for _ in range(np.prod(self.shape[:-1]))], [
pulse.shot_noise(self.w, *shot_noise)
for _ in range(np.prod(self.shape[:-1] + (1,)))
],
self.shape, self.shape,
) )
return self * band + np.sqrt(1 - band**2) * sn return self * band + np.sqrt(1 - band**2) * sn