diff --git a/src/scgenerator/__init__.py b/src/scgenerator/__init__.py index 5de327a..c575341 100644 --- a/src/scgenerator/__init__.py +++ b/src/scgenerator/__init__.py @@ -1,7 +1,8 @@ # flake8: noqa from . import math +from .evaluator import Evaluator from .legacy import convert_sim_folder -from .math import abs2, argclosest, span +from .math import abs2, argclosest, normalized, span from .parameter import Configuration, Parameters from .physics import fiber, materials, pulse, simulate, units from .physics.simulate import RK4IP, parallel_RK4IP, run_simulation @@ -19,4 +20,3 @@ from .plotting import ( from .spectra import SimulationSeries, Spectrum from .utils import Paths, _open_config, open_single_config from .variationer import DescriptorDict, VariationDescriptor, Variationer, VariationSpecsError -from .evaluator import Evaluator diff --git a/src/scgenerator/math.py b/src/scgenerator/math.py index 2fd8ebc..45aaff0 100644 --- a/src/scgenerator/math.py +++ b/src/scgenerator/math.py @@ -77,6 +77,11 @@ def abs2(z: np.ndarray) -> np.ndarray: return z.real ** 2 + z.imag ** 2 +def normalized(z: np.ndarray) -> np.ndarray: + ab = abs2(z) + return ab / ab.max() + + def sigmoid(x): return 1 / (np.exp(-x) + 1) diff --git a/src/scgenerator/physics/pulse.py b/src/scgenerator/physics/pulse.py index 77a609f..86b0a8c 100644 --- a/src/scgenerator/physics/pulse.py +++ b/src/scgenerator/physics/pulse.py @@ -1151,3 +1151,7 @@ def remove_2nd_order_dispersion2( opti = minimize_scalar(score, bounds=(-max_gdd * 1e30, max_gdd * 1e30)) opti["x"] *= 1e-30 return propagate(opti.x * 1e30), opti + + +def gdd(w: np.ndarray, gdd: float) -> np.ndarray: + return np.exp(0.5j * w ** 2 * gdd) diff --git a/src/scgenerator/plotting.py b/src/scgenerator/plotting.py index 4b1822b..16e9ace 100644 --- a/src/scgenerator/plotting.py +++ b/src/scgenerator/plotting.py @@ -1041,12 +1041,20 @@ def measure_and_annotate_fwhm( field = abs2(field) _, (left, right), *_ = pulse.find_lobe_limits(unit.inv(t), field) arrow_label = f"{right - left:.1f} {unit.name}" + + annotate_fwhm(ax, left, right, arrow_label, field.max(), side, arrow_length_pts, arrow_props) + return right - left + + +def annotate_fwhm( + ax, left, right, arrow_label, v_max=1, side="right", arrow_length_pts=20.0, arrow_props=None +): arrow_dict = dict(arrowstyle="->") if arrow_props is not None: arrow_dict |= arrow_props ax.annotate( "" if side == "right" else arrow_label, - (left, field.max() / 2), + (left, v_max / 2), xytext=(-arrow_length_pts, 0), ha="right", va="center", @@ -1055,13 +1063,12 @@ def measure_and_annotate_fwhm( ) ax.annotate( "" if side == "left" else arrow_label, - (right, field.max() / 2), + (right, v_max / 2), xytext=(arrow_length_pts, 0), textcoords="offset points", arrowprops=arrow_dict, va="center", ) - return right - left def partial_plot(root: os.PathLike):