epicsdev 3.2.1__tar.gz → 3.3.0__tar.gz

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 (34) hide show
  1. {epicsdev-3.2.1 → epicsdev-3.3.0}/PKG-INFO +1 -1
  2. {epicsdev-3.2.1 → epicsdev-3.3.0}/docs/using_imagegen.md +25 -0
  3. {epicsdev-3.2.1 → epicsdev-3.3.0}/epicsdev/epicsdev.py +14 -14
  4. {epicsdev-3.2.1 → epicsdev-3.3.0}/epicsdev/imagegen.py +7 -3
  5. epicsdev-3.3.0/examples/mini_beamline_caproto.py +286 -0
  6. {epicsdev-3.2.1 → epicsdev-3.3.0}/pyproject.toml +1 -1
  7. {epicsdev-3.2.1 → epicsdev-3.3.0}/.github/copilot-instructions.md +0 -0
  8. {epicsdev-3.2.1 → epicsdev-3.3.0}/LICENSE +0 -0
  9. {epicsdev-3.2.1 → epicsdev-3.3.0}/README.md +0 -0
  10. {epicsdev-3.2.1 → epicsdev-3.3.0}/config/epicsSimscope_pp.py +0 -0
  11. {epicsdev-3.2.1 → epicsdev-3.3.0}/config/epicsdev.bob +0 -0
  12. {epicsdev-3.2.1 → epicsdev-3.3.0}/config/epicsdev_pp.py +0 -0
  13. {epicsdev-3.2.1 → epicsdev-3.3.0}/docs/epicsdev_pvplot.jpg +0 -0
  14. {epicsdev-3.2.1 → epicsdev-3.3.0}/docs/epicsdev_pypet.png +0 -0
  15. {epicsdev-3.2.1 → epicsdev-3.3.0}/docs/imagegen.jpg +0 -0
  16. {epicsdev-3.2.1 → epicsdev-3.3.0}/docs/modules.md +0 -0
  17. {epicsdev-3.2.1 → epicsdev-3.3.0}/docs/phoebus_epicsdev.jpg +0 -0
  18. {epicsdev-3.2.1 → epicsdev-3.3.0}/epicsdev/__init__.py +0 -0
  19. {epicsdev-3.2.1 → epicsdev-3.3.0}/epicsdev/putlog.py +0 -0
  20. {epicsdev-3.2.1 → epicsdev-3.3.0}/examples/ai_imagegen.py +0 -0
  21. {epicsdev-3.2.1 → epicsdev-3.3.0}/examples/ndarray_server.py +0 -0
  22. {epicsdev-3.2.1 → epicsdev-3.3.0}/examples/ntndarray_server.py +0 -0
  23. {epicsdev-3.2.1 → epicsdev-3.3.0}/examples/process_external_waveform.py +0 -0
  24. {epicsdev-3.2.1 → epicsdev-3.3.0}/fallback/epicsdev-300.py +0 -0
  25. {epicsdev-3.2.1 → epicsdev-3.3.0}/fallback/multiadc-v311.py +0 -0
  26. {epicsdev-3.2.1 → epicsdev-3.3.0}/fallback/multiadc.py +0 -0
  27. {epicsdev-3.2.1 → epicsdev-3.3.0}/fallback/multiadc1_pp.py +0 -0
  28. {epicsdev-3.2.1 → epicsdev-3.3.0}/fallback/multiadc_pp.py +0 -0
  29. {epicsdev-3.2.1 → epicsdev-3.3.0}/new/README.md +0 -0
  30. {epicsdev-3.2.1 → epicsdev-3.3.0}/new/epicsdev.py +0 -0
  31. {epicsdev-3.2.1 → epicsdev-3.3.0}/new/multiadc.py +0 -0
  32. {epicsdev-3.2.1 → epicsdev-3.3.0}/new/pyproject.toml +0 -0
  33. {epicsdev-3.2.1 → epicsdev-3.3.0}/prompts/image_initial +0 -0
  34. {epicsdev-3.2.1 → epicsdev-3.3.0}/prompts/prompt_epics_development_with_python +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: epicsdev
3
- Version: 3.2.1
3
+ Version: 3.3.0
4
4
  Summary: Helper module for creating EPICS PVAccess servers using p4p
5
5
  Project-URL: Homepage, https://github.com/ASukhanov/epicsdev
6
6
  Project-URL: Bug Tracker, https://github.com/ASukhanov/epicsdev
@@ -22,4 +22,29 @@ iface.put('image0:noiseLevel',100); show()
22
22
  Click ROI and position the region of interest.
