Merge branch 'master' into dev

This commit is contained in:
Benoît Sierro
2021-10-25 13:20:23 +02:00
4 changed files with 21 additions and 5 deletions

View File

@@ -1,7 +1,8 @@
# flake8: noqa # flake8: noqa
from . import math from . import math
from .evaluator import Evaluator
from .legacy import convert_sim_folder 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 .parameter import Configuration, Parameters
from .physics import fiber, materials, pulse, simulate, units from .physics import fiber, materials, pulse, simulate, units
from .physics.simulate import RK4IP, parallel_RK4IP, run_simulation from .physics.simulate import RK4IP, parallel_RK4IP, run_simulation
@@ -19,4 +20,3 @@ from .plotting import (
from .spectra import SimulationSeries, Spectrum from .spectra import SimulationSeries, Spectrum
from .utils import Paths, _open_config, open_single_config from .utils import Paths, _open_config, open_single_config
from .variationer import DescriptorDict, VariationDescriptor, Variationer, VariationSpecsError from .variationer import DescriptorDict, VariationDescriptor, Variationer, VariationSpecsError
from .evaluator import Evaluator

View File

@@ -77,6 +77,11 @@ def abs2(z: np.ndarray) -> np.ndarray:
return z.real ** 2 + z.imag ** 2 return z.real ** 2 + z.imag ** 2
def normalized(z: np.ndarray) -> np.ndarray:
ab = abs2(z)
return ab / ab.max()
def sigmoid(x): def sigmoid(x):
return 1 / (np.exp(-x) + 1) return 1 / (np.exp(-x) + 1)

View File

@@ -1151,3 +1151,7 @@ def remove_2nd_order_dispersion2(
opti = minimize_scalar(score, bounds=(-max_gdd * 1e30, max_gdd * 1e30)) opti = minimize_scalar(score, bounds=(-max_gdd * 1e30, max_gdd * 1e30))
opti["x"] *= 1e-30 opti["x"] *= 1e-30
return propagate(opti.x * 1e30), opti return propagate(opti.x * 1e30), opti
def gdd(w: np.ndarray, gdd: float) -> np.ndarray:
return np.exp(0.5j * w ** 2 * gdd)

View File

@@ -1041,12 +1041,20 @@ def measure_and_annotate_fwhm(
field = abs2(field) field = abs2(field)
_, (left, right), *_ = pulse.find_lobe_limits(unit.inv(t), field) _, (left, right), *_ = pulse.find_lobe_limits(unit.inv(t), field)
arrow_label = f"{right - left:.1f} {unit.name}" 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="->") arrow_dict = dict(arrowstyle="->")
if arrow_props is not None: if arrow_props is not None:
arrow_dict |= arrow_props arrow_dict |= arrow_props
ax.annotate( ax.annotate(
"" if side == "right" else arrow_label, "" if side == "right" else arrow_label,
(left, field.max() / 2), (left, v_max / 2),
xytext=(-arrow_length_pts, 0), xytext=(-arrow_length_pts, 0),
ha="right", ha="right",
va="center", va="center",
@@ -1055,13 +1063,12 @@ def measure_and_annotate_fwhm(
) )
ax.annotate( ax.annotate(
"" if side == "left" else arrow_label, "" if side == "left" else arrow_label,
(right, field.max() / 2), (right, v_max / 2),
xytext=(arrow_length_pts, 0), xytext=(arrow_length_pts, 0),
textcoords="offset points", textcoords="offset points",
arrowprops=arrow_dict, arrowprops=arrow_dict,
va="center", va="center",
) )
return right - left
def partial_plot(root: os.PathLike): def partial_plot(root: os.PathLike):