From cdd107adb92d15d7b1bc627a857f6a6531ef4c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sierro?= Date: Wed, 16 Aug 2023 16:09:17 +0200 Subject: [PATCH] change: improved coherence --- src/scgenerator/physics/pulse.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scgenerator/physics/pulse.py b/src/scgenerator/physics/pulse.py index c32f013..db716da 100644 --- a/src/scgenerator/physics/pulse.py +++ b/src/scgenerator/physics/pulse.py @@ -716,7 +716,7 @@ def spectrogram( return spec -def g12(values: np.ndarray, axis: int = 0): +def g12(values: np.ndarray, axis: int = 0, rel_cutoff: float = 1e-16) -> np.ndarray: """ computes the first order coherence function of a ensemble of values @@ -725,7 +725,9 @@ def g12(values: np.ndarray, axis: int = 0): values : np.ndarray, shape (..., n, nt) complex values following sc-ordering axis : int, optional - axis to collapse on which to compute the coherence + axis to collapse on which to compute the coherence, by default 0 + rel_cutoff : float, optional + relative mean spectrum intensity above which to compute coherence Returns ------- @@ -736,7 +738,7 @@ def g12(values: np.ndarray, axis: int = 0): n = len(values) mean_spec = np.mean(math.abs2(values), axis=axis) corr = np.zeros_like(mean_spec, dtype=complex) - mask = mean_spec > 1e-15 * mean_spec.max() + mask = mean_spec > rel_cutoff * mean_spec.max() corr[mask] = _g12_fast(values[..., mask]) corr[mask] = corr[mask] / (n * (n - 1) / 2 * mean_spec[mask]) return np.abs(corr)