23
23
  Click Color gradient and select 'flame'.
24
24
 
25
+ Monitoring example:
26
+ ```python
27
+ def cb(value):
28
+ #print(f'value: {type(value),value}')
29
+ imageView.setImage(value.T, scale=(10,1))
30
+
31
+ subscribtion = iface.monitor('image0:image',cb)
32
+
33
+ # Now the image will be redrawn if its parameters gets changed
34
+ iface.put('image0:gridScaleX', .5)
35
+ iface.put('image0:gridScaleX', 1)
36
+ ```
37
+ # animation, controlled from separate process
38
+ In another terminal start python interpreter with following code:
39
+ ```python
40
+ import time, numpy as np
41
+ from p4p.client.thread import Context
42
+ iface = Context('pva')
43
+
44
+ oneTo0 = 1 - np.linspace(0,1,11)
45
+ scales = np.append(oneTo0[:-1], np.flip(oneTo0)[2:])
46
+ for scale in scales:
47
+ iface.put('image0:gridScaleX',scale)
48
+ time.sleep(.1)
49
+ ```
25
50
  ![imageView](./imagegen.jpg)
@@ -1,6 +1,6 @@
1
1
  """Helper functions for creating EPICS PVAccess server"""
2
2
  # pylint: disable=invalid-name
3
- __version__= 'v3.2.1 26-03-28'# Env. variable OPERATIONS is used for default autosave directory
3
+ __version__= 'v3.3.0 26-05-13'# Do not publish PV in its setter.
4
4
  #TODO: Add CBOR-encoded PVs representing arbitrary Python objects, that can be used for storing complex data structures, such as dictionaries, numpy arrays. That will be more efficient than using multiple PVs for each parameter, and more flexible than using JSON-encoded strings.
5
5
 
6
6
  import sys
@@ -251,6 +251,12 @@ def create_PVs(pvDefs, pvcache=None):
251
251
  vr = vv.raw.value
252
252
  ntNamedTuples = spv._wrap(spv.current())
253
253
  oldvr = ntNamedTuples['value']
254
+ try: # if it is ENum
255
+ index = oldvr.index
256
+ oldvr = oldvr.choices[index]
257
+ except: pass
258
+ #printv(f'oldvr: {type(oldvr)},{oldvr}')
259
+
254
260
  # check limits, if they are defined.
255
261
  try:
256
262
  limitLow = ntNamedTuples['control.limitLow']
@@ -265,14 +271,12 @@ def create_PVs(pvDefs, pvcache=None):
265
271
  vr = str(vv)
266
272
  if spv.setter:
267
273
  spv.setter(vr, spv)
268
- # value will be updated by the setter, so get it again
269
- vr = pvv(spv.name)
270
- #vr = spv._wrap(spv.current())['value']
271
- printv(f'putting {spv.name} = {vr}')
274
+ #printv(f'putting {spv.name} = {type(vr)} {vr}')
272
275
  ct = time.time()
273
276
  C_.lastPutTime = ct
274
277
  spv.post(vr, timestamp=ct) # update subscribers
275
278
 
279
+ #printv(f'putlog {spv.name} = {type(vr)} {vr}')
276
280
  if C_.putlogPV is not None:
277
281
  dt = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3].split()
278
282
  ip = op.peer().split(':')[3][:-1]# peer looks like: [::ffff:192.168.27.6]:46362
@@ -292,7 +296,6 @@ def set_verbose(level, *_):
292
296
  """Set verbosity level for debugging"""
293
297
  C_.verbose = level
294
298
  printi(f'Setting verbose to {level}')
295
- publish('verbose',level)
296
299
 
297
300
  def set_server(servState, *_):
298
301
  """Example of the setter for the server PV.
@@ -306,19 +309,15 @@ def set_server(servState, *_):
306
309
  C_.serverStateChanged(servState)
307
310
  if servState == 'Start':
308
311
  printi('Starting the server')
309
- publish('server','Started')
310
312
  publish('status','Started')
311
313
  elif servState == 'Stop':
312
314
  printi('server stopped')
313
- publish('server','Stopped')
314
315
  publish('status','Stopped')
315
316
  elif servState == 'Exit':
316
317
  printi('server is exiting')
317
- publish('server','Exited')
318
318
  publish('status','Exited')
319
319
  elif servState == 'Clear':
320
320
  publish('status','Cleared')
321
- # set server to previous servState
322
321
  set_server(C_.serverState)
323
322
  return
324
323
  C_.serverState = servState
@@ -450,7 +449,7 @@ def init_epicsdev(prefix:str, pvDefs:list, verbose=0, serverStateChanged=None,
450
449
  try:
451
450
  os.makedirs(autosaveDir, exist_ok=True)
452
451
  except PermissionError:
453
- printe(f'Permission denied to create {autosaveDir}. Use --autosave option.')
452
+ printe(f'Permission denied to create {autosaveDir}. You can define the root directory in OPERATIONS environment variable or disable autosaving.')
454
453
  sys.exit(1)
455
454
  autosaveFile = os.path.join(autosaveDir, f'{prefix[:-1]}.cache')
456
455
  C_.cachefd = open(autosaveFile, 'w')
@@ -563,7 +562,6 @@ if __name__ == "__main__":
563
562
  accordingly."""
