Skip to content

Commit 80689fb

Browse files
committed
More changes...starting new version R3.0
1 parent 5dc9503 commit 80689fb

File tree

3 files changed

+156
-112
lines changed

3 files changed

+156
-112
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ class DataLogger(Experiment):
209209
"Sets up pvlist and filepaths to write data and log files"
210210
def __init__(self,pvlist):
211211
Experiment.__init__(self)
212+
if pvlist:
213+
for pv in pvlist:
214+
if not pv.status:
215+
pvlist.remove(pv)
216+
printMsg('PV %s invalid: removed' % (pv.pvname))
212217
self.pvlist=pvlist
213218
PV(pvPrefix + ':DATA:FILEPATH').put(self.filepath) # Write filepath to PV for display
214219
self.dataFilename=self.filepath + now + '.dat'

nlcta/pvScan-nlcta-singlePv-abort.py

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,75 @@
22
# For aborting scans.
33
# mdunning 1/7/16
44

5-
from epics import PV
5+
from epics import caget,caput,PV,Motor
66
from time import sleep
7-
import os,sys,signal
7+
import datetime,math,os,sys,signal
8+
from threading import Thread
89

9-
# PV prefix for pvScan IOC; should be passed as an argument to this script.
10-
pvPrefix=sys.argv[1]
11-
# Set an environment variable for so pvScan module can use it
12-
os.environ['PVSCAN_PVPREFIX']=pvPrefix
10+
args='PV_PREFIX'
11+
12+
def show_usage():
13+
"Prints usage"
14+
print 'Usage: %s %s' %(sys.argv[0], args)
1315

14-
# Import pvScan module
15-
sys.path.append('/afs/slac/g/testfac/extras/scripts/pvScan/R2.0/modules/')
16-
import pvScan2
16+
if len(sys.argv) != 2:
17+
show_usage()
18+
sys.exit(1)
19+
20+
# PV prefix for pvScan IOC; should be passed as an argument
21+
pvPrefix=sys.argv[1]
1722

1823
# Get PID PV
19-
pid=pvScan2.pidPV.get()
24+
pidPV=PV(pvPrefix + ':PID')
25+
pid=pidPV.get()
2026

21-
#--- Shutters -----------------------------------------
22-
# Create Shutter objects.
23-
# First argument is shutter PV.
24-
# Second arg (optional) is an RBV PV, for example an ADC channel.
25-
shutter1=pvScan2.DummyShutter('ESB:GP01:VAL01') # (UED Drive laser)
26-
shutter2=pvScan2.DummyShutter('ESB:GP01:VAL02') # (UED pump laser)
27-
shutter3=pvScan2.DummyShutter('ESB:GP01:VAL03') # (UED HeNe laser)
28-
#
29-
# Create ShutterGroup object to use common functions on all shutters.
30-
# Argument is a list of shutter objects.
31-
shutterGroup1=pvScan2.ShutterGroup([shutter1,shutter2,shutter3])
27+
# PV for status message
28+
msgpv=PV(pvPrefix + ':MSG')
29+
30+
# Motors to be stopped
31+
motor1='MOTR:AS01:MC01:CH8:MOTOR'
32+
motor1Stop=PV(motor1 + '.STOP')
33+
34+
# Shutter disable PVs
35+
shutter1TTLDisablePv=PV('ASTA:LSC01:TTL:IN:DISABLE')
36+
shutter2TTLDisablePv=PV('ASTA:LSC02:TTL:IN:DISABLE')
37+
shutter3TTLDisablePv=PV('ASTA:LSC03:TTL:IN:DISABLE')
38+
shutterTTLDisablePVList=[shutter1TTLDisablePv,shutter2TTLDisablePv,shutter3TTLDisablePv]
39+
# Shutter close PVs
40+
shutter1ClosePv=PV('ASTA:LSC01:OC:CLOSE')
41+
shutter2ClosePv=PV('ASTA:LSC02:OC:CLOSE')
42+
shutter3ClosePv=PV('ASTA:LSC03:OC:CLOSE')
43+
shutterClosePVList=[shutter1ClosePv,shutter2ClosePv,shutter3ClosePv]
3244

