pvplot 1.2.3__tar.gz → 1.3.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pvplot
3
- Version: 1.2.3
3
+ Version: 1.3.2
4
4
  Summary: Plotting tool for EPICS PVs, ADO and LITE parameters
5
5
  Project-URL: Homepage, https://github.com/ASukhanov/pvplot
6
6
  Project-URL: Bug Tracker, https://github.com/ASukhanov/pvplot/issues
@@ -0,0 +1,5 @@
1
+ txt="""Shortcuts:
2
+ ^p: Print/Update statistics
3
+ ^s: Stop/Start
4
+ ^u: Unzoom
5
+ """
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env python3
2
2
  """Plotting package for EPICS PVs, ADO and LITE parameters.
3
3
  """
4
- __version__ = 'v1.2.3 2024-07-29'# fix: config-less plotting
4
+ __version__ = 'v1.3.2 2024-08-20'# do not printv curve ... did not change, label color, better statistics
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
8
+ #TODO: Use teich text in statistics
8
9
 
9
10
  import sys, os, time, datetime
10
11
  timer = time.perf_counter
@@ -22,6 +23,18 @@ from importlib import import_module
22
23
  #````````````````````````````Constants````````````````````````````````````````
23
24
  X,Y = 0,1
24
25
  Scale,Units = 0,1
26
+ TxtColor = (0,128,128)# color of the plot texts
27
+ class color:
28
+ PURPLE = '\033[95m'
29
+ CYAN = '\033[96m'
30
+ DARKCYAN = '\033[36m'
31
+ BLUE = '\033[94m'
32
+ GREEN = '\033[92m'
33
+ YELLOW = '\033[93m'
34
+ RED = '\033[91m'
35
+ BOLD = '\033[1m'
36
+ UNDERLINE = '\033[4m'
37
+ END = '\033[0m'
25
38
  #````````````````````````````Helper methods```````````````````````````````````
26
39
  def printTime(): return time.strftime("%m%d:%H%M%S")
27
40
  def printi(msg): print((f'INFO_PVP@{printTime()}: '+msg))
@@ -141,7 +154,7 @@ def update_data():
141
154
  tt = round(time.time(),6)
142
155
  if tt > PVPlot.lastPlotTime + PVPlot.minPlottingPeriod:
143
156
  time2plot = True
144
- PVPlot.lastPlotTime = tt + PVPlot.minPlottingPeriod
157
+ PVPlot.lastPlotTime = tt
145
158
  else:
146
159
  time2plot = False
147
160
 
@@ -156,23 +169,12 @@ def update_data():
156
169
  v = timer()-tstart
157
170
  print('update time:'+str(timer()-tstart))
158
171
 
159
- def get_statistics():
160
- statistics = {}
161
- for dataset in MapOfDatasets.dtsDict.values():
162
- s = dataset.get_statistics()
163
- if len(s) != 0:
164
- statistics.update(s)
165
- txt = 'Parm,\tRange,\tMean,\t\tSTD\n'
166
- for key,v in statistics.items():
167
- txt += f'{key},\t{v["xrange"]},\t{v["mean"]},\t{v["std"]}\n'
168
- return txt
169
-
170
172
  def set_legend(dockNum:int, state:bool):
171
173
  if state: # legend enabled
172
174
  printv(f'add legends to dock{dockNum}')
173
175
  widget = PVPlot.mapOfPlotWidgets[dockNum]
174
176
  listOfItems = widget.getPlotItem().listDataItems()
175
- l = pg.LegendItem((100,60), offset=(70,30)) # args are (size, offset)
177
+ l = pg.LegendItem((100,60), offset=(70,30), labelTextColor=TxtColor) # args are (size, offset)
176
178
  l.setParentItem(widget.graphicsItem())
177
179
  PVPlot.legend[dockNum] = l
178
180
  for item in listOfItems:
@@ -245,6 +247,7 @@ class Dataset():
245
247
  self.pxMode = None
246
248
  self.timeAxis = False
247
249
  self.statistics = {}
250
+ self.enabled = True
248
251
 
249
252
  # ``````````````````` Add plotItem ``````````````````````````````````````
250
253
  #dockNum = name.split('.')[0]
@@ -282,9 +285,11 @@ class Dataset():
282
285
  PVPlot.mapOfDocks[dockNum].addWidget(self.plotWidget)
283
286
  printv(f'docks: {PVPlot.mapOfDocks.keys()}, widgets: {PVPlot.mapOfPlotWidgets.keys()}')
