-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
94 lines (76 loc) · 3.27 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from toydaq import Motor, Diode, Camera
class Model():
""" The model for our beamline. It contains our hardware, i.e. diodes, cameras, motors."""
# Configuration of our beamline. Ex[ected parameters for the hardware.
valid_units = ["m", "nm", "mm"]
valid_diode_names=["INTENSITY", "COUNTER", "SIGNAL", "XRF"]
valid_camera_names=["MY-CAMERA"]
def __init__(self):
"""
Make motors, diodes, cameras available in the model with their methods and attributes.
better in the future: load from a config file
"""
self.motors = {}
self.diodes = {}
self.cameras = {}
def _check_valid_units(self, units):
"""
Ensure the user has provided a valid unit name
"""
if units not in self.valid_units:
options = ", ".join(self.valid_units)
raise ValueError(f"{units} is not a known unit type. Options are {options}")
def add_motor(self, name, units):
"""
Add a motor to the model
"""
if name in self.motors:
raise ValueError(
f"Motor names must be unique: {name} is already a defined motor."
)
# Allow any casing
units = units.lower()
self._check_valid_units(units)
print(f"Adding motor {name} with units {units}")
self.motors[name] = Motor(name, units)
def _check_valid_diode_names(self, diode_name):
"""
Ensure the user has provided a valid diode name
"""
if diode_name not in self.valid_diode_names:
options = ", ".join(self.valid_diode_names)
raise ValueError(f"{diode_name} is not a known sensor diode name. Options are {options}")
def add_diode(self, diode_name):
"""
Add a diode to the model
"""
if diode_name in self.diodes:
raise ValueError(
f"Diode names must be unique: {diode_name} is already a defined diode."
)
self._check_valid_diode_names(diode_name)
print(f"Adding diode {diode_name}")
self.diodes[diode_name]=Diode(diode_name)
def _check_valid_camera_names(self, camera_name):
"""
Ensure the user has provided a valid camera name
"""
if camera_name not in self.valid_camera_names:
options = ", ".join(self.valid_camera_names)
raise ValueError(f"{camera_name} is not a known sensor diode name. Options are {options}")
def add_camera(self, camera_name):
"""Add a camera to the model"""
if camera_name in self.cameras:
raise ValueError(f"Camera names must be unique: {camera_name} is already a defined camera.")
self._check_valid_camera_names(camera_name)
print(f"Adding camera {camera_name}")
self.cameras[camera_name]=Camera(camera_name)
def diode_names(self):
""" Return names of all available diodes """
return [self.diodes[label].name for label in self.diodes]
def motor_names(self):
""" Return names of all available motors """
return [self.motors[label].name for label in self.motors]
def camera_names(self):
""" Return names of all available cameras """
return [self.cameras[label].name for label in self.cameras]