3345
##################################################################################################################
46+
def shutterFunction(shutterPVList,pvVal=1,wait=True):
47+
"Opens, Closes, or Enables/Disables TTL Input for shutters, depending on which PVs are passed in. Takes a list of PVs as an argument."
48+
for shutterPV in shutterPVList:
49+
shutterPV.put(pvVal,wait)
50+
3451
def abortRoutine():
3552
"This is the abort routine"
36-
pvScan2.printMsg('Aborting')
37-
# Kill scan routine process
38-
pvScan2.printMsg('Killing process %d...' % (pid))
53+
msgpv.put('Aborting')
54+
# kill scan routine process
3955
os.kill(pid, signal.SIGKILL)
4056
# Disable shutters
41-
#pvScan2.printMsg('Disabling shutters')
42-
#pvScan2.shutterFunction(shutterGroup1.ttlInDisable,0)
57+
#shutterFunction(shutterTTLDisablePVList,1)
4358
#sleep(0.5)
4459
# Close shutters
45-
pvScan2.printMsg('Closing shutters')
46-
pvScan2.shutterFunction(shutterGroup1.close,0)
47-
pvScan2.printMsg('Aborted')
60+
#shutterFunction(shutterClosePVList,1)
61+
# Stop motors
62+
#motor1Stop.put(1)
63+
print 'Aborted'
64+
msgpv.put('Aborted')
4865

66+
67+
4968

5069
if __name__ == "__main__":
5170
"Do abort routine"
52-
args='PV_PREFIX'
53-
def show_usage():
54-
"Prints usage"
55-
print 'Usage: %s %s' %(sys.argv[0], args)
56-
if len(sys.argv) != 2:
57-
show_usage()
58-
sys.exit(1)
5971
abortRoutine()
6072

73+
6174
##################################################################################################################
6275

6376

nlcta/pvScan-nlcta-singlePv.py

Lines changed: 102 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,144 @@
11
#!/usr/bin/env python
2-
# For doing DAQ scans. Logs PV data to a file while doing scan of an arbitrary PV. Uses a supporting IOC (pvScan).
2+
# For doing DAQ scans. Logs PV data to a file while doing beam scan. Uses a supporting IOC (pvScan).
33
# mdunning 1/7/16
44

5-
from epics import PV
5+
from epics import caget,caput,PV
66
from time import sleep
77
import datetime,os,sys
88
from threading import Thread
99

10+
args='PV_PREFIX'
1011

11-
# PV prefix for pvScan IOC; should be passed as an argument to this script.
12+
def show_usage():
13+
"Prints usage"
14+
print 'Usage: %s %s' %(sys.argv[0], args)
15+
16+
if len(sys.argv) != 2:
17+
show_usage()
18+
sys.exit(1)
19+
20+
# PV prefix for pvScan IOC; should be passed as an argument
1221
pvPrefix=sys.argv[1]
1322
# Set an environment variable for so pvScan module can use it
1423
os.environ['PVSCAN_PVPREFIX']=pvPrefix
1524

1625
# Import pvScan module
1726
sys.path.append('/afs/slac/g/testfac/extras/scripts/pvScan/R2.0/modules/')
18-
import pvScan2
19-
20-
#--- Experiment ---------------------------------------
21-
# Create Experiment object. Sets default filepath and gets experiment name from PV.
22-
# First argument (optional) is an experiment name.
23-
# Second arg (optional) is a filepath.
24-
exp1=pvScan2.Experiment()
25-
sleep(2)
26-
27-
#--- Scan PVs ------------------------------------------
28-
# Create ScanPv objects, one for each PV you are scanning.
29-
# First argument is the scan PV, leave blank to get from pvScan IOC.
30-
# Second arg is an index which should be unique.
31-
scanPv1=pvScan2.ScanPv('',1) # (UED Solenoid)
32-
33-
#--- Shutters -----------------------------------------
34-
# Create Shutter objects.
35-
# First argument is shutter PV.
36-
# Second arg (optional) is an RBV PV, for example an ADC channel.
37-
shutter1=pvScan2.DummyShutter('ESB:GP01:VAL01','ESB:GP01:VAL01') # (UED Drive laser)
38-
shutter2=pvScan2.DummyShutter('ESB:GP01:VAL02','ESB:GP01:VAL02') # (UED pump laser)
39-
shutter3=pvScan2.DummyShutter('ESB:GP01:VAL03','ESB:GP01:VAL03') # (UED HeNe laser)
27+
import pvScan
28+
29+
# Scan PVs
30+
scanPv1=pvScan.ScanPv('ESB:GP01:VAL04',1) # ScanPv class instance (UED Solenoid)
4031
#
41-
# Create ShutterGroup object to use common functions on all shutters.
42-
# Argument is a list of shutter objects.
43-
shutterGroup1=pvScan2.ShutterGroup([shutter1,shutter2,shutter3])
32+
# Shutters. Make a list for each group, to use shutterFunction()
33+
shutter1=pvScan.DummyShutter('ESB:GP01:VAL01') # Shutter 1 class instance (UED Drive laser)
34+
shutter2=pvScan.DummyShutter('ESB:GP01:VAL02') # Shutter 2 class instance (UED pump laser)
35+
shutter3=pvScan.DummyShutter('ESB:GP01:VAL03') # Shutter 3 class instance (UED HeNe laser)
36+
shutterList=[shutter1,shutter2,shutter3]
37+
shutterTTLEnablePVList=[]
38+
shutterTTLDisablePVList=[]
39+
shutterOpenPVList=[]
40+
shutterClosePVList=[]
41+
shutterSoftPVList=[]
42+
shutterFastPVList=[]
43+
for i in xrange(len(shutterList)):
44+
shutterTTLEnablePVList.append(shutterList[i].ttlInEnable)
45+
shutterTTLDisablePVList.append(shutterList[i].ttlInDisable)
46+
shutterOpenPVList.append(shutterList[i].open)
47+
shutterClosePVList.append(shutterList[i].close)
48+
shutterSoftPVList.append(shutterList[i].soft)
49+
shutterFastPVList.append(shutterList[i].fast)
50+
# Shutter RBVs
51+
shutter1RBVPv=PV('ESB:GP01:VAL01')
52+
shutter2RBVPv=PV('ESB:GP01:VAL02')
53+
shutter3RBVPv=PV('ESB:GP01:VAL03')
54+
shutterRBVPVList=[shutter1RBVPv,shutter2RBVPv,shutter3RBVPv]
4455
#
45-
#--- Other PVs -----------------
46-
# Define as PV objects. Example PV('MY:RANDOM:PV')
56+
# ADC values
4757
#lsrpwrPv=PV('ESB:A01:ADC1:AI:CH3')
4858
#toroid0355Pv=PV('ESB:A01:ADC1:AI:CH4')
4959
#toroid2150Pv=PV('ESB:A01:ADC1:AI:CH5')
5060
#structureChargePv=PV('ESB:A01:ADC1:CALC:CH1:CONV')
5161