284
287
 
285
- c = PVPlot.config
286
- if c is None: xl,yl = 'LabelX','LabelY'
287
- else: xl,yl = c.XLABEL,c.YLABEL
288
+ xl,yl = 'LabelX','LabelY'
289
+ try:
290
+ c = PVPlot.config
291
+ xl,yl = c.XLABEL,c.YLABEL
292
+ except: pass
288
293
  #print(f'd:{self.dockNum}, X,Y: {xl,yl}')
289
294
  if self.dockNum == 0 and yl != 'LabelY':
290
295
  self.plotWidget.setLabel('left', yl)
@@ -320,6 +325,12 @@ class Dataset():
320
325
  self.plotWidget.addItem(self.plotItem)
321
326
  self.lastTimePlotted = 0.
322
327
 
328
+ def add_plot(self):
329
+ self.plotWidget.addItem(self.plotItem)
330
+
331
+ def remove_plot(self):
332
+ self.plotWidget.removeItem(self.plotItem)
333
+
323
334
  def __str__(self):
324
335
  return f'Dataset {self.name}, x: {self.data[X].shape}'
325
336
 
@@ -345,9 +356,10 @@ class Dataset():
345
356
  self.viewBox.setXRange(self.viewXRange[0], self.viewXRange[1])
346
357
 
347
358
  def plot(self, ts):
348
- # Plot the dataset
359
+ # Plot the dataset. It may be several updates between these calls.
349
360
  if self.lastTimePlotted == ts:
350
361
  return
362
+ printv(f'>plot: {self.name}')
351
363
  self.lastTimePlotted = ts
352
364
  #print(f'>plot: {self.name, {self.dataPtr}, round(ts,3)}')
353
365
  x = self.data[X][:self.dataPtr]
@@ -383,13 +395,11 @@ class Dataset():
383
395
  if ts:
384
396
  if ts == self.lastTimeUpdated:
385
397
  self.dataChanged = False
386
- #print(f'curve {self.name} did not change {round(ts,3)}')
387
- if time2plot:
388
- self.plot(ts)
398
+ #printv(f'curve {self.name} did not change {round(ts,3)}')
389
399
  return
400
+ printv(f'update_plot: {self.name,curvePars}')
390
401
  self.dataChanged = True
391
402
  self.lastTimeUpdated = ts
392
- #printv(f'update_plot: {curvePars}, data:{yd}')
393
403
  #print(f'update {self.name, round(ts,3), round(self.lastTimePlotted,3)}')
394
404
  try:
395
405
  l = len(yd)
@@ -475,8 +485,10 @@ class Dataset():
475
485
  r = {parname:{}}
476
486
  rp = r[parname]
477
487
  rp['xrange'] = (ileft,iright)
478
- rp['mean'] = np.mean(self.data[Y][ileft:iright]).astype('f4')
479
- rp['std'] = np.std(self.data[Y][ileft:iright]).astype('f4')
488
+ y = np.array(self.data[Y][ileft:iright])
489
+ rp['mean'] = y.mean().astype('f4')
490
+ rp['std'] = y.std().astype('f4')
491
+ rp['p2p'] = (y.max() - y.min()).astype('f4')
480
492
  return r
481
493
 
482
494
  def get_visibleData(self):
@@ -524,6 +536,7 @@ class MapOfDatasets():
524
536
  pnameAndCount.append((adoPar,count))
525
537
  printv('adding '+str(pnameAndCount)+' to datasets['+curveName+']')
526
538
  MapOfDatasets.dtsDict[curveName] = Dataset(dockNum, curveName, pnameAndCount)
539
+ PVPlot.mapOfCurves[dockNum].append(curveName)
527
540
  printv(f'MapOfDatasets: {[(k,v.adoPars) for k ,v in MapOfDatasets.dtsDict.items()]}')
528
541
  return 0
529
542
 
@@ -600,7 +613,7 @@ class CustomViewBox(pg.ViewBox):
600
613
  setDatasets = self.menu.addAction('Datasets &Options')
601
614
  setDatasets.triggered.connect(self.changed_datasetOptions)
602
615
 
603
- _statistics = self.menu.addAction('Show Statistics')
616
+ _statistics = self.menu.addAction('&Print Statistics')
604
617
  _statistics.triggered.connect(self.show_statistics)
605
618
 
606
619
  _yProjection = self.menu.addAction('Show yProjection')
@@ -675,7 +688,7 @@ class CustomViewBox(pg.ViewBox):
675
688
  pos = (vr[vid][1] + vr[vid][0])/2.
