Skip to content

Commit 834f322

Browse files
authored
Update RF & Aperture Parmeters (pals-project#43)
- Use `Literal` where only one value is allowed. - Use standard lib (typing, annotated_types) where available.
1 parent 1433c8a commit 834f322

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/pals/parameters/ApertureParameters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Literal
1+
from annotated_types import Ge
2+
from typing import Annotated, Literal
23
from pydantic import BaseModel, Field, field_validator
34

45

@@ -22,6 +23,6 @@ def validate_limits(cls, v):
2223
"ENTRANCE_END", "CENTER", "EXIT_END", "BOTH_ENDS", "NOWHERE", "EVERYWHERE"
2324
] = "ENTRANCE_END"
2425
material: str = ""
25-
thickness: float = Field(default=0.0, ge=0.0)
26+
thickness: Annotated[float, Ge(0.0)] = 0.0
2627
aperture_shifts_with_body: bool = False
2728
aperture_active: bool = True
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
from pydantic import BaseModel, Field
1+
from annotated_types import Ge
2+
from typing import Annotated, Literal
3+
4+
from pydantic import BaseModel
25

36

47
class RFParameters(BaseModel):
58
"""RF parameters"""
69

7-
frequency: float = 0.0 # [Hz] RF frequency
8-
harmon: int = 0 # [unitless] RF frequency harmonic number
10+
frequency: Annotated[float, Ge(0.0)] = 0.0 # [Hz] RF frequency
11+
harmon: Annotated[int, Ge(0)] = 0 # [unitless] RF frequency harmonic number
912
voltage: float = 0.0 # [V] RF voltage
1013
gradient: float = 0.0 # [V/m] RF gradient
1114
phase: float = 0.0 # [unitless] RF phase in 0 to 2*pi
1215
multipass_phase: float = 0.0 # [unitless] RF Phase added to multipass elements
13-
cavity_type: str = "STANDING_WAVE" # [string] Cavity type
14-
n_cell: int = Field(default=1, gt=0) # [unitless] Number of cavity cells
16+
cavity_type: Literal["STANDING_WAVE"] = "STANDING_WAVE" # [string] Cavity type
17+
n_cell: Annotated[int, Ge(1)] = 1 # [unitless] Number of cavity cells

0 commit comments

Comments
 (0)