564
563
  printi(f'Setting tAxis to {value}')
565
564
  publish('tAxis', np.arange(value)*1.E-6)
566
- publish('recordLength', value)
567
565
 
568
566
  def init(recordLength):
569
567
  """Example of device initialization function"""
@@ -622,11 +620,13 @@ if __name__ == "__main__":
622
620
  # The rest of options are not essential, they can be controlled at runtime using PVs.
623
621
  parser.add_argument('-n', '--npoints', type=int, default=100, help=
624
622
  'Number of points in the waveform')
625
- parser.add_argument('-p', '--putlogPV', default='putlog:dump', help=
626
- 'Name of the PV where put operations are logged. If None, then put operations are not logged.')
623
+ parser.add_argument('-p', '--putlogPV', nargs='?', default='', help=
624
+ 'PV name for logging put operations. If given without argument, then putlog is disabled. If not given, then putlog is set to "putlog:dump".')
627
625
  parser.add_argument('-v', '--verbose', action='count', default=0, help=
628
626
  'Show more log messages (-vv: show even more)')
629
627
  pargs = parser.parse_args()
628
+ if pargs.putlogPV == '':
629
+ pargs.putlogPV = 'putlog:dump'
630
630
  print(pargs)
631
631
 
632
632
  # Initialize epicsdev and PVs
@@ -7,13 +7,14 @@ the underlying blob pattern.
7
7
  PVs representing image rows and statistics PVs are updated periodically.