676
689
  pen = pg.mkPen(color='b', width=1, style=QtCore.Qt.DotLine)
677
690
  cursor = pg.InfiniteLine(pos=pos, pen=pen, movable=True, angle=angle
678
- , label=self.cursor_text(pos,vid), labelOpts={'color':(0,0,0)})#,'fill':(0,255,255)})
691
+ , label=self.cursor_text(pos,vid), labelOpts={'color':TxtColor})#,'fill':(0,255,255)})
679
692
  cursor.sigPositionChangeFinished.connect(\
680
693
  (partial(self.cursorPositionChanged,cursor)))
681
694
  self.cursors.add(cursor)
@@ -698,32 +711,41 @@ class CustomViewBox(pg.ViewBox):
698
711
  dlg = QW.QDialog()
699
712
  dlg.setWindowTitle(f"Dataset of dock{self.dockNum}")
700
713
  dlg.setWindowModality(QtCore.Qt.ApplicationModal)
701
- dlgSize = 500,200
702
- dlg.setMinimumSize(*dlgSize)
703
- rowCount,columnCount = 0,6
714
+ rowCount,columnCount = 0,8
704
715
  tbl = QW.QTableWidget(rowCount, columnCount, dlg)
705
716
  tbl.setHorizontalHeaderLabels(
706
- ['Name','PV','Color','Width','Symbol','Size'])
707
- widths = ( 50, 100, 30, 80, 40, 80)
717
+ ['','Name','PV','Color','Width','Sym','Size',''])
718
+ widths = (10, 50, 100, 20, 80, 35, 80,80)
708
719
  for column,width in enumerate(widths):
709
720
  tbl.setColumnWidth(column, width)
710
721
  tbl.setShowGrid(False)
711
722
  tbl.setSizeAdjustPolicy(
712
723
  QW.QAbstractScrollArea.AdjustToContents)
713
- tbl.resize(*dlgSize)
714
724
 
715
- listOfItems = PVPlot.mapOfPlotWidgets[self.dockNum].getPlotItem().listDataItems()
716
- for row,dataitem in enumerate(listOfItems):
725
+ for row,curveName in enumerate(PVPlot.mapOfCurves[self.dockNum]):
717
726
  tbl.insertRow(row)
718
- curveName = dataitem.name()
719
727
  printv(f'curveName:{curveName}')
720
- col = 0
721
728
  dataset = MapOfDatasets.dtsDict[curveName]
729
+ col = 0
730
+ cbox = QW.QCheckBox()
731
+ cbox.setChecked(dataset.enabled)
732
+ cbox.stateChanged.connect(self.enable_dataset)
733
+ cbox.setObjectName(curveName)
734
+ tbl.setCellWidget(row, col, cbox)
735
+
736
+ col+=1
722
737
  adoparName = dataset.adoPars[0][0]
723
- tbl.setItem(row, col, QW.QTableWidgetItem(curveName))
738
+ item = QW.QTableWidgetItem(curveName)
739
+ #item.setTextAlignment(QtCore.Qt.AlignRight)
740
+ tbl.setItem(row, col, item)
741
+
724
742
  col+=1
725
743
  printv(f'dataset:{adoparName}')
726
- tbl.setItem(row, col, QW.QTableWidgetItem(adoparName))
744
+ txt = adoparName[-24:]
745
+ txt = txt[:12]+'\n'+txt[12:]
746
+ item = QW.QTableWidgetItem(txt)
747
+ tbl.setItem(row, col, QW.QTableWidgetItem(item))
748
+
727
749
  col+=1
728
750
  # color button for line
729
751
  colorButton = pg.ColorButton(color=dataset.pen.color())
@@ -731,6 +753,7 @@ class CustomViewBox(pg.ViewBox):
731
753
  colorButton.sigColorChanging.connect(lambda x:
732
754
  change_plotOption(str(self.sender().objectName()),color=x.color()))
733
755
  tbl.setCellWidget(row, col, colorButton)
756
+
734
757
  col+=1
735
758
  # slider for changing the line width
736
759
  widthSlider = QW.QSlider()
@@ -741,6 +764,7 @@ class CustomViewBox(pg.ViewBox):
741
764
  widthSlider.valueChanged.connect(lambda x:
742
765
  change_plotOption(str(self.sender().objectName()),width=x))
743
766
  tbl.setCellWidget(row, col, widthSlider)
767
+
744
768
  col+=1
