From 31fb519e883c9e0c8d14dc7514bd8549480fac93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sierro?= Date: Mon, 11 Oct 2021 15:38:26 +0200 Subject: [PATCH] misc --- README.md | 4 ++-- src/scgenerator/_utils/parameter.py | 6 +++--- src/scgenerator/_utils/utils.py | 17 ++++++++-------- src/scgenerator/physics/fiber.py | 31 +++++++++-------------------- src/scgenerator/scripts/__init__.py | 3 ++- src/scgenerator/spectra.py | 4 ++-- 6 files changed, 27 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index d5890e5..5405150 100644 --- a/README.md +++ b/README.md @@ -141,8 +141,8 @@ hasan : capillary_num : int number of capillaries -capillary_outer_d : float, optional if g is specified - outer diameter of the capillaries +capillary_radius : float, optional if g is specified + outer radius of the capillaries capillary_thickness : float thickness of the capillary walls diff --git a/src/scgenerator/_utils/parameter.py b/src/scgenerator/_utils/parameter.py index 43e1f56..6f4ba83 100644 --- a/src/scgenerator/_utils/parameter.py +++ b/src/scgenerator/_utils/parameter.py @@ -55,7 +55,7 @@ VALID_VARIABLE = { "effective_mode_diameter", "core_radius", "capillary_num", - "capillary_outer_d", + "capillary_radius", "capillary_thickness", "capillary_spacing", "capillary_resonance_strengths", @@ -374,7 +374,7 @@ class Parameters(_AbstractParameters): ) length: float = Parameter(non_negative(float, int)) capillary_num: int = Parameter(positive(int)) - capillary_outer_d: float = Parameter(in_range_excl(0, 1e-3)) + capillary_radius: float = Parameter(in_range_excl(0, 1e-3)) capillary_thickness: float = Parameter(in_range_excl(0, 1e-3)) capillary_spacing: float = Parameter(in_range_excl(0, 1e-3)) capillary_resonance_strengths: Iterable[float] = Parameter(num_list, default=[]) @@ -1104,7 +1104,7 @@ default_rules: list[Rule] = [ ["wl_for_disp", "pitch", "pitch_ratio"], conditions=dict(model="pcf"), ), - Rule("capillary_spacing", fiber.HCARF_gap), + Rule("capillary_spacing", fiber.capillary_spacing_hasan), # Fiber nonlinearity Rule("A_eff", fiber.A_eff_from_V), Rule("A_eff", fiber.A_eff_from_diam), diff --git a/src/scgenerator/_utils/utils.py b/src/scgenerator/_utils/utils.py index d2a4fa8..2931f09 100644 --- a/src/scgenerator/_utils/utils.py +++ b/src/scgenerator/_utils/utils.py @@ -109,11 +109,12 @@ def sort_axis( def get_arg_names(func: Callable) -> list[str]: - spec = inspect.getfullargspec(func) - args = spec.args - if spec.defaults is not None and len(spec.defaults) > 0: - args = args[: -len(spec.defaults)] - return args + # spec = inspect.getfullargspec(func) + # args = spec.args + # if spec.defaults is not None and len(spec.defaults) > 0: + # args = args[: -len(spec.defaults)] + # return args + return [k for k, v in inspect.signature(func).parameters.items() if v.default is inspect._empty] def validate_arg_names(names: list[str]): @@ -238,7 +239,7 @@ def fiber_folder(i: int, sim_name: str, fiber_name: str) -> str: return PARAM_SEPARATOR.join([format(i), sim_name, fiber_name]) -def iter_simulations(path: os.PathLike) -> list[Path]: +def simulations_list(path: os.PathLike) -> list[Path]: """finds simulations folders contained in a parent directory Parameters @@ -246,9 +247,9 @@ def iter_simulations(path: os.PathLike) -> list[Path]: path : os.PathLike parent path - Yields + Returns ------- - Path + list[Path] Absolute Path to the simulation folder """ paths: list[Path] = [] diff --git a/src/scgenerator/physics/fiber.py b/src/scgenerator/physics/fiber.py index d059eda..16ba4ed 100644 --- a/src/scgenerator/physics/fiber.py +++ b/src/scgenerator/physics/fiber.py @@ -7,7 +7,7 @@ from scipy.interpolate import interp1d from ..logger import get_logger -from .. import _utils +from .. import _utils as utils from ..math import abs2, argclosest, power_fact, u_nm from .._utils.cache import np_cache from . import materials as mat @@ -48,27 +48,6 @@ def is_dynamic_dispersion(pressure=None): return out -def HCARF_gap(core_radius: float, capillary_num: int, capillary_outer_d: float): - """computes the gap length between capillaries of a hollow core anti-resonance fiber - - Parameters - ---------- - core_radius : float - radius of the core (m) (from cented to edge of a capillary) - capillary_num : int - number of capillaries - capillary_outer_d : float - diameter of the capillaries including the wall thickness(m). The core together with the microstructure has a diameter of 2R + 2d - - Returns - ------- - gap : float - """ - return (core_radius + capillary_outer_d / 2) * 2 * np.sin( - pi / capillary_num - ) - capillary_outer_d - - def gvd_from_n_eff(n_eff: np.ndarray, wl_for_disp: np.ndarray): """computes the dispersion parameter D from an effective index of refraction n_eff Since computing gradients/derivatives of discrete arrays is not well defined on the boundary, it is @@ -208,6 +187,14 @@ def A_eff_marcatili(core_radius: float) -> float: return 1.5 * core_radius ** 2 +def capillary_spacing_hasan( + capillary_num: int, capillary_radius: float, core_radius: float +) -> float: + return ( + 2 * (capillary_radius + core_radius) * np.sin(np.pi / capillary_num) - 2 * capillary_radius + ) + + @np_cache def n_eff_hasan( wl_for_disp: np.ndarray, diff --git a/src/scgenerator/scripts/__init__.py b/src/scgenerator/scripts/__init__.py index ebc10c0..fb1f473 100644 --- a/src/scgenerator/scripts/__init__.py +++ b/src/scgenerator/scripts/__init__.py @@ -17,6 +17,7 @@ from .._utils.parameter import ( Configuration, Parameters, ) +from .._utils.utils import simulations_list def fingerprint(params: Parameters): @@ -31,7 +32,7 @@ def plot_all(sim_dir: Path, limits: list[str], show=False, **opts): opts[k] = int(v) if k in {"log", "renormalize"}: opts[k] = True if v == "True" else False - dir_list = list(p for p in sim_dir.glob("*") if p.is_dir()) + dir_list = simulations_list(sim_dir) if len(dir_list) == 0: dir_list = [sim_dir] limits = [ diff --git a/src/scgenerator/spectra.py b/src/scgenerator/spectra.py index 2072806..fe9279d 100644 --- a/src/scgenerator/spectra.py +++ b/src/scgenerator/spectra.py @@ -10,7 +10,7 @@ import numpy as np from . import math from ._utils import load_spectrum from ._utils.parameter import Parameters -from ._utils.utils import PlotRange, iter_simulations +from ._utils.utils import PlotRange, simulations_list from .const import PARAM_FN, SPEC1_FN, SPEC1_FN_N from .logger import get_logger from .physics import pulse, units @@ -129,7 +129,7 @@ class SimulationSeries: def __init__(self, path: os.PathLike): self.logger = get_logger() - for self.path in iter_simulations(path): + for self.path in simulations_list(path): break else: raise FileNotFoundError(f"No simulation in {path}")