better validation and errors
This commit is contained in:
@@ -11,16 +11,16 @@ import numpy as np
|
||||
import scgenerator as sc
|
||||
import tomli
|
||||
from customfunc.app import PlotApp
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, ValidationError, confloat
|
||||
|
||||
DEFAULT_CONFIG_FILE = "config.toml"
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
wl_min: float
|
||||
wl_max: float
|
||||
wl_pump: float
|
||||
rep_rate: float
|
||||
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
|
||||
|
||||
@classmethod
|
||||
@@ -29,7 +29,12 @@ class Config(BaseModel):
|
||||
with open(config_file, "rb") as file:
|
||||
d = tomli.load(file)
|
||||
d = cls.default() | d
|
||||
try:
|
||||
return cls(**d)
|
||||
except ValidationError as e:
|
||||
s = f"invalid input in config file {config_file}:\n{e}"
|
||||
print(s)
|
||||
sys.exit(1)
|
||||
|
||||
@classmethod
|
||||
def default(cls) -> dict[str, Any]:
|
||||
@@ -102,12 +107,12 @@ def app(config_file: os.PathLike | None = None):
|
||||
|
||||
with PlotApp(
|
||||
f"Dispersion design with {config.gas.title()}",
|
||||
wall_thickness_um=np.geomspace(0.01, 10),
|
||||
core_diameter_um=np.linspace(50, 300),
|
||||
pressure_mbar=np.geomspace(1, 2000),
|
||||
wall_thickness_um=np.geomspace(0.01, 10),
|
||||
n_tubes=np.arange(6, 16),
|
||||
gap_um=np.linspace(1, 15),
|
||||
t_fwhm_fs=np.linspace(10, 200),
|
||||
t_fwhm_fs=np.linspace(10, 200, 96),
|
||||
) as app:
|
||||
# initial setup
|
||||
app[0].horizontal_line("reference", 0, color="gray")
|
||||
@@ -211,7 +216,7 @@ def app(config_file: os.PathLike | None = None):
|
||||
)
|
||||
|
||||
zdw = lim.wl_zero_disp * 1e9
|
||||
app[0].set_line_data("zdw", [zdw, zdw], [0, 1])
|
||||
app[0].set_line_data("zdw", [zdw, zdw], [-3, 3])
|
||||
app[0].set_line_name("zdw", f"ZDW = {zdw:.0f}nm")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user