From 3a16b8788212d2fe54f2931b32ec63d6a6f01ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sierro?= Date: Mon, 11 Dec 2023 13:39:35 +0100 Subject: [PATCH] fixed HUGE bug with shot noise --- pyproject.toml | 2 +- src/scgenerator/physics/pulse.py | 25 ++----------------------- src/scgenerator/spectra.py | 2 +- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0c8a146..e465cae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "scgenerator" -version = "0.3.26" +version = "0.4.0" description = "Simulate nonlinear pulse propagation in optical fibers" readme = "README.md" authors = [{ name = "Benoit Sierro", email = "benoit.sierro@iap.unibe.ch" }] diff --git a/src/scgenerator/physics/pulse.py b/src/scgenerator/physics/pulse.py index 6856462..ca9de62 100644 --- a/src/scgenerator/physics/pulse.py +++ b/src/scgenerator/physics/pulse.py @@ -559,10 +559,11 @@ def finalize_pulse( dt: float, input_transmission: float, ) -> np.ndarray: + pre_field_0 *= np.sqrt(input_transmission) if quantum_noise: pre_field_0 = pre_field_0 + shot_noise(w, dt) - return np.sqrt(input_transmission) * pre_field_0 + return pre_field_0 def A_to_C(A: np.ndarray, effective_area_arr: np.ndarray) -> np.ndarray: @@ -614,29 +615,7 @@ def compress_pulse(spectra: np.ndarray): else: return fftshift(ifft(flatten_phase(spectra)), axes=1) -def shot_noise(w: np.ndarray, dt: float): - """ - Parameters - ---------- - w : array, shape (n,) - angular frequencies - dt : float - resolution of time grid - - Returns - ------- - np.ndarray, shape (n,) - noise field to be added on top of initial field in time domain - """ - dw = w[1] - w[0] - - rand_phase = np.random.rand(len(w)) * 2 * pi - shot_noise_phase = np.exp(-1j * rand_phase) - - shot_noise_amplitude = np.sqrt(0.5 * units.hbar * np.abs(w) / dw) - - return ifft(shot_noise_amplitude * shot_noise_phase / dt * np.sqrt(2 * pi)) def ideal_compressed_pulse(spectra: np.ndarray): """ returns the ideal compressed pulse assuming flat phase diff --git a/src/scgenerator/spectra.py b/src/scgenerator/spectra.py index f14cf1d..ef9888d 100644 --- a/src/scgenerator/spectra.py +++ b/src/scgenerator/spectra.py @@ -389,7 +389,7 @@ def propagation_series( convenient object to work with multiple propagations **built on the same grid** """ if isinstance(files, str) or not isinstance(files, Sequence): - files = sorted(Path(files).glob("*.zip"), key=logical_sort_key) + files = sorted(Path(files).expanduser().glob("*.zip"), key=logical_sort_key) if len(files) == 0: raise ValueError("You must provide at least one file to build a propagation series")