better config defaults
This commit is contained in:
@@ -2,13 +2,13 @@ from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any, NamedTuple
|
||||
from typing import NamedTuple
|
||||
|
||||
import numpy as np
|
||||
import scgenerator as sc
|
||||
import tomli
|
||||
import tomli_w
|
||||
from pydantic import BaseModel, PrivateAttr, ValidationError, confloat
|
||||
from pydantic import BaseModel, PrivateAttr, ValidationError, confloat, conint
|
||||
|
||||
DEFAULT_CONFIG_FILE = "dispersion_config.toml"
|
||||
|
||||
@@ -23,12 +23,13 @@ class CurrentState(BaseModel):
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
wl_min: confloat(ge=100, le=1000)
|
||||
wl_max: confloat(ge=500, le=6000)
|
||||
wl_pump: confloat(ge=200, le=6000)
|
||||
rep_rate: confloat(gt=0)
|
||||
gas: str
|
||||
safety_factor: float
|
||||
wl_min: confloat(ge=100, le=1000) = 160
|
||||
wl_max: confloat(ge=500, le=6000) = 1600
|
||||
wl_pump: confloat(ge=200, le=6000) = 800
|
||||
rep_rate: confloat(gt=0) = 8e3
|
||||
num_resonances: conint(ge=6, le=20) = 6
|
||||
gas: str = "argon"
|
||||
safety_factor: float = 10.0
|
||||
current_state: CurrentState | None = None
|
||||
|
||||
_file_name: Path = PrivateAttr()
|
||||
@@ -41,7 +42,6 @@ class Config(BaseModel):
|
||||
|
||||
with open(config_file, "rb") as file:
|
||||
d = tomli.load(file)
|
||||
d = cls.default() | d
|
||||
try:
|
||||
out = cls(**d)
|
||||
except ValidationError as e:
|
||||
@@ -51,12 +51,6 @@ class Config(BaseModel):
|
||||
out._file_name = Path(config_file)
|
||||
return out
|
||||
|
||||
@classmethod
|
||||
def default(cls) -> dict[str, Any]:
|
||||
return dict(
|
||||
wl_min=160, wl_max=1600, wl_pump=800, rep_rate=8e3, gas="argon", safety_factor=10
|
||||
)
|
||||
|
||||
def save(self):
|
||||
tmp = self._file_name.parent / f"{self._file_name.name}.tmp"
|
||||
with open(tmp, "wb") as file:
|
||||
|
||||
@@ -99,7 +99,14 @@ def app(config_file: os.PathLike | None = None):
|
||||
tr = sc.fiber.tube_radius_from_gap(core_diameter / 2, gap, n_tubes)
|
||||
n_gas_2 = gas.sellmeier.n_gas_2(wl, None, pressure)
|
||||
n_eff_vinc = sc.fiber.n_eff_vincetti(
|
||||
wl, 800e-9, n_gas_2, wall_thickness, tr, gap, n_tubes
|
||||
wl,
|
||||
800e-9,
|
||||
n_gas_2,
|
||||
wall_thickness,
|
||||
tr,
|
||||
gap,
|
||||
n_tubes,
|
||||
n_terms=config.num_resonances,
|
||||
)
|
||||
return b2(w, n_eff_vinc)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user