52-
#---- Data logging --------------------------
53-
# List of PV() objects to be monitored during scan.
54-
dataLogPvList=shutterGroup1.rbv + [scanPv1]
55-
#
56-
# Create DataLogger object.
57-
# Argument is the list of PVs to monitor.
58-
dataLog1=pvScan2.DataLogger(dataLogPvList)
62+
pause1=1.0 # sec
63+
64+
#---- For data logging --------------------------
65+
pvList=[shutter1RBVPv,shutter2RBVPv,shutter3RBVPv,scanPv1] # list of PVs to be monitored during scan
66+
expName=PV(pvPrefix + ':IOC.DESC').get()
67+
if ' ' in expName: expName=expName.replace(' ','_')
68+
now=datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
69+
filepath=os.environ['NFSHOME'] + '/pvScan/' + expName + '/' + now + '/'
70+
if not os.path.exists(filepath): os.makedirs(filepath)
71+
filepathPv=PV(pvPrefix + ':DATA:FILEPATH')
72+
filepathPv.put(filepath) # Write filepath to PV for display
73+
dataFilename=filepath + now + '.dat'
74+
dataFilenamePv=PV(pvPrefix + ':DATA:FILENAME')
75+
dataFilenamePv.put(dataFilename)
76+
logFilename=filepath + now + '.log'
77+
logFilenamePv=PV(pvPrefix + ':LOG:FILENAME')
78+
logFilenamePv.put(logFilename)
79+
dataEnable=PV(pvPrefix + ':DATA:ENABLE').get() # Enable/Disable data logging
80+
dataInt=PV(pvPrefix + ':DATA:INT').get() # Interval between PV data log points
81+
nPtsMax=100000 # limits number of data points
5982
#-------------------------------------------------
6083

61-
# --- Image grabbing --------------------------
62-
# Override saved camera settings here. Leave empty list to use the default; otherwise add PVs with single quotes.
63-
grabImagesSettingsPvList=['13PS10:cam1:Manufacturer_RBV']
64-
#
65-
# Create ImageGrabber object.
66-
# First arg is the camera PV prefix.
67-
# Second arg (optional) is a list of camera setting PVs to be dumped to a file.
68-
# Third arg (optional) is the image grabbing plugin.
69-
grab1=pvScan2.ImageGrabber('13PS10')
84+
# --- For grabbing images --------------------------
85+
grabImagesFlag=PV(pvPrefix + ':GRABIMAGES:ENABLE').get()
86+
grabImagesN=PV(pvPrefix + ':GRABIMAGES:N').get()
87+
grabImagesFilepath=filepath + 'images/'
88+
grabImagesPlugin='TIFF1'
89+
grabImagesSource='13PS10'
90+
# Leave grabImagesSettingsPvList=[] to use the default
91+
grabImagesSettingsPvList=[]
7092
#-------------------------------------------------------------
7193

