From 7a4d6d1b10bce47e601c10e19c484281ce8ae1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sierro?= Date: Wed, 1 Sep 2021 09:11:59 +0200 Subject: [PATCH] no more alert, added rin curve and propagation --- src/scgenerator/cli/cli.py | 20 +++++++++--------- src/scgenerator/physics/pulse.py | 8 +++++-- src/scgenerator/spectra.py | 36 +++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/scgenerator/cli/cli.py b/src/scgenerator/cli/cli.py index ff66523..a7f465e 100644 --- a/src/scgenerator/cli/cli.py +++ b/src/scgenerator/cli/cli.py @@ -149,16 +149,16 @@ def run_sim(args): method = prep_ray() run_simulation_sequence(*args.configs, method=method) - if sys.platform == "darwin" and sys.stdout.isatty(): - subprocess.run( - [ - "osascript", - "-e", - 'tell app "System Events" to display dialog "simulation finished !"', - ], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ) + # if sys.platform == "darwin" and sys.stdout.isatty(): + # subprocess.run( + # [ + # "osascript", + # "-e", + # 'tell app "System Events" to display dialog "simulation finished !"', + # ], + # stdout=subprocess.DEVNULL, + # stderr=subprocess.DEVNULL, + # ) def merge(args): diff --git a/src/scgenerator/physics/pulse.py b/src/scgenerator/physics/pulse.py index d1b086b..11fccb1 100644 --- a/src/scgenerator/physics/pulse.py +++ b/src/scgenerator/physics/pulse.py @@ -1013,14 +1013,18 @@ def rin_curve(spectra: np.ndarray) -> np.ndarray: ---------- spectra : np.ndarray, shape (n, nt) a collection of n spectra from which to compute the RIN + complex amplitude is automatically converted to intensity Returns ------- rin_curve : np.ndarray RIN curve """ - A2 = abs2(spectra) - return np.std(A2, axis=0) / np.mean(A2, axis=0) + if np.iscomplexobj(spectra): + A2 = abs2(spectra) + else: + A2 = spectra + return np.std(A2, axis=-2) / np.mean(A2, axis=-2) def measure_field(t: np.ndarray, field: np.ndarray) -> Tuple[float, float, float]: diff --git a/src/scgenerator/spectra.py b/src/scgenerator/spectra.py index ed1897a..b38ae50 100644 --- a/src/scgenerator/spectra.py +++ b/src/scgenerator/spectra.py @@ -10,7 +10,12 @@ from . import initialize, io, math from .const import SPECN_FN from .logger import get_logger from .physics import pulse, units -from .plotting import mean_values_plot, propagation_plot, single_position_plot +from .plotting import ( + mean_values_plot, + propagation_plot, + single_position_plot, + transform_2D_propagation, +) from .utils.parameter import BareParams @@ -358,6 +363,35 @@ class Pulse(Sequence): vals = vals[sim_ind] return plt_range, vals + def rin_propagation( + self, left: float, right: float, unit: str + ) -> tuple[np.ndarray, np.ndarray, np.ndarray]: + """returns the RIN as function of unit and z + + Parameters + ---------- + left : float + left limit in unit + right : float + right limit in unit + unit : str + unit descriptor + + Returns + ------- + x : np.ndarray, shape (nt,) + x axis + y : np.ndarray, shape (z_num, ) + y axis + rin_prop : np.ndarray, shape (z_num, nt) + RIN + """ + spectra = [] + for spec in np.moveaxis(self.all_spectra(), 1, 0): + x, z, tmp = transform_2D_propagation(spec, (left, right, unit), self.params, False) + spectra.append(tmp) + return x, z, pulse.rin_curve(np.moveaxis(spectra, 0, 1)) + def z_ind(self, z: float) -> int: """return the closest z index to the given target