745
769
  # symbol, selected from a comboBox
746
770
  self.symbol = QW.QComboBox() # TODO: why self?
@@ -748,6 +772,7 @@ class CustomViewBox(pg.ViewBox):
748
772
  self.symbol.setObjectName(curveName)
749
773
  self.symbol.currentIndexChanged.connect(self.set_symbol)
750
774
  tbl.setCellWidget(row, col, self.symbol)
775
+
751
776
  col+=1
752
777
  # slider for changing the line width
753
778
  symbolSizeSlider = QW.QSlider()
@@ -758,13 +783,11 @@ class CustomViewBox(pg.ViewBox):
758
783
  symbolSizeSlider.valueChanged.connect(lambda x:
759
784
  change_plotOption(str(self.sender().objectName()),symbolSize=x))
760
785
  tbl.setCellWidget(row, col, symbolSizeSlider)
761
- col+=1
762
- # color button for symbol
763
- symbolColorButton = pg.ColorButton(color=dataset.pen.color())
764
- symbolColorButton.setObjectName(curveName)
765
- symbolColorButton.sigColorChanging.connect(lambda x:
766
- change_plotOption(str(self.sender().objectName()),scolor=x.color()))
767
- tbl.setCellWidget(row, col,symbolColorButton)
786
+
787
+ #dlg.resize(tbl.width(),tbl.height())
788
+ dialogWidth = tbl.horizontalHeader().length() + 24
789
+ dialogHeight= tbl.verticalHeader().length() + 24
790
+ dlg.setMinimumSize(dialogWidth, dialogHeight)
768
791
  dlg.exec_()
769
792
 
770
793
  def set_symbol(self, x):
@@ -821,12 +844,9 @@ class CustomViewBox(pg.ViewBox):
821
844
  update=True, disableAutoRange=True)
822
845
 
823
846
  def show_statistics(self):
824
- if PVPlot.statisticsWindow is None:
825
- PVPlot.statisticsWindow = PopupWindow()
826
- txt = get_statistics()
827
- PVPlot.statisticsWindow.label.setText(txt)
828
- PVPlot.statisticsWindow.show()
829
- PVPlot.statistics = {}
847
+ #print(f'print statistics for {self.dockNum}')
848
+ PVPlot.statDock = self.dockNum
849
+ PVPlot.actionStatistics()
830
850
 
831
851
  def show_yProjection(self):
832
852
  if PVPlot.yProjectionWindow is None:
@@ -838,6 +858,15 @@ class CustomViewBox(pg.ViewBox):
838
858
  PVPlot.yProjectionWindow.setWindowTitle(
839
859
  f'Vertical projection of {self.dataset.adoPars[0][0].rsplit(":",1)[1]}')
840
860
  self.dataset.show_yProjection()
861
+
862
+ def enable_dataset(self, state):
863
+ dtsetName = str(self.sender().objectName())
864
+ #print(f'enable_dataset {dtsetName, (state==QtCore.Qt.Checked)}')
865
+ dataset = MapOfDatasets.dtsDict[dtsetName]
866
+ enabled = (state==QtCore.Qt.Checked)
867
+ dataset.enabled = enabled
868
+ dataset.add_plot() if enabled else dataset.remove_plot()
869
+ #set_legend(self.dockNum, enabled)# deletes all legend items
841
870
  #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
842
871
 
843
872
  def callback(args):
@@ -872,6 +901,7 @@ def add_curves(dockNum:int, curveMap:str):
872
901
  else:
873
902
  PVPlot.dockArea.addDock(PVPlot.mapOfDocks[dockNum],
874
903
  'top', PVPlot.mapOfDocks[0], closable=True) #TODO:closable does not work
904
+ PVPlot.mapOfCurves[dockNum] = []
875
905
  if MapOfDatasets.add(dockNum, curveMap):
876
906
  printe(f'in add_curves: {dockNum, curveMap}')
877
907
 
@@ -909,8 +939,9 @@ def parse_input_parameters(pargs):
909
939
  class PVPlot():
910
940
  config = None
911
941
  pargs = None
912
- mapOfPlotWidgets = {}
913
- mapOfDocks = {}
942
+ mapOfPlotWidgets = {}# active plotItems
943
+ mapOfDocks = {}# dockAreas
944
+ mapOfCurves = {}
914
945
  padding = 0.1
915
946
  scaleUnits = [[1,'Sample'],[1,'Count']]
916
947
  subscribedParMap = {}
