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.
Files changed (89) hide show
  1. pytac/__init__.py +47 -0
  2. pytac/__main__.py +16 -0
  3. pytac/_version.py +4 -0
  4. pytac/cothread_cs.py +139 -0
  5. pytac/cs.py +77 -0
  6. pytac/data/DIAD/elements.csv +2145 -0
  7. pytac/data/DIAD/epics_devices.csv +2932 -0
  8. pytac/data/DIAD/families.csv +2575 -0
  9. pytac/data/DIAD/simple_devices.csv +2 -0
  10. pytac/data/DIAD/uc_pchip_data.csv +770 -0
  11. pytac/data/DIAD/uc_poly_data.csv +921 -0
  12. pytac/data/DIAD/unitconv.csv +1381 -0
  13. pytac/data/DIADSP/elements.csv +2145 -0
  14. pytac/data/DIADSP/epics_devices.csv +2932 -0
  15. pytac/data/DIADSP/families.csv +2575 -0
  16. pytac/data/DIADSP/simple_devices.csv +2 -0
  17. pytac/data/DIADSP/uc_pchip_data.csv +770 -0
  18. pytac/data/DIADSP/uc_poly_data.csv +921 -0
  19. pytac/data/DIADSP/unitconv.csv +1381 -0
  20. pytac/data/DIADTHz/elements.csv +2145 -0
  21. pytac/data/DIADTHz/epics_devices.csv +2932 -0
  22. pytac/data/DIADTHz/families.csv +2575 -0
  23. pytac/data/DIADTHz/simple_devices.csv +2 -0
  24. pytac/data/DIADTHz/uc_pchip_data.csv +770 -0
  25. pytac/data/DIADTHz/uc_poly_data.csv +921 -0
  26. pytac/data/DIADTHz/unitconv.csv +1381 -0
  27. pytac/data/I04/elements.csv +2191 -0
  28. pytac/data/I04/epics_devices.csv +2936 -0
  29. pytac/data/I04/families.csv +2621 -0
  30. pytac/data/I04/simple_devices.csv +2 -0
  31. pytac/data/I04/uc_pchip_data.csv +770 -0
  32. pytac/data/I04/uc_poly_data.csv +929 -0
  33. pytac/data/I04/unitconv.csv +1385 -0
  34. pytac/data/I04SP/elements.csv +2191 -0
  35. pytac/data/I04SP/epics_devices.csv +2936 -0
  36. pytac/data/I04SP/families.csv +2621 -0
  37. pytac/data/I04SP/simple_devices.csv +2 -0
  38. pytac/data/I04SP/uc_pchip_data.csv +770 -0
  39. pytac/data/I04SP/uc_poly_data.csv +929 -0
  40. pytac/data/I04SP/unitconv.csv +1385 -0
  41. pytac/data/I04THz/elements.csv +2191 -0
  42. pytac/data/I04THz/epics_devices.csv +2936 -0
  43. pytac/data/I04THz/families.csv +2621 -0
  44. pytac/data/I04THz/simple_devices.csv +2 -0
  45. pytac/data/I04THz/uc_pchip_data.csv +770 -0
  46. pytac/data/I04THz/uc_poly_data.csv +929 -0
  47. pytac/data/I04THz/unitconv.csv +1385 -0
  48. pytac/data/SRI0913_MOGA/elements.csv +2145 -0
  49. pytac/data/SRI0913_MOGA/epics_devices.csv +2932 -0
  50. pytac/data/SRI0913_MOGA/families.csv +2575 -0
  51. pytac/data/SRI0913_MOGA/simple_devices.csv +2 -0
  52. pytac/data/SRI0913_MOGA/uc_pchip_data.csv +770 -0
  53. pytac/data/SRI0913_MOGA/uc_poly_data.csv +921 -0
  54. pytac/data/SRI0913_MOGA/unitconv.csv +1381 -0
  55. pytac/data/VMX/elements.csv +2143 -0
  56. pytac/data/VMX/epics_devices.csv +2939 -0
  57. pytac/data/VMX/families.csv +2575 -0
  58. pytac/data/VMX/simple_devices.csv +2 -0
  59. pytac/data/VMX/uc_pchip_data.csv +774 -0
  60. pytac/data/VMX/uc_poly_data.csv +925 -0
  61. pytac/data/VMX/unitconv.csv +1384 -0
  62. pytac/data/VMXSP/elements.csv +2143 -0
  63. pytac/data/VMXSP/epics_devices.csv +2939 -0
  64. pytac/data/VMXSP/families.csv +2575 -0
  65. pytac/data/VMXSP/simple_devices.csv +2 -0
  66. pytac/data/VMXSP/uc_pchip_data.csv +774 -0
  67. pytac/data/VMXSP/uc_poly_data.csv +925 -0
  68. pytac/data/VMXSP/unitconv.csv +1384 -0
  69. pytac/data/VMXTHz/elements.csv +2143 -0
  70. pytac/data/VMXTHz/epics_devices.csv +2939 -0
  71. pytac/data/VMXTHz/families.csv +2575 -0
  72. pytac/data/VMXTHz/simple_devices.csv +2 -0
  73. pytac/data/VMXTHz/uc_pchip_data.csv +774 -0
  74. pytac/data/VMXTHz/uc_poly_data.csv +925 -0
  75. pytac/data/VMXTHz/unitconv.csv +1384 -0
  76. pytac/data_source.py +352 -0
  77. pytac/device.py +255 -0
  78. pytac/element.py +344 -0
  79. pytac/exceptions.py +33 -0
  80. pytac/lattice.py +696 -0
  81. pytac/load_csv.py +225 -0
  82. pytac/units.py +502 -0
  83. pytac/utils.py +54 -0
  84. pytac-0.6.0b1.dist-info/LICENSE +201 -0
  85. pytac-0.6.0b1.dist-info/METADATA +284 -0
  86. pytac-0.6.0b1.dist-info/RECORD +89 -0
  87. pytac-0.6.0b1.dist-info/WHEEL +5 -0
  88. pytac-0.6.0b1.dist-info/entry_points.txt +2 -0
  89. 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
@@ -0,0 +1,4 @@
1
+ # file generated by setuptools_scm
2
+ # don't change, don't track in version control
3
+ __version__ = version = '0.6.0b1'
4
+ __version_tuple__ = version_tuple = (0, 6, 0)
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()