diff --git a/src/scgenerator/cli/cli.py b/src/scgenerator/cli/cli.py index 3fef98a..42807b4 100644 --- a/src/scgenerator/cli/cli.py +++ b/src/scgenerator/cli/cli.py @@ -137,16 +137,16 @@ def run_sim(args): method = prep_ray() run_simulation(args.config, 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 5c5aafd..001f292 100644 --- a/src/scgenerator/physics/pulse.py +++ b/src/scgenerator/physics/pulse.py @@ -1039,14 +1039,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 0d2f7b9..7bd0225 100644 --- a/src/scgenerator/spectra.py +++ b/src/scgenerator/spectra.py @@ -10,7 +10,12 @@ from . import 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 Parameters, PlotRange @@ -356,6 +361,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