pvplot 1.3.4__tar.gz → 1.3.5__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.
- {pvplot-1.3.4 → pvplot-1.3.5}/PKG-INFO +1 -1
- pvplot-1.3.5/pvplot/cad_epics.py +191 -0
- pvplot-1.3.4/pvplot/pvplot_todo_disable_plot.py → pvplot-1.3.5/pvplot/pvplot-123a.py +26 -19
- {pvplot-1.3.4 → pvplot-1.3.5}/pvplot/pvplot.py +2 -2
- {pvplot-1.3.4 → pvplot-1.3.5}/pyproject.toml +1 -1
- pvplot-1.3.4/config.py +0 -48
- pvplot-1.3.4/config_proposal.py +0 -40
- pvplot-1.3.4/pvplot/pvplot_tmp.py +0 -875
- {pvplot-1.3.4 → pvplot-1.3.5}/LICENSE +0 -0
- {pvplot-1.3.4 → pvplot-1.3.5}/README.md +0 -0
- {pvplot-1.3.4 → pvplot-1.3.5}/cad_epics/__init__.py +0 -0
- {pvplot-1.3.4 → pvplot-1.3.5}/cad_epics/epics.py +0 -0
- {pvplot-1.3.4 → pvplot-1.3.5}/config/peakSimulator_pvp.py +0 -0
- {pvplot-1.3.4 → pvplot-1.3.5}/pvplot/__init__.py +0 -0
- {pvplot-1.3.4 → pvplot-1.3.5}/pvplot/__main__.py +0 -0
- {pvplot-1.3.4 → pvplot-1.3.5}/pvplot/helptxt.py +0 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Basic EPICS access API using caproto threading.
|
|
2
|
+
The API is similar to cad_io.
|
|
3
|
+
The devPar argument is tuple (deviceName,parameterName).
|
|
4
|
+
The EPICS PV name is concatenation of the deviceName and parameterName
|
|
5
|
+
|
|
6
|
+
For example: epics.get(('testAPD:scope1:','MaxValue_RBV')) returns
|
|
7
|
+
{('testAPD:scope1:', 'MaxValue_RBV'): {'value': 1.5620877339306638, 'timestamp': 1681488886.923712, 'alarm': 0}}
|
|
8
|
+
"""
|
|
9
|
+
__version__ = 'v0.0.2 2023-04-14'# No colon separation when splitting PV name to (device,parameter) tuple.
|
|
10
|
+
|
|
11
|
+
#from time import perf_counter as timer
|
|
12
|
+
|
|
13
|
+
from caproto.threading.client import Context
|
|
14
|
+
_Ctx = Context()
|
|
15
|
+
|
|
16
|
+
_PVCache = {}# cache of PVs
|
|
17
|
+
# the key is EPICS PV name, the fields are as follows:
|
|
18
|
+
_PVC_PV = 0# EPICS PV object
|
|
19
|
+
_PVC_CB = 1# callback
|
|
20
|
+
_PVC_Props = 2# PV properties
|
|
21
|
+
_PVC_DevPar = 3# (deviceName, ParameterName)
|
|
22
|
+
|
|
23
|
+
_Subscriptions = []# list of EPICS PV subscriptions
|
|
24
|
+
|
|
25
|
+
_CA_data_type_STRING = 14
|
|
26
|
+
|
|
27
|
+
_dbg = False
|
|
28
|
+
def _printd(msg):
|
|
29
|
+
if _dbg:
|
|
30
|
+
print(f'CPAccess:{msg}')
|
|
31
|
+
|
|
32
|
+
def init():
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
def _get_pv(devPar:tuple):
|
|
36
|
+
pvName = ''.join(devPar)
|
|
37
|
+
r = _PVCache.get(pvName)
|
|
38
|
+
if r is None:
|
|
39
|
+
_printd(f'register pv {pvName} {devPar}')
|
|
40
|
+
pv,*_ = _Ctx.get_pvs(''.join(pvName), timeout=2)
|
|
41
|
+
_PVCache[pvName] = [pv, None, None, devPar]
|
|
42
|
+
_fill_PVCacheProps(pv)
|
|
43
|
+
else:
|
|
44
|
+
pv,*_ = r
|
|
45
|
+
return pv
|
|
46
|
+
|
|
47
|
+
def _fill_PVCacheProps(pv):
|
|
48
|
+
pvName = pv.name
|
|
49
|
+
pvData = pv.read(data_type='time')
|
|
50
|
+
val = pvData.data
|
|
51
|
+
if len(val) == 1:
|
|
52
|
+
try:
|
|
53
|
+
# treat it as numpy
|
|
54
|
+
val = pvData.data[0].item()
|
|
55
|
+
except:
|
|
56
|
+
# data is not numpy
|
|
57
|
+
val = pvData.data[0]
|
|
58
|
+
|
|
59
|
+
# get properties
|
|
60
|
+
#ISSUE: the caproto reports timestamp as float, the precision for float64
|
|
61
|
+
#presentation is ~300ns
|
|
62
|
+
featureBit2Letter = {1:'R', 2:'WE'}
|
|
63
|
+
featureCode = pv.access_rights
|
|
64
|
+
features = ''
|
|
65
|
+
for bit, letter in featureBit2Letter.items():
|
|
66
|
+
if bit & featureCode:
|
|
67
|
+
features += letter
|
|
68
|
+
pvControl = pv.read(data_type='control')
|
|
69
|
+
#_printd(f'pvcontrol {pvName}: {pvControl}')
|
|
70
|
+
datatype = pvControl.data_type
|
|
71
|
+
#_printd(f'data_type:{datatype}')
|
|
72
|
+
if datatype == _CA_data_type_STRING:# convert text bytearray to str
|
|
73
|
+
val = val.decode()
|
|
74
|
+
props = {'value':val}
|
|
75
|
+
props['timestamp'] = pvData.metadata.timestamp
|
|
76
|
+
props['count'] = len(pvData.data)
|
|
77
|
+
props['features'] = features
|
|
78
|
+
try:
|
|
79
|
+
props['units'] = pvControl.metadata.units.decode()
|
|
80
|
+
if props['units'] == '': props['units'] = None
|
|
81
|
+
except: pass
|
|
82
|
+
|
|
83
|
+
try: props['engLow'] = pvControl.metadata.lower_ctrl_limit
|
|
84
|
+
except: pass
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
props['engHigh'] = pvControl.metadata.upper_ctrl_limit
|
|
88
|
+
if props['engHigh'] == 0.0 and props['engHigh'] == 0.0:
|
|
89
|
+
props['engHigh'], props['engLow'] = None, None
|
|
90
|
+
except: pass
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
props['alarm'] = pvControl.metadata.severity
|
|
94
|
+
#_printd(f'status {pvControl.metadata.severity}')
|
|
95
|
+
if props['alarm'] == 17:# UDF
|
|
96
|
+
props['alarm'] = None
|
|
97
|
+
except: pass
|
|
98
|
+
|
|
99
|
+
try: # legalValues
|
|
100
|
+
enum_strings = pvControl.metadata.enum_strings
|
|
101
|
+
props['legalValues'] = [i.decode() for i in enum_strings]
|
|
102
|
+
props['value'] = props['legalValues'][val]
|
|
103
|
+
except:
|
|
104
|
+
#props['legalValues'] = None
|
|
105
|
+
if 'legalValues' in props:
|
|
106
|
+
del props['legalValues']
|
|
107
|
+
#_printd(f'_props {props}')
|
|
108
|
+
_PVCache[pvName][_PVC_Props] = props
|
|
109
|
+
|
|
110
|
+
def info(devPar:tuple):
|
|
111
|
+
"""Abridged PV info"""
|
|
112
|
+
pvName = ''.join(devPar)
|
|
113
|
+
pv = _get_pv(devPar)
|
|
114
|
+
return {devPar:_PVCache[pvName][_PVC_Props]}
|
|
115
|
+
|
|
116
|
+
def get(devPar:tuple, *args, **kwargs):
|
|
117
|
+
'''Returns devPar-keyed map of PV properties: {'value','timestamp'...}'''
|
|
118
|
+
pvName = ''.join(devPar)
|
|
119
|
+
pv = _get_pv(devPar)
|
|
120
|
+
pvData = pv.read(data_type='time')
|
|
121
|
+
rDict = _unpack_ReadNotifyResponse(pvName, pvData)
|
|
122
|
+
return rDict
|
|
123
|
+
|
|
124
|
+
def set(devParValue:tuple):
|
|
125
|
+
'''Sets the PV value. The devParValue is (deviceName, ParameterName, value)
|
|
126
|
+
'''
|
|
127
|
+
dev, par, value = devParValue
|
|
128
|
+
#print(f'epicsAccess.set({dev,par,value})')
|
|
129
|
+
pvName = ''.join((dev,par))
|
|
130
|
+
pv = _get_pv((dev,par))
|
|
131
|
+
try: # if PV has legalValues then the value should be index of legalValues
|
|
132
|
+
value = _PVCache[pvName][_PVC_Props]['legalValues'].index(value)
|
|
133
|
+
except Exception as e:
|
|
134
|
+
#print(f'in epicsAccess.set. Value not in legalValues: {e}')
|
|
135
|
+
pass
|
|
136
|
+
pv.write(value)
|
|
137
|
+
return 1
|
|
138
|
+
|
|
139
|
+
def _unpack_ReadNotifyResponse(pvName:str, pvData):
|
|
140
|
+
val = pvData.data
|
|
141
|
+
if len(val) == 1:
|
|
142
|
+
try: #it as numpy
|
|
143
|
+
val = pvData.data[0].item()
|
|
144
|
+
except: # it is not numpy
|
|
145
|
+
val = pvData.data[0]
|
|
146
|
+
#_printd(f'pvData:{pvData}')
|
|
147
|
+
#_printd(f'val:{val}, {pvData.data_type}')
|
|
148
|
+
if pvData.data_type == _CA_data_type_STRING:
|
|
149
|
+
val = val.decode()
|
|
150
|
+
|
|
151
|
+
legalValues = _PVCache[pvName][_PVC_Props].get('legalValues')
|
|
152
|
+
if legalValues is not None:
|
|
153
|
+
#rDict['value'] = legalValues[int(val)]
|
|
154
|
+
val = legalValues[int(val)]
|
|
155
|
+
alarm = pvData.metadata.severity
|
|
156
|
+
key = _PVCache[pvName][_PVC_DevPar]
|
|
157
|
+
rDict = {key: {'value':val\
|
|
158
|
+
, 'timestamp':pvData.metadata.timestamp, 'alarm': alarm}}
|
|
159
|
+
return rDict
|
|
160
|
+
|
|
161
|
+
def _callback(subscription, pvData):
|
|
162
|
+
#tMark = [timer(), 0., 0.]
|
|
163
|
+
pvName = subscription.pv.name
|
|
164
|
+
_printd(f'>epicsAccess._callback: {pvName}')#{pvData})')
|
|
165
|
+
rDict = _unpack_ReadNotifyResponse(pvName, pvData)
|
|
166
|
+
#tMark[1] = timer()
|
|
167
|
+
cache = _PVCache.get(pvName)
|
|
168
|
+
cb = cache[_PVC_CB]
|
|
169
|
+
if cb:
|
|
170
|
+
cb(rDict)
|
|
171
|
+
#tMark[2] = timer() - tMark[1]
|
|
172
|
+
#tMark[1] -= tMark[0]
|
|
173
|
+
##_printd(f'caproto cb times {tMark}')# 20-30 uS
|
|
174
|
+
|
|
175
|
+
def subscribe(callback:callable, devPar:tuple):
|
|
176
|
+
'''Subscribe callback method to changes of PVs, defined by devPar'''
|
|
177
|
+
pvName = ''.join(devPar)
|
|
178
|
+
pv = _get_pv(devPar)
|
|
179
|
+
subscription = pv.subscribe(data_type='time')
|
|
180
|
+
_PVCache[pvName][_PVC_CB] = callback
|
|
181
|
+
subscription.add_callback(_callback)
|
|
182
|
+
_Subscriptions.append(subscription)
|
|
183
|
+
|
|
184
|
+
def unsubscribe():
|
|
185
|
+
'''Unsubscribe all subscriptions'''
|
|
186
|
+
global _Subscriptions
|
|
187
|
+
for subscription in _Subscriptions:
|
|
188
|
+
#print(f'>epicsAccess clear subs: {subscription}')
|
|
189
|
+
subscription.clear()
|
|
190
|
+
_Subscriptions = []
|
|
191
|
+
|
|
@@ -321,6 +321,12 @@ class Dataset():
|
|
|
321
321
|
self.plotWidget.addItem(self.plotItem)
|
|
322
322
|
self.lastTimePlotted = 0.
|
|
323
323
|
|
|
324
|
+
def add_plot(self):
|
|
325
|
+
self.plotWidget.addItem(self.plotItem)
|
|
326
|
+
|
|
327
|
+
def remove_plot(self):
|
|
328
|
+
self.plotWidget.removeItem(self.plotItem)
|
|
329
|
+
|
|
324
330
|
def __str__(self):
|
|
325
331
|
return f'Dataset {self.name}, x: {self.data[X].shape}'
|
|
326
332
|
|
|
@@ -346,12 +352,10 @@ class Dataset():
|
|
|
346
352
|
self.viewBox.setXRange(self.viewXRange[0], self.viewXRange[1])
|
|
347
353
|
|
|
348
354
|
def plot(self, ts):
|
|
349
|
-
# Plot the dataset
|
|
350
|
-
print(f'>plot: {self.name, self.enabled}')
|
|
351
|
-
if not self.enabled:
|
|
352
|
-
return
|
|
355
|
+
# Plot the dataset. It may be several updates between these calls.
|
|
353
356
|
if self.lastTimePlotted == ts:
|
|
354
357
|
return
|
|
358
|
+
printv(f'>plot: {self.name}')
|
|
355
359
|
self.lastTimePlotted = ts
|
|
356
360
|
#print(f'>plot: {self.name, {self.dataPtr}, round(ts,3)}')
|
|
357
361
|
x = self.data[X][:self.dataPtr]
|
|
@@ -376,9 +380,6 @@ class Dataset():
|
|
|
376
380
|
|
|
377
381
|
def update_plot(self, time2plot):
|
|
378
382
|
curvePars = self.adoPars
|
|
379
|
-
if not self.enabled:
|
|
380
|
-
return
|
|
381
|
-
print(f'update_plot: {self.name,curvePars}')
|
|
382
383
|
yd,ts = None,None
|
|
383
384
|
try:
|
|
384
385
|
#Limitation: only one (first) curve will be plotted
|
|
@@ -390,10 +391,11 @@ class Dataset():
|
|
|
390
391
|
if ts:
|
|
391
392
|
if ts == self.lastTimeUpdated:
|
|
392
393
|
self.dataChanged = False
|
|
393
|
-
|
|
394
|
-
if time2plot:
|
|
395
|
-
|
|
394
|
+
printv(f'curve {self.name} did not change {round(ts,3)}')
|
|
395
|
+
#if time2plot:
|
|
396
|
+
# self.plot(ts)
|
|
396
397
|
return
|
|
398
|
+
printv(f'update_plot: {self.name,curvePars}')
|
|
397
399
|
self.dataChanged = True
|
|
398
400
|
self.lastTimeUpdated = ts
|
|
399
401
|
#printv(f'update_plot: {curvePars}, data:{yd}')
|
|
@@ -531,6 +533,7 @@ class MapOfDatasets():
|
|
|
531
533
|
pnameAndCount.append((adoPar,count))
|
|
532
534
|
printv('adding '+str(pnameAndCount)+' to datasets['+curveName+']')
|
|
533
535
|
MapOfDatasets.dtsDict[curveName] = Dataset(dockNum, curveName, pnameAndCount)
|
|
536
|
+
PVPlot.mapOfCurves[dockNum].append(curveName)
|
|
534
537
|
printv(f'MapOfDatasets: {[(k,v.adoPars) for k ,v in MapOfDatasets.dtsDict.items()]}')
|
|
535
538
|
return 0
|
|
536
539
|
|
|
@@ -717,22 +720,21 @@ class CustomViewBox(pg.ViewBox):
|
|
|
717
720
|
tbl.setShowGrid(False)
|
|
718
721
|
tbl.setSizeAdjustPolicy(
|
|
719
722
|
QW.QAbstractScrollArea.AdjustToContents)
|
|
720
|
-
tbl.resize(*dlgSize)
|
|
723
|
+
#tbl.resize(*dlgSize)
|
|
724
|
+
tbl.resize()
|
|
721
725
|
|
|
722
|
-
|
|
723
|
-
for row,dataitem in enumerate(listOfItems):
|
|
726
|
+
for row,curveName in enumerate(PVPlot.mapOfCurves[self.dockNum]):
|
|
724
727
|
tbl.insertRow(row)
|
|
725
|
-
curveName = dataitem.name()
|
|
726
728
|
printv(f'curveName:{curveName}')
|
|
729
|
+
dataset = MapOfDatasets.dtsDict[curveName]
|
|
727
730
|
col = 0
|
|
728
731
|
cbox = QW.QCheckBox()
|
|
729
|
-
cbox.setChecked(
|
|
732
|
+
cbox.setChecked(dataset.enabled)
|
|
730
733
|
#cbox.stateChanged.connect(lambda x: self.enable_dataset(x))
|
|
731
734
|
cbox.stateChanged.connect(self.enable_dataset)
|
|
732
735
|
cbox.setObjectName(curveName)
|
|
733
736
|
tbl.setCellWidget(row, col, cbox)
|
|
734
737
|
col+=1
|
|
735
|
-
dataset = MapOfDatasets.dtsDict[curveName]
|
|
736
738
|
adoparName = dataset.adoPars[0][0]
|
|
737
739
|
tbl.setItem(row, col, QW.QTableWidgetItem(curveName))
|
|
738
740
|
col+=1
|
|
@@ -856,7 +858,10 @@ class CustomViewBox(pg.ViewBox):
|
|
|
856
858
|
def enable_dataset(self, state):
|
|
857
859
|
dtsetName = str(self.sender().objectName())
|
|
858
860
|
print(f'enable_dataset {dtsetName, (state==QtCore.Qt.Checked)}')
|
|
859
|
-
MapOfDatasets.dtsDict[dtsetName]
|
|
861
|
+
dataset = MapOfDatasets.dtsDict[dtsetName]
|
|
862
|
+
enabled = (state==QtCore.Qt.Checked)
|
|
863
|
+
dataset.enabled = enabled
|
|
864
|
+
dataset.add_plot() if enabled else dataset.remove_plot()
|
|
860
865
|
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
861
866
|
|
|
862
867
|
def callback(args):
|
|
@@ -891,6 +896,7 @@ def add_curves(dockNum:int, curveMap:str):
|
|
|
891
896
|
else:
|
|
892
897
|
PVPlot.dockArea.addDock(PVPlot.mapOfDocks[dockNum],
|
|
893
898
|
'top', PVPlot.mapOfDocks[0], closable=True) #TODO:closable does not work
|
|
899
|
+
PVPlot.mapOfCurves[dockNum] = []
|
|
894
900
|
if MapOfDatasets.add(dockNum, curveMap):
|
|
895
901
|
printe(f'in add_curves: {dockNum, curveMap}')
|
|
896
902
|
|
|
@@ -928,8 +934,9 @@ def parse_input_parameters(pargs):
|
|
|
928
934
|
class PVPlot():
|
|
929
935
|
config = None
|
|
930
936
|
pargs = None
|
|
931
|
-
mapOfPlotWidgets = {}
|
|
932
|
-
mapOfDocks = {}
|
|
937
|
+
mapOfPlotWidgets = {}# active plotItems
|
|
938
|
+
mapOfDocks = {}# dockAreas
|
|
939
|
+
mapOfCurves = {}
|
|
933
940
|
padding = 0.1
|
|
934
941
|
scaleUnits = [[1,'Sample'],[1,'Count']]
|
|
935
942
|
subscribedParMap = {}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""Plotting package for EPICS PVs, ADO and LITE parameters.
|
|
3
3
|
"""
|
|
4
|
-
__version__ = 'v1.3.
|
|
4
|
+
__version__ = 'v1.3.5 2024-10-23'# cad_epics integrated
|
|
5
5
|
#TODO: if backend times out the gui is not responsive
|
|
6
6
|
#TODO: move Add Dataset to Dataset options
|
|
7
7
|
#TODO: add dataset arithmetics
|
|
@@ -63,7 +63,7 @@ def prettyDict(rDict, lineLimit=75):
|
|
|
63
63
|
r += croppedText(f' {parVals}',lineLimit)+'\n'
|
|
64
64
|
return r
|
|
65
65
|
|
|
66
|
-
try: from
|
|
66
|
+
try: from pvplot import cad_epics as EPICSAccess
|
|
67
67
|
except Exception as e:
|
|
68
68
|
EPICSAccess = None
|
|
69
69
|
printw(f'EPICS devices are not supported on this host: {e}')
|
pvplot-1.3.4/config.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
""" Pvplot configuration for litePeakSimulator, serving port 9710 at localhost.
|
|
2
|
-
The command line to start litePeakSimulator:
|
|
3
|
-
python3 -m liteserver.device.litePeakSimulator -ilo -p9710
|
|
4
|
-
"""
|
|
5
|
-
configFormat='pvplot'
|
|
6
|
-
TITLE="PeakSimulator"
|
|
7
|
-
|
|
8
|
-
""" The following variables are not handled yet:
|
|
9
|
-
YES = 1
|
|
10
|
-
POLLPERIOD = 0
|
|
11
|
-
MINPOLLPERIOD = 0
|
|
12
|
-
POLLBEFOREASYNC = 1
|
|
13
|
-
AVERAGETYPE = none
|
|
14
|
-
LOGFORMAT = logger
|
|
15
|
-
LOGPERIODSEC = 0
|
|
16
|
-
LOGMETHOD = 'continuous'
|
|
17
|
-
LOGDESCRIPTION = ""
|
|
18
|
-
LOGCORRELATION = 'NOTREQUIRED'
|
|
19
|
-
FILLDATA = YES
|
|
20
|
-
LOGTREEPATH = '/operations/app_store/RunData/currentFill/'
|
|
21
|
-
PREFERREDLOGDISPLAY = Snapshot
|
|
22
|
-
XLABEL = "Time (us)"
|
|
23
|
-
YLABEL = "V"
|
|
24
|
-
DATASTAMPTYPE = 'WCTPERIOD'
|
|
25
|
-
WCTCORRPERIOD_MSEC = 1000
|
|
26
|
-
WCTCORRWINDOW_MSEC = 1000
|
|
27
|
-
SYNCHRONIZED = 0
|
|
28
|
-
YMINAUTOSCALE = 2
|
|
29
|
-
YMAXAUTOSCALE = 2
|
|
30
|
-
YLOGAXIS = 0
|
|
31
|
-
Y2LABEL = ""
|
|
32
|
-
Y2MINAUTOSCALE = 2
|
|
33
|
-
Y2MAXAUTOSCALE = 2
|
|
34
|
-
Y2LOGAXIS = 0
|
|
35
|
-
ERRORBARS = 0
|
|
36
|
-
FONTTYPE = 'Medium'
|
|
37
|
-
KEEPPREVIOUS = 0
|
|
38
|
-
"""
|
|
39
|
-
dev='L:localhost;9710:dev1:'
|
|
40
|
-
|
|
41
|
-
DOCKS = [
|
|
42
|
-
{'YMax':f'device({dev}yMax)',
|
|
43
|
-
'YMin':f'device({dev}yMin)',
|
|
44
|
-
'Y[10]':f'device({dev}y[500])',
|
|
45
|
-
},
|
|
46
|
-
{'YvsX':(f'device({dev}x)',f'device({dev}y)'),
|
|
47
|
-
}
|
|
48
|
-
]
|
pvplot-1.3.4/config_proposal.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
configFormat='pvplot'
|
|
2
|
-
TITLE="Blue Injection Scope"
|
|
3
|
-
POLLPERIOD 0
|
|
4
|
-
MINPOLLPERIOD 0
|
|
5
|
-
POLLBEFOREASYNC 1
|
|
6
|
-
AVERAGETYPE none
|
|
7
|
-
LOGFORMAT logger
|
|
8
|
-
LOGPERIODSEC 0
|
|
9
|
-
LOGMETHOD continuous
|
|
10
|
-
LOGDESCRIPTION ""
|
|
11
|
-
LOGCORRELATION NOTREQUIRED
|
|
12
|
-
FILLDATA YES
|
|
13
|
-
LOGTREEPATH /operations/app_store/RunData/currentFill/
|
|
14
|
-
PREFERREDLOGDISPLAY Snapshot
|
|
15
|
-
XLABEL "Time (us)"
|
|
16
|
-
YLABEL "kV (at 1 V/div)"
|
|
17
|
-
DATASTAMPTYPE WCTPERIOD
|
|
18
|
-
WCTCORRPERIOD_MSEC 1000
|
|
19
|
-
WCTCORRWINDOW_MSEC 1000
|
|
20
|
-
SYNCHRONIZED 0
|
|
21
|
-
YMINAUTOSCALE 2
|
|
22
|
-
YMAXAUTOSCALE 2
|
|
23
|
-
YLOGAXIS 0
|
|
24
|
-
Y2LABEL ""
|
|
25
|
-
Y2MINAUTOSCALE 2
|
|
26
|
-
Y2MAXAUTOSCALE 2
|
|
27
|
-
Y2LOGAXIS 0
|
|
28
|
-
ERRORBARS 0
|
|
29
|
-
FONTTYPE Medium
|
|
30
|
-
KEEPPREVIOUS 0
|
|
31
|
-
SNAPREFRESHMODE 2
|
|
32
|
-
SNAPSUBCYCLES 1 2 3 4 5 6 7 8 9 10
|
|
33
|
-
|
|
34
|
-
dev='tek5Scope.inject7W_blu:'
|
|
35
|
-
|
|
36
|
-
#STATIC Time= 1.e6*device(tek5Scope.inject7W_blu:tAxis[*])
|
|
37
|
-
DOCKS =
|
|
38
|
-
[
|
|
39
|
-
{f'Module{i}':f'device({dev}c{i}WaveforM:value[*])*a+b' for i in [1,2,3,4]}
|
|
40
|
-
]
|
|
@@ -1,875 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Plotting package for EPICS PVs, ADO and LITE parameters.
|
|
3
|
-
"""
|
|
4
|
-
__version__ = 'v0.6.8 2024-05-10'#
|
|
5
|
-
#TODO: if backend times out the gui is not responsive
|
|
6
|
-
#TODO: add_curves is not correct for multiple curves
|
|
7
|
-
#TODO: move Add Dataset to Dataset options
|
|
8
|
-
#TODO: if docks are stripcharts then zooming should be synchronized
|
|
9
|
-
#TODO: add dataset arithmetics
|
|
10
|
-
|
|
11
|
-
import sys, os, time
|
|
12
|
-
timer = time.perf_counter
|
|
13
|
-
import numpy as np
|
|
14
|
-
from qtpy import QtWidgets as QW, QtGui, QtCore
|
|
15
|
-
from qtpy.QtWidgets import QApplication, QMainWindow, QGridLayout
|
|
16
|
-
import pyqtgraph as pg
|
|
17
|
-
from pyqtgraph.graphicsItems.ViewBox.ViewBoxMenu import ViewBoxMenu
|
|
18
|
-
from pyqtgraph import dockarea
|
|
19
|
-
from functools import partial
|
|
20
|
-
|
|
21
|
-
#````````````````````````````Constants````````````````````````````````````````
|
|
22
|
-
X,Y = 0,1
|
|
23
|
-
Scale,Units = 0,1
|
|
24
|
-
#````````````````````````````Helper methods```````````````````````````````````
|
|
25
|
-
def printTime(): return time.strftime("%m%d:%H%M%S")
|
|
26
|
-
def printi(msg): print((f'INFO_PP@{printTime()}: '+msg))
|
|
27
|
-
def printw(msg): print((f'WARN_PP@{printTime()}: '+msg))
|
|
28
|
-
def printe(msg): print((f'ERR_PP@{printTime()}: '+msg))
|
|
29
|
-
def _printv(msg, level=0):
|
|
30
|
-
if PVPlot.pargs.verbose is None:
|
|
31
|
-
return
|
|
32
|
-
if len(PVPlot.pargs.verbose) >= level:
|
|
33
|
-
print((f'DBG{level}_PP@{printTime()}: '+msg))
|
|
34
|
-
def printv(msg): _printv(msg, 0)
|
|
35
|
-
def printvv(msg): _printv(msg, 1)
|
|
36
|
-
|
|
37
|
-
def croppedText(txt, limit=200):
|
|
38
|
-
if len(txt) > limit:
|
|
39
|
-
txt = txt[:limit]+'...'
|
|
40
|
-
return txt
|
|
41
|
-
def prettyDict(rDict, lineLimit=75):
|
|
42
|
-
r=''
|
|
43
|
-
for dev,devVals in rDict.items():
|
|
44
|
-
r += dev+'\n'
|
|
45
|
-
for par, parVals in devVals.items():
|
|
46
|
-
r += ' '+par+':'
|
|
47
|
-
if isinstance(parVals,dict):
|
|
48
|
-
r += '\n'
|
|
49
|
-
for attr, attrVal in parVals.items():
|
|
50
|
-
r += croppedText(f' {attr}: {attrVal}',lineLimit)+'\n'
|
|
51
|
-
else:
|
|
52
|
-
r += croppedText(f' {parVals}',lineLimit)+'\n'
|
|
53
|
-
return r
|
|
54
|
-
|
|
55
|
-
try: from cad_epics import epics as EPICSAccess
|
|
56
|
-
except Exception as e:
|
|
57
|
-
EPICSAccess = None
|
|
58
|
-
printw(f'EPICS devices are not supported on this host: {e}')
|
|
59
|
-
try:
|
|
60
|
-
import liteaccess as liteAccess
|
|
61
|
-
LITEAccess = liteAccess.Access
|
|
62
|
-
print(f'liteAccess {liteAccess.__version__}')
|
|
63
|
-
except Exception as e:
|
|
64
|
-
printw(f'LITE devices are not supported on this host: {e}')
|
|
65
|
-
LITEAccess = None
|
|
66
|
-
try:
|
|
67
|
-
from cad_io import adoaccess
|
|
68
|
-
ADOAccess = adoaccess.IORequest()
|
|
69
|
-
except Exception as e:
|
|
70
|
-
printw(f'ADO devices are not supported on this host: {e}')
|
|
71
|
-
ADOAccess = None
|
|
72
|
-
|
|
73
|
-
def cprint(msg):
|
|
74
|
-
print('cprint:'+msg)
|
|
75
|
-
|
|
76
|
-
def get_pv(adopar:str, prop='value'):
|
|
77
|
-
#print(f'>get_pv {adopar}')
|
|
78
|
-
adopar, vslice = split_slice(adopar)
|
|
79
|
-
access = PVPlot.access.get(adopar[:2], (ADOAccess,0))
|
|
80
|
-
access,prefixLength = PVPlot.access.get(adopar[:2], (ADOAccess,0))
|
|
81
|
-
if access is None:
|
|
82
|
-
printe(f'No access method for `{adopar}`')
|
|
83
|
-
sys.exit(1)
|
|
84
|
-
|
|
85
|
-
pvTuple = tuple(adopar[prefixLength:].rsplit(':',1))
|
|
86
|
-
rd = access.get(pvTuple)[pvTuple]
|
|
87
|
-
val = rd['value']
|
|
88
|
-
try:
|
|
89
|
-
shape = val.shape
|
|
90
|
-
if len(shape) > 2:
|
|
91
|
-
printe(f'2+dimensional arrays not supported for {dev,par}')
|
|
92
|
-
return None
|
|
93
|
-
except:
|
|
94
|
-
# val does not have attribute shape
|
|
95
|
-
pass
|
|
96
|
-
try:
|
|
97
|
-
ts = rd['timestamp']# EPICS and LITE
|
|
98
|
-
except: # ADO
|
|
99
|
-
ts = rd['timestampSeconds'] + rd['timestampNanoSeconds']*1.e-9
|
|
100
|
-
|
|
101
|
-
#printv(f"get_pv {adopar}: {rd['value']} {vslice}")
|
|
102
|
-
if vslice is not None:
|
|
103
|
-
val = val[vslice[0]:vslice[1]]
|
|
104
|
-
return val, ts
|
|
105
|
-
|
|
106
|
-
def change_plotOption(curveName,color=None,width=None,symbolSize=None,scolor=None):
|
|
107
|
-
printv('change_plotOption color,width,size,color: '+str((color,width,symbolSize,scolor)))
|
|
108
|
-
dataset = MapOfDatasets.dtsDict[curveName]
|
|
109
|
-
if color != None:
|
|
110
|
-
prop = 'color'
|
|
111
|
-
dataset.pen.setColor(color)
|
|
112
|
-
if width != None:
|
|
113
|
-
prop = 'width'
|
|
114
|
-
dataset.width = width
|
|
115
|
-
dataset.pen.setWidth(width)
|
|
116
|
-
elif symbolSize!=None:
|
|
117
|
-
dataset.symbolSize = symbolSize
|
|
118
|
-
elif scolor!=None:
|
|
119
|
-
dataset.symbolBrush = scolor
|
|
120
|
-
else: return
|
|
121
|
-
try:
|
|
122
|
-
dataset.plotItem.setPen(
|
|
123
|
-
dataset.pen)
|
|
124
|
-
except: cprint('could not set '+prop+' for '+str(curveName))
|
|
125
|
-
|
|
126
|
-
def split_slice(parNameSlice):
|
|
127
|
-
"""Decode 'name[n1:n2]' to 'name',[n1:n2]"""
|
|
128
|
-
devParSlice = parNameSlice.split('[',1)
|
|
129
|
-
if len(devParSlice) < 2:
|
|
130
|
-
return devParSlice[0], None
|
|
131
|
-
sliceStr = devParSlice[1].replace(']','')
|
|
132
|
-
vrange = sliceStr.split(':',1)
|
|
133
|
-
r0 = int(vrange[0])
|
|
134
|
-
if len(vrange) == 1:
|
|
135
|
-
vslice = (r0, r0+1)
|
|
136
|
-
else:
|
|
137
|
-
vslice = (r0, int(vrange[1]))
|
|
138
|
-
return devParSlice[0], vslice
|
|
139
|
-
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
140
|
-
|
|
141
|
-
def new_dock(dataset):
|
|
142
|
-
docks = [x.split('.')[0] for x in MapOfDatasets.dtsDict]
|
|
143
|
-
i = 0
|
|
144
|
-
while '#'+str(i) in docks: i += 1
|
|
145
|
-
v = '#'+str(i)+' '+dataset
|
|
146
|
-
printv('adding plot: '+str(v))
|
|
147
|
-
|
|
148
|
-
def close_dock(dname):
|
|
149
|
-
"""remove datasets and curves and close the dock widget"""
|
|
150
|
-
print('closing dock '+dname)
|
|
151
|
-
for curveName in MapOfDatasets.dtsDict.keys():
|
|
152
|
-
printv('looking: '+curveName)
|
|
153
|
-
dock = curveName.split('.')[0]
|
|
154
|
-
if dock == dname:
|
|
155
|
-
printv('removing: '+curveName)
|
|
156
|
-
MapOfDatasets.remove(curveName)
|
|
157
|
-
printv('MapOfDatasets.dtsDict: '+str(MapOfDatasets.dtsDict))
|
|
158
|
-
PVPlot.mapOfDocks[dname].close()
|
|
159
|
-
del PVPlot.mapOfPlotWidgets[dname]
|
|
160
|
-
|
|
161
|
-
def update_data():
|
|
162
|
-
""" called on QtCore.qTimer() event to update plots."""
|
|
163
|
-
tstart = timer()
|
|
164
|
-
tt = round(time.time(),6)
|
|
165
|
-
if tt > PVPlot.lastPlotTime + PVPlot.minPlottingPeriod:
|
|
166
|
-
time2plot = True
|
|
167
|
-
PVPlot.lastPlotTime = tt + PVPlot.minPlottingPeriod
|
|
168
|
-
else:
|
|
169
|
-
time2plot = False
|
|
170
|
-
|
|
171
|
-
for dataset in MapOfDatasets.dtsDict.values():
|
|
172
|
-
dataset.update_plot(time2plot)
|
|
173
|
-
|
|
174
|
-
if PVPlot.perfmon:
|
|
175
|
-
v = timer()-tstart
|
|
176
|
-
print('update time:'+str(timer()-tstart))
|
|
177
|
-
|
|
178
|
-
def set_legend(dockName:str, state:bool):
|
|
179
|
-
if state: # legend enabled
|
|
180
|
-
printv('add legend for '+str(dockName))
|
|
181
|
-
widget = PVPlot.mapOfPlotWidgets[dockName]
|
|
182
|
-
listOfItems = widget.getPlotItem().listDataItems()
|
|
183
|
-
l = pg.LegendItem((100,60), offset=(70,30)) # args are (size, offset)
|
|
184
|
-
l.setParentItem(widget.graphicsItem())
|
|
185
|
-
PVPlot.legend[dockName] = l
|
|
186
|
-
for item in listOfItems:
|
|
187
|
-
iname = item.name()
|
|
188
|
-
txt = MapOfDatasets.dtsDict[iname].adoPars[0][0]
|
|
189
|
-
# show only parameter name
|
|
190
|
-
ltxt = txt.rsplit(':',1)[-1]
|
|
191
|
-
if '[' in txt:
|
|
192
|
-
ltxt = ':'.join(txt.rsplit(':',2)[-2:])
|
|
193
|
-
printv('set_legend: '+iname+' par: '+ltxt)
|
|
194
|
-
l.addItem(item, ltxt)
|
|
195
|
-
else: # legend disabled
|
|
196
|
-
printv('remove legend from '+dockName)
|
|
197
|
-
try:
|
|
198
|
-
PVPlot.legend[dockName].scene().removeItem(PVPlot.legend[dockName])
|
|
199
|
-
del PVPlot.legend[dockName]
|
|
200
|
-
except Exception as e:
|
|
201
|
-
printe('failed to remove legend '+dockName+':'+str(e))
|
|
202
|
-
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
203
|
-
#```````````````````````````DateAxis class: time scale for bottom plot scale``
|
|
204
|
-
class DateAxis(pg.AxisItem):
|
|
205
|
-
def tickStrings(self, values, scale, spacing):
|
|
206
|
-
strns = []
|
|
207
|
-
if len(values) == 0:
|
|
208
|
-
return ''
|
|
209
|
-
rng = max(values)-min(values)
|
|
210
|
-
#if rng < 120:
|
|
211
|
-
# return pg.AxisItem.tickStrings(self, values, scale, spacing)
|
|
212
|
-
if rng < 3600*24:
|
|
213
|
-
string = '%H:%M:%S'
|
|
214
|
-
elif rng >= 3600*24 and rng < 3600*24*30:
|
|
215
|
-
string = '%d'
|
|
216
|
-
elif rng >= 3600*24*30 and rng < 3600*24*30*24:
|
|
217
|
-
string = '%b'
|
|
218
|
-
elif rng >=3600*24*30*24:
|
|
219
|
-
string = '%Y'
|
|
220
|
-
for x in values:
|
|
221
|
-
try:
|
|
222
|
-
strns.append(time.strftime(string, time.localtime(x)))
|
|
223
|
-
except ValueError: ## Windows can't handle dates before 1970
|
|
224
|
-
strns.append('')
|
|
225
|
-
return strns
|
|
226
|
-
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
227
|
-
#````````````````````````````Datasets`````````````````````````````````````````
|
|
228
|
-
class Dataset():
|
|
229
|
-
""" dataset storage, keeps everything what is necessary to plot the curve.
|
|
230
|
-
"""
|
|
231
|
-
def __init__(self,name,paramAndCount):
|
|
232
|
-
self.name = name
|
|
233
|
-
self.adoPars = paramAndCount # list of max 2 of (adoPar,count)
|
|
234
|
-
self.plotItem = None # plotting object PlotDataItem
|
|
235
|
-
self.pen = None # current pen
|
|
236
|
-
self.width = 1 # pen width
|
|
237
|
-
self.lastTimePlotted = 0.
|
|
238
|
-
self.lastTimeUpdated = 0.
|
|
239
|
-
self.timestampReported = 0 # time of the last title update
|
|
240
|
-
self.plotWidget = None
|
|
241
|
-
self.viewBox = None
|
|
242
|
-
# members for stripchart plot
|
|
243
|
-
self.viewXSize = 9E9# Wed Mar 14 2255 16:00:00
|
|
244
|
-
self.viewXRange = [0., 9E9]
|
|
245
|
-
self.scrolling = False
|
|
246
|
-
|
|
247
|
-
# plotting options, described in
|
|
248
|
-
# http://www.pyqtgraph.org/documentation/graphicsItems/plotdataitem.html#pyqtgraph.PlotDataItem
|
|
249
|
-
self.connect = None
|
|
250
|
-
self.shadowPen = None
|
|
251
|
-
self.fillLevel = None
|
|
252
|
-
self.fillBrush = None
|
|
253
|
-
self.stepMode = None
|
|
254
|
-
self.symbol = None
|
|
255
|
-
self.symbolPen = None
|
|
256
|
-
self.symbolBrush = None
|
|
257
|
-
self.symbolSize = None
|
|
258
|
-
self.pxMode = None
|
|
259
|
-
|
|
260
|
-
# ``````````````````` Add plotItem ``````````````````````````````````````
|
|
261
|
-
dock = name.split('.')[0]
|
|
262
|
-
printv('plotItem for: '+str([s for s in self.adoPars])+', name:'+str(dock))
|
|
263
|
-
initialWidth = 16
|
|
264
|
-
self.data = [np.empty(initialWidth),np.empty(initialWidth)]# [X,U] data storage
|
|
265
|
-
self.dataPtr = 0
|
|
266
|
-
count = self.adoPars[0][1] #
|
|
267
|
-
printv(f'adoPars,count: {self.adoPars,count}')
|
|
268
|
-
|
|
269
|
-
# create plotItem with proper pen
|
|
270
|
-
lineNumber = 0
|
|
271
|
-
try: lineNumber = int(name.split('.')[1])
|
|
272
|
-
except: pass
|
|
273
|
-
isCorrelationPlot = len(self.adoPars) >= 2
|
|
274
|
-
self.pen = pg.mkPen(lineNumber)
|
|
275
|
-
if self.adoPars[0][0] == '':
|
|
276
|
-
printv('no dataset - no plotItem')
|
|
277
|
-
else:
|
|
278
|
-
self.plotItem = pg.PlotDataItem(name=name, pen=self.pen)
|
|
279
|
-
|
|
280
|
-
# assign the plotwidget
|
|
281
|
-
if dock in PVPlot.mapOfPlotWidgets:
|
|
282
|
-
# dock already exist, use the existing plotwidget
|
|
283
|
-
self.plotWidget = PVPlot.mapOfPlotWidgets[dock]
|
|
284
|
-
else:
|
|
285
|
-
# new dock need to be created
|
|
286
|
-
# create vewBox with plotwidget
|
|
287
|
-
self.viewBox = CustomViewBox(dock, self)
|
|
288
|
-
self.viewBox.setMouseMode(self.viewBox.RectMode)
|
|
289
|
-
self.viewBox.sigRangeChangedManually.connect(self.xrangeChanged)
|
|
290
|
-
printv('Creating new dock:'+dock)
|
|
291
|
-
title = None
|
|
292
|
-
if count == 1 and not isCorrelationPlot:
|
|
293
|
-
self.plotWidget = pg.PlotWidget(title=title, viewBox=self.viewBox,
|
|
294
|
-
axisItems={'bottom':DateAxis(orientation='bottom')})
|
|
295
|
-
if dock != '#0':
|
|
296
|
-
self.plotWidget.setXLink(PVPlot.mapOfPlotWidgets['#0'])
|
|
297
|
-
else:
|
|
298
|
-
self.plotWidget = pg.PlotWidget(title=title, viewBox=self.viewBox)
|
|
299
|
-
#self.plotWidget.showGrid(True,True)
|
|
300
|
-
PVPlot.mapOfPlotWidgets[dock] = self.plotWidget
|
|
301
|
-
PVPlot.mapOfDocks[dock].addWidget(self.plotWidget)
|
|
302
|
-
if isCorrelationPlot:
|
|
303
|
-
self.plotWidget.setLabel('bottom',self.adoPars[1][0])
|
|
304
|
-
elif count == 1:
|
|
305
|
-
self.plotWidget.setLabel('bottom','time', units='date', unitPrefix='')
|
|
306
|
-
else:
|
|
307
|
-
self.plotWidget.setLabel('bottom',PVPlot.scaleUnits[X][Units])
|
|
308
|
-
|
|
309
|
-
# set X and Y ranges
|
|
310
|
-
rangeMap = {X: (PVPlot.pargs.xrange, self.plotWidget.setXRange),
|
|
311
|
-
Y: (PVPlot.pargs.yrange, self.plotWidget.setYRange)}
|
|
312
|
-
for axis,v in rangeMap.items():
|
|
313
|
-
r,func = v
|
|
314
|
-
if r is None:
|
|
315
|
-
continue
|
|
316
|
-
r = [float(i) for i in v[0].split(':')]
|
|
317
|
-
func(*r)
|
|
318
|
-
|
|
319
|
-
if self.plotItem:
|
|
320
|
-
self.plotWidget.addItem(self.plotItem)
|
|
321
|
-
self.lastTimePlotted = 0.
|
|
322
|
-
|
|
323
|
-
def __str__(self):
|
|
324
|
-
return f'Dataset {self.name}, x: {self.data[X].shape}'
|
|
325
|
-
|
|
326
|
-
def xrangeChanged(self):
|
|
327
|
-
viewRange = self.viewBox.viewRange()
|
|
328
|
-
self.viewXRange = viewRange[X]
|
|
329
|
-
viewlimit = self.viewXRange[1]
|
|
330
|
-
self.viewXSize = viewlimit - self.viewXRange[0]
|
|
331
|
-
rstack = self.viewBox.rangestack
|
|
332
|
-
rstack.append(viewRange)
|
|
333
|
-
if len(rstack) > 10:
|
|
334
|
-
rstack.pop(0)
|
|
335
|
-
self.scrolling = (self.viewBox is not None)\
|
|
336
|
-
and viewlimit > self.data[X][self.dataPtr-1]
|
|
337
|
-
#print(f'scrolling: {self.scrolling}')
|
|
338
|
-
|
|
339
|
-
def shift_viewXRange(self):
|
|
340
|
-
if self.viewBox.state['autoRange'][X]:
|
|
341
|
-
return
|
|
342
|
-
dx = self.viewXSize*PVPlot.padding
|
|
343
|
-
self.viewXRange[0] += dx
|
|
344
|
-
self.viewXRange[1] += dx
|
|
345
|
-
#print(f'>shift_viewXRange: {self.viewXRange[0], self.viewXRange[1]}')
|
|
346
|
-
self.viewBox.setXRange(self.viewXRange[0], self.viewXRange[1])
|
|
347
|
-
|
|
348
|
-
def plot(self, ts):
|
|
349
|
-
# Plot the dataset
|
|
350
|
-
if self.lastTimePlotted == ts:
|
|
351
|
-
return
|
|
352
|
-
self.lastTimePlotted = ts
|
|
353
|
-
#print(f'>plot: {self.name, {self.dataPtr}, round(ts,3)}')
|
|
354
|
-
x = self.data[X][:self.dataPtr]
|
|
355
|
-
y = self.data[Y][:self.dataPtr]
|
|
356
|
-
pen = self.pen if self.width else None
|
|
357
|
-
#printvv(f'x:{x}\ny:{y}')
|
|
358
|
-
self.plotItem.setData(x=x, y=y,
|
|
359
|
-
pen = pen,
|
|
360
|
-
#TODO:connect = self.connect,
|
|
361
|
-
#TODO:shadowPen = self.shadowPen,
|
|
362
|
-
#TODO:fillLevel = self.fillLevel,
|
|
363
|
-
#TODO:fillBrush = self.fillBrush,
|
|
364
|
-
#TODO:stepMode = self.stepMode,
|
|
365
|
-
symbol = self.symbol,
|
|
366
|
-
#TODO:symbolPen = self.symbolPen,
|
|
367
|
-
symbolPen = None,
|
|
368
|
-
symbolBrush = self.symbolBrush,
|
|
369
|
-
#TODO:symbolBrush = self.pen.color(),
|
|
370
|
-
symbolSize = self.symbolSize,
|
|
371
|
-
#TODO:pxMode = self.pxMode,
|
|
372
|
-
)
|
|
373
|
-
|
|
374
|
-
def update_plot(self, time2plot):
|
|
375
|
-
curvePars = self.adoPars
|
|
376
|
-
yd,ts = None,None
|
|
377
|
-
try:
|
|
378
|
-
#Limitation: only one (first) curve will be plotted
|
|
379
|
-
yd, ts = get_pv(curvePars[0][0])
|
|
380
|
-
except Exception as e:
|
|
381
|
-
#printv('got '+str((yd,ts))+', from:'+str(curvePars[0][0])+', except:'+str(e))
|
|
382
|
-
printw(f'Exception getting {curvePars[0][0]}: {e}')
|
|
383
|
-
return
|
|
384
|
-
if ts:
|
|
385
|
-
if ts == self.lastTimeUpdated:
|
|
386
|
-
#print(f'curve {self.name} did not change {round(ts,3)}')
|
|
387
|
-
if time2plot:
|
|
388
|
-
self.plot(ts)
|
|
389
|
-
return
|
|
390
|
-
self.lastTimeUpdated = ts
|
|
391
|
-
printv(f'update_plot: {curvePars}')# data:{yd}')
|
|
392
|
-
#print(f'update {self.name, round(ts,3), round(self.lastTimePlotted,3)}')
|
|
393
|
-
try:
|
|
394
|
-
l = len(yd)
|
|
395
|
-
if l == 1: yd = yd[0]
|
|
396
|
-
except:
|
|
397
|
-
l = 1
|
|
398
|
-
|
|
399
|
-
# Evaluate X and Y arrays
|
|
400
|
-
if l > 1:
|
|
401
|
-
# the plot is array plot
|
|
402
|
-
self.data[Y] = np.array(yd)
|
|
403
|
-
if len(curvePars) > 1:
|
|
404
|
-
# use last item as horizontal axis
|
|
405
|
-
self.data[X],*_ = get_pv(curvePars[-1][0])
|
|
406
|
-
else:
|
|
407
|
-
# scaled sample number
|
|
408
|
-
self.data[X] = np.arange(len(yd))*PVPlot.scaleUnits[X][Scale]
|
|
409
|
-
self.dataPtr = len(yd)
|
|
410
|
-
self.plot(ts)
|
|
411
|
-
return
|
|
412
|
-
else:
|
|
413
|
-
# the plot is scrolling or correlation plot
|
|
414
|
-
ptr = self.dataPtr
|
|
415
|
-
if ptr >= PVPlot.maxPoints:
|
|
416
|
-
# do not extent the data buffer, roll it over insted
|
|
417
|
-
self.data[X] = np.roll(self.data[X],-1)
|
|
418
|
-
self.data[Y] = np.roll(self.data[Y],-1)
|
|
419
|
-
ptr -= 1
|
|
420
|
-
self.data[Y][ptr] = yd
|
|
421
|
-
if len(curvePars) > 1:
|
|
422
|
-
printv(f'correlation plot: {curvePars[1][0]}')
|
|
423
|
-
try:
|
|
424
|
-
v,*_ = get_pv(curvePars[1][0])
|
|
425
|
-
try: v = v[0]
|
|
426
|
-
except: pass
|
|
427
|
-
self.data[X][ptr] = v
|
|
428
|
-
except Exception as e:
|
|
429
|
-
printe('no data from '+str(curvePars[1][0]))
|
|
430
|
-
else:
|
|
431
|
-
# scrolling plot with time scale
|
|
432
|
-
#print(f'ts: {round(ts,3), round(self.viewXRange[1],3)}')
|
|
433
|
-
if self.scrolling and ts > self.viewXRange[1]:
|
|
434
|
-
self.shift_viewXRange()
|
|
435
|
-
self.data[X][ptr] = ts
|
|
436
|
-
ptr += 1
|
|
437
|
-
self.dataPtr = ptr
|
|
438
|
-
#print(f'ptr: {ptr,self.data[Y].shape[0]}')
|
|
439
|
-
if (ptr <= PVPlot.maxPoints/2) & (ptr >= self.data[Y].shape[0]):
|
|
440
|
-
tmp = self.data
|
|
441
|
-
self.data = [np.empty(self.data[Y].shape[0] * 2),
|
|
442
|
-
np.empty(self.data[Y].shape[0] * 2)]
|
|
443
|
-
self.data[Y][:tmp[Y].shape[0]] = tmp[Y]
|
|
444
|
-
self.data[X][:tmp[X].shape[0]] = tmp[X]
|
|
445
|
-
#printi(f'adjust {self.name} from {tmp[X].shape} to {self.data[X].shape}')
|
|
446
|
-
|
|
447
|
-
if time2plot:
|
|
448
|
-
self.plot(ts)
|
|
449
|
-
|
|
450
|
-
class MapOfDatasets():
|
|
451
|
-
"""Global dictionary of Datasets, provides safe methods to add and remove
|
|
452
|
-
the datasets"""
|
|
453
|
-
dtsDict = {}
|
|
454
|
-
|
|
455
|
-
def add(name, adoPars):
|
|
456
|
-
"""add new datasets, the adoPars is the space delimited string of
|
|
457
|
-
source ado:parameters."""
|
|
458
|
-
printv(f'>MapOfDatasets.add({adoPars})')
|
|
459
|
-
if name in MapOfDatasets.dtsDict:
|
|
460
|
-
printv('Need to remove '+name)
|
|
461
|
-
MapOfDatasets.remove(name)
|
|
462
|
-
for i, token in enumerate(adoPars.split()):
|
|
463
|
-
dname = f'{name}.{i}'
|
|
464
|
-
pnameAndCount = [];
|
|
465
|
-
alist = token.split(',')
|
|
466
|
-
#alist = alist[:2] # we cannot handle more than 2 curves in correlation plot
|
|
467
|
-
if len(alist) == 0:
|
|
468
|
-
#MapOfDatasets.dtsDict[dname] = Dataset(dname,[('',0)])
|
|
469
|
-
#print(f'added dataset {str(MapOfDatasets.dtsDict[dname])}')
|
|
470
|
-
print(f'Logic error: MapOfDatasets({adoPars})')
|
|
471
|
-
sys.exit(1)
|
|
472
|
-
else:
|
|
473
|
-
alist.reverse()
|
|
474
|
-
for adoPar in alist:
|
|
475
|
-
ap = PVPlot.pargs.prefix+adoPar
|
|
476
|
-
try:
|
|
477
|
-
printv(f'check if {ap}, is alive')
|
|
478
|
-
valts = get_pv(ap) # check if parameter is alive
|
|
479
|
-
if valts is None:
|
|
480
|
-
printw('Could not add {ap}')
|
|
481
|
-
return 2
|
|
482
|
-
except Exception as e:
|
|
483
|
-
printw(f'Exception in getting parameter {ap}')
|
|
484
|
-
return 1
|
|
485
|
-
val,ts = valts
|
|
486
|
-
newName = ap
|
|
487
|
-
try: count = len(val)
|
|
488
|
-
except: count = 1
|
|
489
|
-
pnameAndCount.append((newName,count))
|
|
490
|
-
printv('adding '+str(pnameAndCount)+' to datasets['+dname+']')
|
|
491
|
-
MapOfDatasets.dtsDict[dname] = Dataset(dname,pnameAndCount)
|
|
492
|
-
printv(f'MapOfDatasets: {[(k,v.adoPars) for k,v in MapOfDatasets.dtsDict.items()]}')
|
|
493
|
-
return 0
|
|
494
|
-
|
|
495
|
-
def remove(name):
|
|
496
|
-
printv('MapOfDatasets.remove '+name)
|
|
497
|
-
dataset = MapOfDatasets.dtsDict[name]
|
|
498
|
-
dataset.plotWidget.removeItem(dataset.plotItem)
|
|
499
|
-
del MapOfDatasets.dtsDict[dataset.name]
|
|
500
|
-
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
501
|
-
#`````````````````````````````````````````````````````````````````````````````
|
|
502
|
-
class CustomViewBox(pg.ViewBox):
|
|
503
|
-
""" defines actions, activated on the right mouse click in the dock
|
|
504
|
-
"""
|
|
505
|
-
def __init__(self, name, dataset):
|
|
506
|
-
#self.dockName = kwds['name'] # cannot use name due to an issue in demo
|
|
507
|
-
#del kwds['name'] # the name in ViewBox.init fails in demo
|
|
508
|
-
self.dockName = name
|
|
509
|
-
self.dataset = dataset# master dataset, it defines horizontal axis
|
|
510
|
-
#print('CustomViewBox: '+str(self.dockName))
|
|
511
|
-
|
|
512
|
-
# call the init method of the parent class
|
|
513
|
-
super(CustomViewBox, self).__init__()
|
|
514
|
-
self.setDefaultPadding(0.)# standard is 0.02
|
|
515
|
-
|
|
516
|
-
# IMPORTANT: menu creation is deferred because it is expensive
|
|
517
|
-
# and often the user will never see the menu anyway.
|
|
518
|
-
self.menu = None
|
|
519
|
-
self.cursors = set()
|
|
520
|
-
self.rangestack = [] #stack of view ranges
|
|
521
|
-
|
|
522
|
-
#v32#def mouseClickEvent(self, ev) removed, due to blank exports
|
|
523
|
-
|
|
524
|
-
def raiseContextMenu(self, ev):
|
|
525
|
-
# Let the scene add on to the end of our context menu
|
|
526
|
-
menuIn = self.getContextMenus()
|
|
527
|
-
menu = self.scene().addParentContextMenus(self, menuIn, ev)
|
|
528
|
-
menu.popup(ev.screenPos().toPoint())
|
|
529
|
-
return True
|
|
530
|
-
|
|
531
|
-
def getContextMenus(self, event=None):
|
|
532
|
-
""" This method will be called when this item's children want to raise
|
|
533
|
-
a context menu that includes their parents' menus.
|
|
534
|
-
"""
|
|
535
|
-
if self.menu:
|
|
536
|
-
printv('menu exist')
|
|
537
|
-
return self.menu
|
|
538
|
-
printv('getContextMenus for '+str(self.dockName))
|
|
539
|
-
self.menu = ViewBoxMenu(self)
|
|
540
|
-
self.menu.setTitle(str(self.dockName)+ " options..")
|
|
541
|
-
|
|
542
|
-
# unzoom last
|
|
543
|
-
unzoom = self.menu.addAction("&UnZoom")
|
|
544
|
-
unzoom.triggered.connect(lambda: self.unzoom())
|
|
545
|
-
|
|
546
|
-
# Datasets options dialog
|
|
547
|
-
setDatasets = self.menu.addAction('Datasets &Options')
|
|
548
|
-
setDatasets.triggered.connect(self.changed_datasetOptions)
|
|
549
|
-
|
|
550
|
-
_statistics = self.menu.addAction('Show Statistics')
|
|
551
|
-
_statistics.triggered.connect(self.show_statistics)
|
|
552
|
-
|
|
553
|
-
cursorMenu = self.menu.addMenu('Add &Cursor')
|
|
554
|
-
for cursor in ['Vertical','Horizontal']:
|
|
555
|
-
action = cursorMenu.addAction(cursor)
|
|
556
|
-
action.triggered.connect(partial(self.cursorAction,cursor))
|
|
557
|
-
|
|
558
|
-
labelX = QW.QWidgetAction(self.menu)
|
|
559
|
-
self.labelXGui = QW.QLineEdit('LabelX')
|
|
560
|
-
self.labelXGui.returnPressed.connect(
|
|
561
|
-
lambda: self.set_label('bottom',self.labelXGui))
|
|
562
|
-
labelX.setDefaultWidget(self.labelXGui)
|
|
563
|
-
self.menu.addAction(labelX)
|
|
564
|
-
labelY = QW.QWidgetAction(self.menu)
|
|
565
|
-
self.labelYGui = QW.QLineEdit('LabelY')
|
|
566
|
-
self.labelYGui.returnPressed.connect(
|
|
567
|
-
lambda: self.set_label('left',self.labelYGui))
|
|
568
|
-
labelY.setDefaultWidget(self.labelYGui)
|
|
569
|
-
self.menu.addAction(labelY)
|
|
570
|
-
|
|
571
|
-
backgroundAction = QW.QWidgetAction(self.menu)
|
|
572
|
-
backgroundGui = QW.QCheckBox('&Black background')
|
|
573
|
-
backgroundGui.stateChanged.connect(
|
|
574
|
-
lambda x: self.setBackgroundColor(\
|
|
575
|
-
'k' if x == QtCore.Qt.Checked else 'w'))
|
|
576
|
-
backgroundAction.setDefaultWidget(backgroundGui)
|
|
577
|
-
self.menu.addAction(backgroundAction)
|
|
578
|
-
|
|
579
|
-
legenAction = QW.QWidgetAction(self.menu)
|
|
580
|
-
legendGui = QW.QCheckBox('&Legend')
|
|
581
|
-
legendGui.setChecked(True)
|
|
582
|
-
legendGui.stateChanged.connect(lambda x: self.set_legend(x))
|
|
583
|
-
legenAction.setDefaultWidget(legendGui)
|
|
584
|
-
self.menu.addAction(legenAction)
|
|
585
|
-
|
|
586
|
-
runAction = QW.QWidgetAction(self.menu)
|
|
587
|
-
runWidget = QW.QCheckBox('&Stop')
|
|
588
|
-
runWidget.setChecked(False)
|
|
589
|
-
runWidget.stateChanged.connect(lambda x: self.set_stop(x))
|
|
590
|
-
runAction.setDefaultWidget(runWidget)
|
|
591
|
-
self.menu.addAction(runAction)
|
|
592
|
-
|
|
593
|
-
sleepTimeMenu = self.menu.addMenu('Sleep&Time')
|
|
594
|
-
sleepTimeAction = QW.QWidgetAction(sleepTimeMenu)
|
|
595
|
-
sleepTimeWidget = QW.QDoubleSpinBox()
|
|
596
|
-
sleepTimeWidget.setValue(PVPlot.pargs.sleepTime)
|
|
597
|
-
sleepTimeWidget.setRange(0.001,100)
|
|
598
|
-
sleepTimeWidget.setSuffix(' s')
|
|
599
|
-
sleepTimeWidget.setSingleStep(.1)
|
|
600
|
-
sleepTimeWidget.valueChanged.connect(lambda x: self.set_sleepTime(x))
|
|
601
|
-
sleepTimeAction.setDefaultWidget(sleepTimeWidget)
|
|
602
|
-
sleepTimeMenu.addAction(sleepTimeAction)
|
|
603
|
-
return self.menu
|
|
604
|
-
|
|
605
|
-
def cursorAction(self, direction):
|
|
606
|
-
angle = {'Vertical':90, 'Horizontal':0}[direction]
|
|
607
|
-
pwidget = PVPlot.mapOfPlotWidgets[self.dockName]
|
|
608
|
-
vid = {'Vertical':0, 'Horizontal':1}[direction]
|
|
609
|
-
vr = pwidget.getPlotItem().viewRange()
|
|
610
|
-
#print(f'vid: {vid,vr[vid]}')
|
|
611
|
-
pos = (vr[vid][1] + vr[vid][0])/2.
|
|
612
|
-
pen = pg.mkPen(color='b', width=1, style=QtCore.Qt.DotLine)
|
|
613
|
-
cursor = pg.InfiniteLine(pos=pos, pen=pen, movable=True, angle=angle
|
|
614
|
-
, label=str(round(pos,3)))
|
|
615
|
-
cursor.sigPositionChangeFinished.connect(\
|
|
616
|
-
(partial(self.cursorPositionChanged,cursor)))
|
|
617
|
-
self.cursors.add(cursor)
|
|
618
|
-
pwidget.addItem(cursor)
|
|
619
|
-
|
|
620
|
-
def cursorPositionChanged(self, cursor):
|
|
621
|
-
pos = cursor.value()
|
|
622
|
-
horizontal = cursor.angle == 0.
|
|
623
|
-
pwidget = PVPlot.mapOfPlotWidgets[self.dockName]
|
|
624
|
-
viewRange = pwidget.getPlotItem().viewRange()[horizontal]
|
|
625
|
-
if pos > viewRange[1]:
|
|
626
|
-
pwidget.removeItem(cursor)
|
|
627
|
-
self.cursors.remove(cursor)
|
|
628
|
-
else:
|
|
629
|
-
cursor.label.setText(str(round(pos,3)))
|
|
630
|
-
|
|
631
|
-
def changed_datasetOptions(self):
|
|
632
|
-
"""Dialog Plotting Options"""
|
|
633
|
-
dlg = QW.QDialog()
|
|
634
|
-
dlg.setWindowTitle("Dataset plotting config")
|
|
635
|
-
dlg.setWindowModality(QtCore.Qt.ApplicationModal)
|
|
636
|
-
dlgSize = 500,200
|
|
637
|
-
dlg.setMinimumSize(*dlgSize)
|
|
638
|
-
rowCount,columnCount = 0,6
|
|
639
|
-
tbl = QW.QTableWidget(rowCount, columnCount, dlg)
|
|
640
|
-
tbl.setHorizontalHeaderLabels(['Dataset','Color','Width','Symbol','Size','Color'])
|
|
641
|
-
for column,width in ((1,30),(3,50),(5,30)): # change column widths
|
|
642
|
-
tbl.setColumnWidth(column, width)
|
|
643
|
-
tbl.setShowGrid(False)
|
|
644
|
-
tbl.setSizeAdjustPolicy(
|
|
645
|
-
QW.QAbstractScrollArea.AdjustToContents)
|
|
646
|
-
tbl.resize(*dlgSize)
|
|
647
|
-
|
|
648
|
-
listOfItems = PVPlot.mapOfPlotWidgets[self.dockName].getPlotItem().listDataItems()
|
|
649
|
-
for row,dataitem in enumerate(listOfItems):
|
|
650
|
-
tbl.insertRow(row)
|
|
651
|
-
curveName = dataitem.name()
|
|
652
|
-
printv(f'curveName:{curveName}')
|
|
653
|
-
dataset = MapOfDatasets.dtsDict[curveName]
|
|
654
|
-
adoparName = dataset.adoPars[0][0]
|
|
655
|
-
|
|
656
|
-
printv(f'dataset:{adoparName}')
|
|
657
|
-
item = QW.QTableWidgetItem(adoparName.rsplit(':',1)[1])
|
|
658
|
-
#DNW#item.setTextAlignment(QtCore.Qt.AlignRight)
|
|
659
|
-
tbl.setItem(row, 0, item)
|
|
660
|
-
|
|
661
|
-
# color button for line
|
|
662
|
-
colorButton = pg.ColorButton(color=dataset.pen.color())
|
|
663
|
-
colorButton.setObjectName(curveName)
|
|
664
|
-
colorButton.sigColorChanging.connect(lambda x:
|
|
665
|
-
change_plotOption(str(self.sender().objectName()),color=x.color()))
|
|
666
|
-
tbl.setCellWidget(row, 1, colorButton)
|
|
667
|
-
|
|
668
|
-
# slider for changing the line width
|
|
669
|
-
widthSlider = QW.QSlider()
|
|
670
|
-
widthSlider.setObjectName(curveName)
|
|
671
|
-
widthSlider.setOrientation(QtCore.Qt.Horizontal)
|
|
672
|
-
widthSlider.setMaximum(10)
|
|
673
|
-
widthSlider.setValue(1)
|
|
674
|
-
widthSlider.valueChanged.connect(lambda x:
|
|
675
|
-
change_plotOption(str(self.sender().objectName()),width=x))
|
|
676
|
-
tbl.setCellWidget(row, 2, widthSlider)
|
|
677
|
-
|
|
678
|
-
# symbol, selected from a comboBox
|
|
679
|
-
self.symbol = QW.QComboBox() # TODO: why self?
|
|
680
|
-
for symbol in ' ostd+x': self.symbol.addItem(symbol)
|
|
681
|
-
self.symbol.setObjectName(curveName)
|
|
682
|
-
self.symbol.currentIndexChanged.connect(self.set_symbol)
|
|
683
|
-
tbl.setCellWidget(row, 3, self.symbol)
|
|
684
|
-
|
|
685
|
-
# slider for changing the line width
|
|
686
|
-
symbolSizeSlider = QW.QSlider()
|
|
687
|
-
symbolSizeSlider.setObjectName(curveName)
|
|
688
|
-
symbolSizeSlider.setOrientation(QtCore.Qt.Horizontal)
|
|
689
|
-
symbolSizeSlider.setMaximum(10)
|
|
690
|
-
symbolSizeSlider.setValue(1)
|
|
691
|
-
symbolSizeSlider.valueChanged.connect(lambda x:
|
|
692
|
-
change_plotOption(str(self.sender().objectName()),symbolSize=x))
|
|
693
|
-
tbl.setCellWidget(row, 4, symbolSizeSlider)
|
|
694
|
-
|
|
695
|
-
# color button for symbol
|
|
696
|
-
symbolColorButton = pg.ColorButton(color=dataset.pen.color())
|
|
697
|
-
symbolColorButton.setObjectName(curveName)
|
|
698
|
-
symbolColorButton.sigColorChanging.connect(lambda x:
|
|
699
|
-
change_plotOption(str(self.sender().objectName()),scolor=x.color()))
|
|
700
|
-
tbl.setCellWidget(row, 5,symbolColorButton)
|
|
701
|
-
dlg.exec_()
|
|
702
|
-
|
|
703
|
-
def set_symbol(self, x):
|
|
704
|
-
""" Change symbol of the scatter plot. The size and color are taken
|
|
705
|
-
from the curve setting"""
|
|
706
|
-
dtsetName = str(self.sender().objectName())
|
|
707
|
-
symbol = str(self.sender().itemText(x))
|
|
708
|
-
printv('set_symbol for '+dtsetName+' to '+symbol)
|
|
709
|
-
dataset = MapOfDatasets.dtsDict[dtsetName]
|
|
710
|
-
if symbol != ' ':
|
|
711
|
-
dataset.symbol = symbol
|
|
712
|
-
if not dataset.symbolSize:
|
|
713
|
-
dataset.symbolSize = 4 # default size
|
|
714
|
-
if not dataset.symbolBrush:
|
|
715
|
-
dataset.symbolBrush = dataset.pen.color() # symbol color = line color
|
|
716
|
-
else:
|
|
717
|
-
# no symbols - remove the scatter plot
|
|
718
|
-
dataset.symbol = None
|
|
719
|
-
pass
|
|
720
|
-
|
|
721
|
-
def set_label(self,side,labelGui):
|
|
722
|
-
dock,label = self.dockName,str(labelGui.text())
|
|
723
|
-
printv('changed_label '+side+': '+str((dock,label)))
|
|
724
|
-
PVPlot.mapOfPlotWidgets[dock].setLabel(side,label, units='')
|
|
725
|
-
# it might be useful to return the prompt back:
|
|
726
|
-
#labelGui.setText('LabelX' if side=='bottom' else 'LabelY')
|
|
727
|
-
|
|
728
|
-
def set_legend(self, state):
|
|
729
|
-
state = (state==QtCore.Qt.Checked)
|
|
730
|
-
print(f'set_legend {state}')
|
|
731
|
-
set_legend(self.dockName, state)
|
|
732
|
-
|
|
733
|
-
def set_stop(self, state):
|
|
734
|
-
if state == QtCore.Qt.Checked:
|
|
735
|
-
PVPlot.qTimer.stop()
|
|
736
|
-
else:
|
|
737
|
-
PVPlot.qTimer.start(int(PVPlot.pargs.sleepTime*1000))
|
|
738
|
-
|
|
739
|
-
def set_sleepTime(self, itemData):
|
|
740
|
-
#print('setting SleepTime to: '+str(itemData))
|
|
741
|
-
PVPlot.pargs.sleepTime = itemData
|
|
742
|
-
PVPlot.qTimer.stop()
|
|
743
|
-
PVPlot.qTimer.start(int(PVPlot.pargs.sleepTime*1000))
|
|
744
|
-
|
|
745
|
-
def unzoom(self):
|
|
746
|
-
self.rangestack.pop()
|
|
747
|
-
try: viewRange = self.rangestack[-1]
|
|
748
|
-
except:
|
|
749
|
-
return
|
|
750
|
-
self.setRange(xRange=viewRange[X], yRange=viewRange[Y], padding=None,
|
|
751
|
-
update=True, disableAutoRange=True)
|
|
752
|
-
|
|
753
|
-
def show_statistics(self):
|
|
754
|
-
label = QW.QLabel('Statistics')
|
|
755
|
-
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
756
|
-
|
|
757
|
-
def callback(args):
|
|
758
|
-
#print(f'cb: {args}')
|
|
759
|
-
for hostDevPar, pardict in args.items():
|
|
760
|
-
try:
|
|
761
|
-
axis,units = PVPlot.subscribedParMap[(hostDevPar)]
|
|
762
|
-
except Exception as e:
|
|
763
|
-
printw(f'callback exception for {hostDevPar}: {e}')
|
|
764
|
-
#print(f'map: {PVPlot.subscribedParMap}')
|
|
765
|
-
continue
|
|
766
|
-
scale = pardict['value'][0]
|
|
767
|
-
printv(f'axis={axis}, units={units}, scale={scale}')
|
|
768
|
-
PVPlot.scaleUnits[axis][Scale] = scale
|
|
769
|
-
|
|
770
|
-
def add_curves(dock:str, adopars:str):
|
|
771
|
-
# if dock name is new then create new dock, otherwise extend the
|
|
772
|
-
# existing one with new curve
|
|
773
|
-
|
|
774
|
-
curves = [x for x in MapOfDatasets.dtsDict]
|
|
775
|
-
docks = [x.split('.')[0] for x in curves]
|
|
776
|
-
printv(f'>addcurves curves,docks:{curves,docks}')
|
|
777
|
-
if dock in docks:
|
|
778
|
-
printv('extending dock '+str(dock))
|
|
779
|
-
for i in range(MaxCurvesPerPlot):
|
|
780
|
-
newSlot = dock+'.'+str(i+1)
|
|
781
|
-
if newSlot not in curves: break
|
|
782
|
-
dock = newSlot
|
|
783
|
-
else:
|
|
784
|
-
printv('adding new dock '+dock)
|
|
785
|
-
PVPlot.mapOfDocks[dock] = dockarea.Dock(dock, size=(500,200), hideTitle=True)
|
|
786
|
-
if dock == '#0':
|
|
787
|
-
PVPlot.dockArea.addDock(PVPlot.mapOfDocks[dock], 'right', closable=True)
|
|
788
|
-
else:
|
|
789
|
-
PVPlot.dockArea.addDock(PVPlot.mapOfDocks[dock],
|
|
790
|
-
'top', PVPlot.mapOfDocks['#0'], closable=True) #TODO:closable does not work
|
|
791
|
-
if MapOfDatasets.add(dock, adopars):
|
|
792
|
-
printe('in add_curves: '+str((dock, adopars)))
|
|
793
|
-
|
|
794
|
-
class PVPlot():
|
|
795
|
-
pargs = None
|
|
796
|
-
mapOfDocks = {}
|
|
797
|
-
mapOfPlotWidgets = {}
|
|
798
|
-
padding = 0.1
|
|
799
|
-
scaleUnits = [[1,'Sample'],[1,'Count']]
|
|
800
|
-
subscribedParMap = {}
|
|
801
|
-
perfmon = False # option for performance monitoring
|
|
802
|
-
legend = {}# unfortunately we have to keep track of legends
|
|
803
|
-
access = {'E:':(EPICSAccess,2), 'L:':(LITEAccess,2)}
|
|
804
|
-
qWin = None
|
|
805
|
-
qTimer = QtCore.QTimer()
|
|
806
|
-
dockArea = None
|
|
807
|
-
minPlottingPeriod = 1/10.# the data will not be plotted faster than that limit.
|
|
808
|
-
lastPlotTime = 0.
|
|
809
|
-
maxPoints = 1048576# Max number of data points to store.
|
|
810
|
-
|
|
811
|
-
def start():
|
|
812
|
-
pargs = PVPlot.pargs
|
|
813
|
-
print(f'pargs: {PVPlot.pargs}')
|
|
814
|
-
|
|
815
|
-
try: os.environ["QT_SCALE_FACTOR"] = str(pargs.zoomin)
|
|
816
|
-
except: pass
|
|
817
|
-
qApp = QApplication([])
|
|
818
|
-
PVPlot.qWin = QMainWindow()
|
|
819
|
-
PVPlot.dockArea = dockarea.DockArea()
|
|
820
|
-
PVPlot.qWin.setCentralWidget(PVPlot.dockArea)
|
|
821
|
-
PVPlot.qWin.resize(1000,500)
|
|
822
|
-
## Switch to using white background and black foreground
|
|
823
|
-
pg.setConfigOption('background', 'w')
|
|
824
|
-
pg.setConfigOption('foreground', 'k')
|
|
825
|
-
|
|
826
|
-
PVPlot.qWin.setWindowTitle(f'pvplot {pargs.parms}')
|
|
827
|
-
|
|
828
|
-
# plots for other docks
|
|
829
|
-
if pargs.dock:
|
|
830
|
-
for par in pargs.dock:
|
|
831
|
-
dock = par[0][0]
|
|
832
|
-
adopar = par[0][1:].lstrip()
|
|
833
|
-
dock = '#'+dock
|
|
834
|
-
add_curves(dock, adopar)
|
|
835
|
-
else:
|
|
836
|
-
# plots for the main dock
|
|
837
|
-
add_curves('#0', pargs.parms)
|
|
838
|
-
if len(MapOfDatasets.dtsDict) == 0:
|
|
839
|
-
printe(f'No datasets created')
|
|
840
|
-
sys.exit(1)
|
|
841
|
-
|
|
842
|
-
for dock in PVPlot.mapOfDocks:
|
|
843
|
-
set_legend(str(dock), True)
|
|
844
|
-
|
|
845
|
-
# Subscriptions. Only LITE system is supported.
|
|
846
|
-
if pargs.xscale is not None:
|
|
847
|
-
print(f'infra: {pargs.prefix}')
|
|
848
|
-
infrastructure = pargs.prefix[:2]
|
|
849
|
-
if infrastructure != 'L:':
|
|
850
|
-
printe(f'The --xscale option is supported only for LITE infrastucture')
|
|
851
|
-
sys.exit(1)
|
|
852
|
-
hostDev = pargs.prefix[2:]
|
|
853
|
-
if hostDev[-1] == ':':
|
|
854
|
-
hostDev = hostDev[:-1]
|
|
855
|
-
par = pargs.xscale
|
|
856
|
-
printv(f'subscribing: {hostDev,par}')
|
|
857
|
-
info = LITEAccess.info((hostDev,par))
|
|
858
|
-
printv(f'info of {hostDev,par}: {info}')
|
|
859
|
-
units = info[par].get('units','')
|
|
860
|
-
PVPlot.scaleUnits[X][1] = units
|
|
861
|
-
LITEAccess.subscribe(callback, (hostDev,par))
|
|
862
|
-
PVPlot.subscribedParMap[(hostDev,par)] = [X, units]
|
|
863
|
-
|
|
864
|
-
update_data()
|
|
865
|
-
|
|
866
|
-
## Start a timer to rapidly update the plot in pw
|
|
867
|
-
PVPlot.qTimer.timeout.connect(update_data)
|
|
868
|
-
PVPlot.qTimer.start(int(pargs.sleepTime*1000))
|
|
869
|
-
|
|
870
|
-
PVPlot.qWin.show()
|
|
871
|
-
PVPlot.qWin.resize(640,480)
|
|
872
|
-
|
|
873
|
-
# start GUI
|
|
874
|
-
qApp.instance().exec_()
|
|
875
|
-
print('Application exit')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|