@@ -926,6 +957,7 @@ class PVPlot():
926
957
  yProjectionWindow = None
927
958
  yProjectionPlotItem = None
928
959
  stopped = False
960
+ statDock = 0
929
961
 
930
962
  def start():
931
963
  pargs = PVPlot.pargs
@@ -945,10 +977,12 @@ class PVPlot():
945
977
  # Shortcuts
946
978
  shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+H"), PVPlot.qWin)
947
979
  shortcut.activated.connect(PVPlot.actionHelp)
980
+ shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+P"), PVPlot.qWin)
981
+ shortcut.activated.connect(partial(PVPlot.actionStatistics))
948
982
  shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+S"), PVPlot.qWin)
949
- shortcut.activated.connect(partial(PVPlot.actionStop,True))
950
- shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+Q"), PVPlot.qWin)
951
- shortcut.activated.connect(partial(PVPlot.actionStop,False))
983
+ shortcut.activated.connect(partial(PVPlot.actionStop))
984
+ #shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+Q"), PVPlot.qWin)
985
+ #shortcut.activated.connect(partial(PVPlot.actionStop,False))
952
986
  shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+U"), PVPlot.qWin)
953
987
  shortcut.activated.connect(PVPlot.actionUnzoom)
954
988
  from . import helptxt
@@ -1028,10 +1062,14 @@ class PVPlot():
1028
1062
 
1029
1063
  def stop(state):
1030
1064
  PVPlot.stopped = state
1065
+ suffix = ' is stopped'
1031
1066
  if state == True:
1032
1067
  PVPlot.qTimer.stop()
1068
+ title = PVPlot.qWin.windowTitle()+suffix
1033
1069
  else:
1034
1070
  PVPlot.qTimer.start(int(PVPlot.pargs.sleepTime*1000))
1071
+ title = PVPlot.qWin.windowTitle().replace(suffix,'')
1072
+ PVPlot.qWin.setWindowTitle(title)
1035
1073
 
1036
1074
  #``````````Shorthcut handlers
1037
1075
  def actionHelp():
@@ -1039,8 +1077,9 @@ class PVPlot():
1039
1077
  PVPlot.helpWin.label.setText(PVPlot.helptxt)
1040
1078
  PVPlot.helpWin.show()
1041
1079
 
1042
- def actionStop(state:bool):
1043
- PVPlot.stop(state)
1080
+ def actionStop():
1081
+ PVPlot.stopped = not PVPlot.stopped
1082
+ PVPlot.stop(PVPlot.stopped)
1044
1083
 
1045
1084
  def actionUnzoom():
1046
1085
  md = PVPlot.mapOfDocks
@@ -1048,3 +1087,25 @@ class PVPlot():
1048
1087
  for dockNum in docks:
1049
1088
  vb = PVPlot.mapOfPlotWidgets[dockNum].getPlotItem().getViewBox()
1050
1089
  vb.unzoom()
1090
+
1091
+ def actionStatistics():
1092
+ #print(f'>actionStatistics {PVPlot.statDock}')
1093
+ def get_statistics():
1094
+ statistics = {}
1095
+ for dataset in MapOfDatasets.dtsDict.values():
1096
+ if dataset.dockNum != PVPlot.statDock:
1097
+ continue
1098
+ s = dataset.get_statistics()
1099
+ if len(s) != 0:
1100
+ statistics.update(s)
1101
+ txt = ('Parameter,\tRange \tMean \tSTD \tPeak2Peak\n'
1102
+ '----------\t------\t------\t------\t---------\n')
1103
+ for key,v in statistics.items():
1104
+ txt += f'{key}:\t{v["xrange"]}\t{v["mean"]:.6g}\t{v["std"]:.6g}\t{v["p2p"]:.6g}\n'
1105
+ return txt
1106
+ if PVPlot.statisticsWindow is None:
1107
+ PVPlot.statisticsWindow = PopupWindow()
1108
+ txt = get_statistics()
1109
+ PVPlot.statisticsWindow.label.setText(txt)
1110
+ PVPlot.statisticsWindow.show()
1111
+ PVPlot.statistics = {}
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pvplot"
7
- version = "1.2.3"
7
+ version = "1.3.2"
8
8
  authors = [
9
9
  { name="Andrei Sukhanov", email="cyxandr@gmail.com" },
10
10
  ]
@@ -1,6 +0,0 @@
1
- txt="""
2
- Shortcuts
3
- ^s: Stop
4
- ^q: Continue
5
- ^u: Unzoom
6
- """
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