72-
### Define scan routine #####################################################
94+
####################################################################################################
95+
96+
def singlePvScan(scanPv,grabImagesFlag=0,grabImagesN=0,grabImagesSource='',grabImagesFilepath='~/pvScan/images/',grabImagesPlugin='TIFF1',grabImagesFilenameExtras='',grabImagesWriteSettingsFlag=1,grabImagesSettingsPvList=[]):
97+
"Scans pv from start to stop in n steps, optionally grabbing images at each step."
98+
initialPos=scanPv.get()
99+
pvScan.printMsg('Starting scan')
100+
inc=(scanPv.stop-scanPv.start)/(scanPv.nsteps-1)
101+
for i in range(scanPv.nsteps):
102+
newPos=scanPv.start + i*inc
103+
pvScan.printMsg('Setting %s to %f' % (scanPv.pvname,newPos))
104+
scanPv.put(newPos)
105+
pvScan.printSleep(scanPv.settletime,'Settling')
106+
if grabImagesFlag:
107+
grabImagesFilenameExtras='_ScanPV-' + '{0:08.4f}'.format(scanPv.get())
108+
pvScan.grabImages(grabImagesN,grabImagesSource,grabImagesFilepath,grabImagesPlugin,grabImagesFilenameExtras,grabImagesWriteSettingsFlag,grabImagesSettingsPvList)
109+
# Move back to initial positions
110+
pvScan.printMsg('Setting %s back to initial position: %f' %(scanPv.pvname,initialPos))
111+
scanPv.put(initialPos)
73112

74113
def scanRoutine():
75114
"This is the scan routine"
76-
pvScan2.printMsg('Starting')
77-
sleep(0.5) # Collect some initial data first
115+
pvScan.printMsg('Starting')
116+
sleep(pause1)
78117
# Open shutters
79-
pvScan2.printMsg('Opening shutters')
80-
pvScan2.shutterFunction(shutterGroup1.open,1)
118+
#pvScan.printMsg('Opening shutters')
119+
#pvScan.shutterFunction(shutterOpenPVList,1)
81120
# Scan delay stage and grab images...
82-
pvScan2.ScanPv.pv1DScan(scanPv1,grab1)
121+
singlePvScan(scanPv1,grabImagesFlag,grabImagesN,grabImagesSource,grabImagesFilepath,grabImagesPlugin,grabImagesFilenameExtras='',grabImagesWriteSettingsFlag=1,grabImagesSettingsPvList=grabImagesSettingsPvList)
83122
# Close shutters
84-
pvScan2.printMsg('Closing shutters')
85-
pvScan2.shutterFunction(shutterGroup1.close,0)
86-
pvScan2.printMsg('Done')
87-
88-
### Main program ##########################################################3
123+
#pvScan.printMsg('Closing shutters')
124+
#pvScan.shutterFunction(shutterClosePVList,0)
125+
pvScan.printMsg('Done')
89126

90127
if __name__ == "__main__":
91128
"Do scan routine; log PV data to file as a separate thread if enabled"
129+
pvScan.Tee(logFilename, 'w')
130+
pvScan.dataFlag=1 # Start logging data when thread starts
131+
if dataEnable==1:
132+
datalogthread=Thread(target=pvScan.datalog,args=(dataInt,dataFilename,pvList,nPtsMax))
133+
datalogthread.start()
92134
try:
93-
args='PV_PREFIX'
94-
def show_usage():
95-
"Prints usage"
96-
print 'Usage: %s %s' %(sys.argv[0], args)
97-
98-
if len(sys.argv) != 2:
99-
show_usage()
100-
sys.exit(1)
101-
102-
pid=os.getpid()
103-
pvScan2.pidPV.put(pid)
104-
pvScan2.Tee(dataLog1.logFilename, 'w')
105-
pvScan2.dataFlag=1 # Start logging data when thread starts
106-
if dataLog1.dataEnable==1:
107-
datalogthread=Thread(target=pvScan2.DataLogger.datalog,args=(dataLog1,))
108-
datalogthread.start()
109135
scanRoutine()
110-
sleep(2) # Log data for a little longer
136+
sleep(pause1) # Log data for a little longer
111137
finally:
112-
pvScan2.dataFlag=0 # Stop logging data
138+
pvScan.dataFlag=0 # Stop logging data
113139

114140

115-
### End ##########################################################################
141+
##################################################################################################################
116142

117143

118144
exit

0 commit comments

Comments
 (0)