8
8
  """
9
9
  # pylint: disable=invalid-name
10
- __version__= 'v0.1.0 26-04-07'# added plobSigmaX and Y.
11
- import argparse
10
+ __version__= 'v0.1.1 26-04-11'# gridCsalex sclales image with respect to the center of the image
11
+
12
12
  from time import perf_counter as timer
13
+ import argparse
13
14
  import numpy as np
14
- from p4p.server import Server
15
15
 
16
16
  from epicsdev.epicsdev import (
17
+ Server,
17
18
  init_epicsdev,
18
19
  printi,
19
20
  publish,
@@ -62,6 +63,9 @@ def _gaussian_blob_grid_image() -> np.ndarray:
62
63
  dy = n_rows / (n_blobs_y)/2 if n_blobs_y > 0 else n_rows
63
64
  if n_blobs_x > 0 and n_blobs_y > 0 and blob_max > 0:
64
65
  x_centers = pvv('gridScaleX') * np.linspace(dx, n_cols - dx, n_blobs_x, dtype=np.float32)
66
+ print(f"Blob centers X before scaling: {x_centers}")
67
+ x_centers += n_cols/2. * (1 - pvv('gridScaleX')) # Scale centers with respect to the center of the image
68
+ print(f"Blob centers X after scaling: {x_centers}")
65
69
  y_centers = np.linspace(dy, n_rows - dy, n_blobs_y, dtype=np.float32)
66
70
  print(f"Blob centers X: {x_centers}, Y: {y_centers}")
67
71
 
@@ -0,0 +1,286 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ This example is quite large. It defines a range of simulated detectors and
4
+ motors and is used for demos and tutorials.
5
+ """
6
+ import contextvars
7
+ import functools
8
+ import math
9
+ import textwrap
10
+ import time
11
+
12
+ import numpy as np
13
+
14
+ from caproto.server import PVGroup, SubGroup, ioc_arg_parser, pvproperty, run
15
+
16
+ internal_process = contextvars.ContextVar("internal_process", default=False)
17
+
18
+
19
+ def no_reentry(func):
20
+ @functools.wraps(func)
21
+ async def inner(*args, **kwargs):
22
+ if internal_process.get():
23
+ return
24
+ try:
25
+ internal_process.set(True)
26
+ return await func(*args, **kwargs)
27
+ finally:
28
+ internal_process.set(False)
29
+
30
+ return inner
31
+
32
+
33
+ def _arrayify(func):
34
+ @functools.wraps(func)
35
+ def inner(*args):
36
+ return func(*(np.asarray(a) for a in args))
37
+
38
+ return inner
39
+
40
+
41
+ class _JitterDetector(PVGroup):
42
+ """
43
+ A jittery base class which assumes the subclass implements ``_read()``.
44
+
45
+ The pvproperty ``det`` will be periodically updated based on the result of
46
+ the subclass ``_read()``.
47
+ """
48
+ det = pvproperty(
49
+ value=0,
50
+ dtype=float,
51
+ read_only=True,
52
+ doc="Scalar detector value",
53
+ )
54
+
55
+ @det.scan(period=0.5)
56
+ async def det(self, instance, async_lib):
57
+ value = await self._read()
58
+ await self.det.write(value=value)
59
+
60
+ mtr = pvproperty(
61
+ value=0,
62
+ dtype=float,
63
+ precision=3,
64
+ record="ai",
65
+ doc="Motor",
66
+ )
67
+ exp = pvproperty(
68
+ value=1,
69
+ dtype=float,
70
+ doc="Exponential value",
71
+ )
72
+ vel = pvproperty(
73
+ value=1,
74
+ dtype=float,
75
+ doc="Velocity",
76
+ )
77
+
78
+ mtr_tick_rate = pvproperty(
79
+ value=10,
80
+ dtype=float,
81
+ units="Hz",
82
+ doc="Update tick rate",
83
+ )
84
+
85
+ @exp.putter
86
+ async def exp(self, instance, value):
87
+ value = np.clip(value, a_min=0, a_max=None)
88
+ return value
89
+
90
+ @mtr.startup
91
+ async def mtr(self, instance, async_lib):
92
+ instance.ev = async_lib.library.Event()
93
+ instance.async_lib = async_lib
94
+
95
+ @mtr.putter
96
+ @no_reentry
97
+ async def mtr(self, instance, value):
98
+ # "tick" at 10Hz
99
+ dwell = 1 / self.mtr_tick_rate.value
100
+
101
+ disp = value - instance.value
102
+ # compute the total movement time based an velocity
103
+ total_time = abs(disp / self.vel.value)
104
+ # compute how many steps, should come up short as there will
105
+ # be a final write of the return value outside of this call
106
+ N = int(total_time // dwell)
107
+
108
+ for j in range(N):
109
+ # hide a possible divide by 0
110
+ step_size = disp / N
111
+ await instance.write(instance.value + step_size)
112
+ await instance.async_lib.library.sleep(dwell)
113
+
114
+ return value
115
+
116
+
117
+ class PinHole(_JitterDetector):
118
+ """A pinhole simulation device."""
119
+
120
+ async def _read(self):
121
+ sigma = 5
122
+ center = 0
123
+ c = -1 / (2 * sigma * sigma)
124
+
125
+ @_arrayify
126
+ def jitter_read(m, e, intensity):
127
+ N = (
128
+ self.parent.N_per_I_per_s * intensity * e *
129
+ np.exp(c * (m - center) ** 2)
130
+ )
131
+ return np.random.poisson(N)
132
+
133
+ return jitter_read(self.mtr.value, self.exp.value, self.parent.current.value)
134
+
135
+
136
+ class Edge(_JitterDetector):
137
+ """An edge simulation device."""
138
+
139
+ async def _read(self):
140
+ sigma = 2.5
141
+ center = 5
142
+ c = 1 / sigma
143
+
144
+ @_arrayify
145
+ def jitter_read(m, e, intensity):
146
+ s = math.erfc(c * (-m + center)) / 2
147
+ N = self.parent.N_per_I_per_s * intensity * e * s
148
+ return np.random.poisson(N)
149
+
150
+ return jitter_read(self.mtr.value, self.exp.value, self.parent.current.value)
151
+
152
+
153
+ class Slit(_JitterDetector):
154
+ """A slit simulation device."""
155
+
156
+ async def _read(self):
157
+ sigma = 2.5
158
+ center = 7.5
159
+ c = 1 / sigma
160
+
161
+ @_arrayify
162
+ def jitter_read(m, e, intensity):
163
+ s = (math.erfc(c * (m - center)) - math.erfc(c * (m + center))) / 2
164
+
165
+ N = self.parent.N_per_I_per_s * intensity * e * s
166
+ return np.random.poisson(N)
167
+
168
+ return jitter_read(self.mtr.value, self.exp.value, self.parent.current.value)
169
+
170
+
171
+ class MovingDot(PVGroup):
172
+ N = 480
173
+ M = 640
174
+
175
+ sigmax = 50
176
+ sigmay = 25
177
+
178
+ background = 1000
179
+
180
+ Xcen = 0
181
+ Ycen = 0
182
+
183
+ det = pvproperty(
184
+ value=[0] * N * M,
185
+ dtype=float,
186
+ read_only=True,
187
+ doc=f"Detector image ({N}x{M})"
188
+ )
189
+
190
+ @det.scan(period=2.0)
191
+ async def det(self, instance, async_lib):
192
+ back = np.random.poisson(self.background, (self.N, self.M))
193
+ if not self.shutter_open.value:
194
+ await self.img_sum.write([back.sum()])
195
+ await instance.write(value=back.ravel())
196
+ return
197
+
198
+ Y, X = np.ogrid[:self.N, :self.M]
199
+
200
+ X = X - self.M / 2 + self.mtrx.value
201
+ Y = Y - self.N / 2 + self.mtry.value
202
+
203
+ X /= self.sigmax
204
+ Y /= self.sigmay
205
+
206
+ dot = (
207
+ np.exp(-(X ** 2 + Y ** 2) / 2) *
208
+ np.exp(-(self.mtrx.value ** 2 + self.mtry.value ** 2) / 100 ** 2)
209
+ )
210
+
211
+ I = self.parent.current.value # noqa
212
+ e = self.exp.value
213
+ measured = self.parent.N_per_I_per_s * dot * e * I
214
+ ret = back + np.random.poisson(measured)
215
+ await self.img_sum.write(value=ret.sum())
216
+ await instance.write(value=ret.ravel())
217
+
218
+ img_sum = pvproperty(value=0, read_only=True, dtype=float, doc="Image sum")
219
+ mtrx = pvproperty(value=0, dtype=float, doc="Motor X")
220
+ mtry = pvproperty(value=0, dtype=float, doc="Motor Y")
221
+
222
+ exp = pvproperty(value=1, dtype=float)
223
+
224
+ @exp.putter
225
+ async def exp(self, instance, value):
226
+ """Clip the value to be >= 0."""
227
+ return np.clip(value, a_min=0, a_max=None)
228
+
229
+ shutter_open = pvproperty(
230
+ value=1,
231
+ dtype=int,
232
+ doc="Shutter open/close",
233
+ )
234
+ ArraySizeY_RBV = pvproperty(
235
+ value=N,
236
+ dtype=int,
237
+ read_only=True,
238
+ doc='Image array size Y'
239
+ )
240
+ ArraySizeX_RBV = pvproperty(
241
+ value=M,
242
+ dtype=int,
243
+ read_only=True,
244
+ doc='Image array size X'
245
+ )
246
+ ArraySize_RBV = pvproperty(
247
+ value=[N, M],
248
+ dtype=int,
249
+ read_only=True,
250
+ doc='Image array size [Y, X]',
251
+ )
252
+
253
+
254
+ class MiniBeamline(PVGroup):
255
+ """
256
+ A collection of detectors coupled to motors and an oscillating beam
257
+ current.
258
+
259
+ An IOC that provides a simulated pinhole, edge and slit with coupled with a
260
+ shared global current that oscillates in time.
261
+ """
262
+
263
+ N_per_I_per_s = 200
264
+
265
+ current = pvproperty(value=500, dtype=float, read_only=True)
266
+
267
+ @current.scan(period=0.1)
268
+ async def current(self, instance, async_lib):
269
+ current = 500 + 25 * np.sin(time.monotonic() * (2 * np.pi) / 4)
270
+ await instance.write(value=current)
271
+
272
+ ph = SubGroup(PinHole, doc="Simulated pinhole")
273
+ edge = SubGroup(Edge, doc="Simulated edge")
274
+ slit = SubGroup(Slit, doc="Simulated slit")
275
+
276
+ dot = SubGroup(MovingDot, doc="The simulated detector")
277
+
278
+
279
+ if __name__ == "__main__":
280
+ ioc_options, run_options = ioc_arg_parser(
281
+ default_prefix="mini:",
282
+ desc=textwrap.dedent(MiniBeamline.__doc__),
283
+ )
284
+
285
+ ioc = MiniBeamline(**ioc_options)
286
+ run(ioc.pvdb, **run_options)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "epicsdev"
7
- version = "3.2.1"
7
+ version = "3.3.0"
8
8
  authors = [
9
9
  { name="Andrey Sukhanov", email="sukhanov@bnl.gov" },
10
10
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes