pytac 0.6.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytac/__init__.py +47 -0
- pytac/__main__.py +16 -0
- pytac/_version.py +4 -0
- pytac/cothread_cs.py +139 -0
- pytac/cs.py +77 -0
- pytac/data/DIAD/elements.csv +2145 -0
- pytac/data/DIAD/epics_devices.csv +2932 -0
- pytac/data/DIAD/families.csv +2575 -0
- pytac/data/DIAD/simple_devices.csv +2 -0
- pytac/data/DIAD/uc_pchip_data.csv +770 -0
- pytac/data/DIAD/uc_poly_data.csv +921 -0
- pytac/data/DIAD/unitconv.csv +1381 -0
- pytac/data/DIADSP/elements.csv +2145 -0
- pytac/data/DIADSP/epics_devices.csv +2932 -0
- pytac/data/DIADSP/families.csv +2575 -0
- pytac/data/DIADSP/simple_devices.csv +2 -0
- pytac/data/DIADSP/uc_pchip_data.csv +770 -0
- pytac/data/DIADSP/uc_poly_data.csv +921 -0
- pytac/data/DIADSP/unitconv.csv +1381 -0
- pytac/data/DIADTHz/elements.csv +2145 -0
- pytac/data/DIADTHz/epics_devices.csv +2932 -0
- pytac/data/DIADTHz/families.csv +2575 -0
- pytac/data/DIADTHz/simple_devices.csv +2 -0
- pytac/data/DIADTHz/uc_pchip_data.csv +770 -0
- pytac/data/DIADTHz/uc_poly_data.csv +921 -0
- pytac/data/DIADTHz/unitconv.csv +1381 -0
- pytac/data/I04/elements.csv +2191 -0
- pytac/data/I04/epics_devices.csv +2936 -0
- pytac/data/I04/families.csv +2621 -0
- pytac/data/I04/simple_devices.csv +2 -0
- pytac/data/I04/uc_pchip_data.csv +770 -0
- pytac/data/I04/uc_poly_data.csv +929 -0
- pytac/data/I04/unitconv.csv +1385 -0
- pytac/data/I04SP/elements.csv +2191 -0
- pytac/data/I04SP/epics_devices.csv +2936 -0
- pytac/data/I04SP/families.csv +2621 -0
- pytac/data/I04SP/simple_devices.csv +2 -0
- pytac/data/I04SP/uc_pchip_data.csv +770 -0
- pytac/data/I04SP/uc_poly_data.csv +929 -0
- pytac/data/I04SP/unitconv.csv +1385 -0
- pytac/data/I04THz/elements.csv +2191 -0
- pytac/data/I04THz/epics_devices.csv +2936 -0
- pytac/data/I04THz/families.csv +2621 -0
- pytac/data/I04THz/simple_devices.csv +2 -0
- pytac/data/I04THz/uc_pchip_data.csv +770 -0
- pytac/data/I04THz/uc_poly_data.csv +929 -0
- pytac/data/I04THz/unitconv.csv +1385 -0
- pytac/data/SRI0913_MOGA/elements.csv +2145 -0
- pytac/data/SRI0913_MOGA/epics_devices.csv +2932 -0
- pytac/data/SRI0913_MOGA/families.csv +2575 -0
- pytac/data/SRI0913_MOGA/simple_devices.csv +2 -0
- pytac/data/SRI0913_MOGA/uc_pchip_data.csv +770 -0
- pytac/data/SRI0913_MOGA/uc_poly_data.csv +921 -0
- pytac/data/SRI0913_MOGA/unitconv.csv +1381 -0
- pytac/data/VMX/elements.csv +2143 -0
- pytac/data/VMX/epics_devices.csv +2939 -0
- pytac/data/VMX/families.csv +2575 -0
- pytac/data/VMX/simple_devices.csv +2 -0
- pytac/data/VMX/uc_pchip_data.csv +774 -0
- pytac/data/VMX/uc_poly_data.csv +925 -0
- pytac/data/VMX/unitconv.csv +1384 -0
- pytac/data/VMXSP/elements.csv +2143 -0
- pytac/data/VMXSP/epics_devices.csv +2939 -0
- pytac/data/VMXSP/families.csv +2575 -0
- pytac/data/VMXSP/simple_devices.csv +2 -0
- pytac/data/VMXSP/uc_pchip_data.csv +774 -0
- pytac/data/VMXSP/uc_poly_data.csv +925 -0
- pytac/data/VMXSP/unitconv.csv +1384 -0
- pytac/data/VMXTHz/elements.csv +2143 -0
- pytac/data/VMXTHz/epics_devices.csv +2939 -0
- pytac/data/VMXTHz/families.csv +2575 -0
- pytac/data/VMXTHz/simple_devices.csv +2 -0
- pytac/data/VMXTHz/uc_pchip_data.csv +774 -0
- pytac/data/VMXTHz/uc_poly_data.csv +925 -0
- pytac/data/VMXTHz/unitconv.csv +1384 -0
- pytac/data_source.py +352 -0
- pytac/device.py +255 -0
- pytac/element.py +344 -0
- pytac/exceptions.py +33 -0
- pytac/lattice.py +696 -0
- pytac/load_csv.py +225 -0
- pytac/units.py +502 -0
- pytac/utils.py +54 -0
- pytac-0.6.0b1.dist-info/LICENSE +201 -0
- pytac-0.6.0b1.dist-info/METADATA +284 -0
- pytac-0.6.0b1.dist-info/RECORD +89 -0
- pytac-0.6.0b1.dist-info/WHEEL +5 -0
- pytac-0.6.0b1.dist-info/entry_points.txt +2 -0
- pytac-0.6.0b1.dist-info/top_level.txt +1 -0
pytac/__init__.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
if sys.version_info < (3, 8):
|
|
4
|
+
from importlib_metadata import version # noqa
|
|
5
|
+
else:
|
|
6
|
+
from importlib.metadata import version # noqa
|
|
7
|
+
|
|
8
|
+
# PV types.
|
|
9
|
+
SP = "setpoint"
|
|
10
|
+
RB = "readback"
|
|
11
|
+
# Unit systems.
|
|
12
|
+
ENG = "engineering"
|
|
13
|
+
PHYS = "physics"
|
|
14
|
+
# Data Source types.
|
|
15
|
+
SIM = "simulation"
|
|
16
|
+
LIVE = "live"
|
|
17
|
+
# Default argument flag.
|
|
18
|
+
DEFAULT = "default"
|
|
19
|
+
|
|
20
|
+
from . import ( # isort:skip
|
|
21
|
+
data_source,
|
|
22
|
+
device,
|
|
23
|
+
element,
|
|
24
|
+
exceptions,
|
|
25
|
+
lattice,
|
|
26
|
+
load_csv,
|
|
27
|
+
units,
|
|
28
|
+
utils,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
"""Ignore isort (flake8 Error 402) as we cannot import these modules at the top of the
|
|
32
|
+
file as the strings above must be set first or the imports will fail.
|
|
33
|
+
"""
|
|
34
|
+
__version__ = version("pytac")
|
|
35
|
+
del version
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"__version__",
|
|
39
|
+
"data_source",
|
|
40
|
+
"device",
|
|
41
|
+
"element",
|
|
42
|
+
"exceptions",
|
|
43
|
+
"lattice",
|
|
44
|
+
"load_csv",
|
|
45
|
+
"units",
|
|
46
|
+
"utils",
|
|
47
|
+
]
|
pytac/__main__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from argparse import ArgumentParser
|
|
2
|
+
|
|
3
|
+
from . import __version__
|
|
4
|
+
|
|
5
|
+
__all__ = ["main"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main(args=None):
|
|
9
|
+
parser = ArgumentParser()
|
|
10
|
+
parser.add_argument("-v", "--version", action="version", version=__version__)
|
|
11
|
+
args = parser.parse_args(args)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# test with: python -m pytac
|
|
15
|
+
if __name__ == "__main__":
|
|
16
|
+
main()
|
pytac/_version.py
ADDED
pytac/cothread_cs.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from cothread.catools import ca_nothing, caget, caput
|
|
4
|
+
|
|
5
|
+
from pytac.cs import ControlSystem
|
|
6
|
+
from pytac.exceptions import ControlSystemException
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CothreadControlSystem(ControlSystem):
|
|
10
|
+
"""A control system using cothread to communicate with EPICS.
|
|
11
|
+
|
|
12
|
+
N.B. this is the default control system. It is used to communicate over
|
|
13
|
+
channel access with the hardware in the ring.
|
|
14
|
+
|
|
15
|
+
**Methods:**
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, timeout=1.0, wait=False):
|
|
19
|
+
self._timeout = timeout
|
|
20
|
+
self._wait = wait
|
|
21
|
+
|
|
22
|
+
def get_single(self, pv, throw=True):
|
|
23
|
+
"""Get the value of a given PV.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
pv (string): The process variable given as a string. It can be a
|
|
27
|
+
readback or a setpoint PV.
|
|
28
|
+
throw (bool): On failure: if True, raise ControlSystemException; if
|
|
29
|
+
False, return None and log a warning.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
object: the current value of the given PV.
|
|
33
|
+
|
|
34
|
+
Raises:
|
|
35
|
+
ControlSystemException: if it cannot connect to the specified PV.
|
|
36
|
+
"""
|
|
37
|
+
try:
|
|
38
|
+
return caget(pv, timeout=self._timeout, throw=True)
|
|
39
|
+
except ca_nothing:
|
|
40
|
+
error_msg = f"Cannot connect to {pv}."
|
|
41
|
+
if throw:
|
|
42
|
+
raise ControlSystemException(error_msg)
|
|
43
|
+
else:
|
|
44
|
+
logging.warning(error_msg)
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
def get_multiple(self, pvs, throw=True):
|
|
48
|
+
"""Get the value for given PVs.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
pvs (sequence): PVs to get values of.
|
|
52
|
+
throw (bool): On failure: if True, raise ControlSystemException; if
|
|
53
|
+
False, None will be returned for any PV that fails
|
|
54
|
+
and a warning will be logged.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
sequence: the current values of the PVs.
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
ControlSystemException: if it cannot connect to one or more PVs.
|
|
61
|
+
"""
|
|
62
|
+
results = caget(pvs, timeout=self._timeout, throw=False)
|
|
63
|
+
return_values = []
|
|
64
|
+
failures = []
|
|
65
|
+
for result in results:
|
|
66
|
+
if isinstance(result, ca_nothing):
|
|
67
|
+
logging.warning(f"Cannot connect to {result.name}.")
|
|
68
|
+
if throw:
|
|
69
|
+
failures.append(result)
|
|
70
|
+
else:
|
|
71
|
+
return_values.append(None)
|
|
72
|
+
else:
|
|
73
|
+
return_values.append(result)
|
|
74
|
+
if throw and failures:
|
|
75
|
+
raise ControlSystemException(f"{len(failures)} caget calls failed.")
|
|
76
|
+
return return_values
|
|
77
|
+
|
|
78
|
+
def set_single(self, pv, value, throw=True):
|
|
79
|
+
"""Set the value of a given PV.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
pv (string): PV to set the value of.
|
|
83
|
+
value (object): The value to set the PV to.
|
|
84
|
+
throw (bool): On failure: if True, raise ControlSystemException: if
|
|
85
|
+
False, log a warning.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
bool: True for success, False for failure
|
|
89
|
+
|
|
90
|
+
Raises:
|
|
91
|
+
ControlSystemException: if it cannot connect to the specified PV.
|
|
92
|
+
"""
|
|
93
|
+
try:
|
|
94
|
+
caput(pv, value, timeout=self._timeout, throw=True, wait=self._wait)
|
|
95
|
+
return True
|
|
96
|
+
except ca_nothing:
|
|
97
|
+
error_msg = f"Cannot connect to {pv}."
|
|
98
|
+
if throw:
|
|
99
|
+
raise ControlSystemException(error_msg)
|
|
100
|
+
else:
|
|
101
|
+
logging.warning(error_msg)
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
def set_multiple(self, pvs, values, throw=True):
|
|
105
|
+
"""Set the values for given PVs.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
pvs (sequence): PVs to set the values of.
|
|
109
|
+
values (sequence): values to set to the PVs.
|
|
110
|
+
throw (bool): On failure, if True raise ControlSystemException, if
|
|
111
|
+
False return a list of True and False values
|
|
112
|
+
corresponding to successes and failures and log a
|
|
113
|
+
warning for each PV that fails.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
list(bool): True for success, False for failure; only returned if
|
|
117
|
+
throw is false and a failure occurs.
|
|
118
|
+
|
|
119
|
+
Raises:
|
|
120
|
+
ValueError: if the lists of values and PVs are diffent lengths.
|
|
121
|
+
ControlSystemException: if it cannot connect to one or more PVs.
|
|
122
|
+
"""
|
|
123
|
+
if len(pvs) != len(values):
|
|
124
|
+
raise ValueError("Please enter the same number of values as PVs.")
|
|
125
|
+
status = caput(pvs, values, timeout=self._timeout, throw=False, wait=self._wait)
|
|
126
|
+
return_values = []
|
|
127
|
+
failures = []
|
|
128
|
+
for stat in status:
|
|
129
|
+
if not stat.ok:
|
|
130
|
+
return_values.append(False)
|
|
131
|
+
failures.append(stat)
|
|
132
|
+
logging.warning(f"Cannot connect to {stat.name}.")
|
|
133
|
+
else:
|
|
134
|
+
return_values.append(True)
|
|
135
|
+
if failures:
|
|
136
|
+
if throw:
|
|
137
|
+
raise ControlSystemException(f"{len(failures)} caput calls failed.")
|
|
138
|
+
else:
|
|
139
|
+
return return_values
|
pytac/cs.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Class representing an abstract control system."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ControlSystem(object):
|
|
5
|
+
"""Abstract base class representing a control system.
|
|
6
|
+
|
|
7
|
+
A specialised implementation of this class would be used to communicate
|
|
8
|
+
over channel access with the hardware in the ring.
|
|
9
|
+
|
|
10
|
+
**Methods:**
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def get_single(self, pv, throw):
|
|
14
|
+
"""Get the value of a given PV.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
pv (string): PV to get the value of.
|
|
18
|
+
readback or a setpoint PV.
|
|
19
|
+
throw (bool): On failure: if True, raise ControlSystemException; if
|
|
20
|
+
False, return None and log a warning.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
object: the current value of the given PV.
|
|
24
|
+
|
|
25
|
+
Raises:
|
|
26
|
+
ControlSystemException: if it cannot connect to the specified PVs.
|
|
27
|
+
"""
|
|
28
|
+
raise NotImplementedError()
|
|
29
|
+
|
|
30
|
+
def get_multiple(self, pvs, throw):
|
|
31
|
+
"""Get the value for given PVs.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
pvs (sequence): PVs to get values of.
|
|
35
|
+
throw (bool): On failure: if True, raise ControlSystemException; if
|
|
36
|
+
False, None will be returned for any PV that fails
|
|
37
|
+
and a warning will be logged.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
list(object): the current values of the PVs.
|
|
41
|
+
|
|
42
|
+
Raises:
|
|
43
|
+
ControlSystemException: if it cannot connect to the specified PV.
|
|
44
|
+
"""
|
|
45
|
+
raise NotImplementedError()
|
|
46
|
+
|
|
47
|
+
def set_single(self, pv, value, throw):
|
|
48
|
+
"""Set the value of a given PV.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
pv (string): The PV to set the value of.
|
|
52
|
+
value (object): The value to set the PV to.
|
|
53
|
+
throw (bool): On failure: if True, raise ControlSystemException: if
|
|
54
|
+
False, log a warning.
|
|
55
|
+
|
|
56
|
+
Raises:
|
|
57
|
+
ControlSystemException: if it cannot connect to the specified PV.
|
|
58
|
+
"""
|
|
59
|
+
raise NotImplementedError()
|
|
60
|
+
|
|
61
|
+
def set_multiple(self, pvs, values, throw):
|
|
62
|
+
"""Set the values for given PVs.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
pvs (sequence): PVs to set the values of.
|
|
66
|
+
values (sequence): values to set no the PVs.
|
|
67
|
+
throw (bool): On failure, if True raise ControlSystemException, if
|
|
68
|
+
False return a list of True and False values
|
|
69
|
+
corresponding to successes and failures and log a
|
|
70
|
+
warning for each PV that fails.
|
|
71
|
+
|
|
72
|
+
Raises:
|
|
73
|
+
ValueError: if the PVs or values are not passed in as sequences
|
|
74
|
+
or if they have different lengths
|
|
75
|
+
ControlSystemException: if it cannot connect to one or more PVs.
|
|
76
|
+
"""
|
|
77
|
+
raise NotImplementedError()
|