Skip to content

Commit 48f0e7d

Browse files
committed
Move linopt validation check to dataclass
1 parent 63855d5 commit 48f0e7d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/atip/simulator.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ class SimParams:
2828

2929
def __post_init__(self):
3030
"""Check that we have a valid combination of simulation parameters."""
31+
try:
32+
LinoptType(self.linopt)
33+
except ValueError as e:
34+
raise ValueError(
35+
f"{self.linopt} is not a valid linopt function. Choose from: "
36+
f"{[sp.value for sp in LinoptType]}"
37+
) from e
38+
3139
if self.linopt == LinoptType.LINOPT2 or self.linopt == LinoptType.LINOPT4:
3240
if self.emittance or self.radiation:
3341
raise ValueError(
@@ -86,11 +94,6 @@ def calculate_optics(
8694
case LinoptType.LINOPT6:
8795
orbit_func = at_lattice.find_orbit6
8896
linopt_func = at_lattice.linopt6
89-
case _:
90-
raise ValueError(
91-
f"Error. Invalid linopt function selected: {sp.linopt}. Simulation "
92-
"data not calculated."
93-
)
9497

9598
# Perform pyAT orbit calculation
9699
orbit0, _ = orbit_func()

0 commit comments

Comments
 (0)