Skip to content

Commit 83282b1

Browse files
author
Kay Kasemir (ky9)
committed
Update totorial/* for python3
1 parent 0eae737 commit 83282b1

13 files changed

+389
-608
lines changed

doc/getting_started.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,11 @@ the "Scan Data Table" and watch how samples are added.
211211
This internal data logger is again not meant to replace data aquisition,
212212
but meant to assist in tracknig the progress of scans and to debug them.
213213

214-
For more on the available scan commands, read the other sections
215-
of this document.
214+
At this point you may familiarize yourself with all the :ref:`scan_commands`,
215+
especially the many options of the :class:`.Set` command.
216+
The PyScanClient `tutorial` folder contains several examples
217+
to try.
218+
216219

217220
CS-Studio GUI combined with PyScanClient
218221
----------------------------------------
@@ -242,6 +245,18 @@ Default Device Settings
242245

243246
TODO
244247

248+
Table Scan
249+
----------
250+
251+
TODO
252+
253+
254+
Alignment Scan
255+
--------------
256+
257+
TODO
258+
Custom script commands
259+
245260
Production Setup
246261
----------------
247262

Lines changed: 69 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
'''
22
This is an example how to use PyScanClient library to perform a 2D scan using table scan, and take multiple samples
33
at each point.
4-
It needs an example EPICS database, simulation.db, which could be found at:
5-
https://github.com/ControlSystemStudio/cs-studio/blob/master/applications/plugins/org.csstudio.scan/examples/
6-
And it assumes the server running on localhost at port 4810.
7-
84
95
It does the following:
10-
- set pv 'motor_x' to 1, which means to open a shutter, and wait until finish.
116
- loop pv 'motor_x' from 1 to 5 with stepping size = 1 and wait until finish. at each step:
127
- loop pv 'motor_y' from 1 to 3 with stepping size = 1, and wait until finish. at each step:
138
- wait for 1 second
149
- log pv 'motor_x', 'motor_y' and 'neutrons'
15-
- set pv 'motor_x' to original place
16-
- set pv 'motor_y' to original place
17-
- get logged data back
18-
- create a table for the results
19-
- clear scan server
2010
21-
It does not demo:
22-
- read back and its tolerance to ensure
11+
It uses the table's pre and post options
12+
- set pv 'motor_x' to 1 to simulate openint a shutter, and wait until finish.
2313
24-
Created on Apr 17, 2015
25-
26-
@author: shen
14+
- set pv 'motor_x' to original place
15+
- set pv 'motor_y' to original place
16+
17+
@author: shen, Kay Kasemir
2718
'''
2819

2920
from scan.client.scanclient import ScanClient
@@ -33,7 +24,7 @@
3324
from scan.client.logdata import createTable
3425

3526
from scan.util.scan_settings import ScanSettings, setScanSettings
36-
# Note how we replace the original Set() and Wait() commands with those that utilize ScanSettings
27+
# Note how we replace the original Set() with one that utilizes ScanSettings
3728
from scan.util.scan_settings import SettingsBasedSet as Set
3829

3930
class LocalScanSettings(ScanSettings):
@@ -50,72 +41,66 @@ def __init__(self):
5041
# return device_name + ".RBV"
5142
# return device_name
5243

53-
if __name__ == '__main__':
54-
orig_motor_x = 0
55-
orig_motor_y = 0
56-
57-
# Custom settings configure the TableScan
58-
setScanSettings(LocalScanSettings())
59-
# Create table scan command
60-
# list all scan parameters
61-
table = TableScan(['motor_x', 'motor_y', 'loc://i(0)', "Wait For", "Value"],
62-
[ [ 1, 1, 1, 'Seconds', 1],
63-
[ '', '', 2, 'Seconds', 1],
64-
[ '', 2, 1, 'Seconds', 1],
65-
[ '', '', 2, 'Seconds', 1],
66-
[ '', 3, 1, 'Seconds', 1],
67-
[ '', '', 2, 'Seconds', 1],
68-
[ 2, 1, 1, 'Seconds', 1],
69-
[ '', '', 2, 'Seconds', 1],
70-
[ '', 2, 1, 'Seconds', 1],
71-
[ '', '', 2, 'Seconds', 1],
72-
[ '', 3, 1, 'Seconds', 1],
73-
[ '', '', 2, 'Seconds', 1],
74-
[ 3, 1, 1, 'Seconds', 1],
75-
[ '', '', 2, 'Seconds', 1],
76-
[ '', 2, 1, 'Seconds', 1],
77-
[ '', '', 2, 'Seconds', 1],
78-
[ '', 3, 1, 'Seconds', 1],
79-
[ '', '', 2, 'Seconds', 1],
80-
[ 4, 1, 1, 'Seconds', 1],
81-
[ '', '', 2, 'Seconds', 1],
82-
[ '', 2, 1, 'Seconds', 1],
83-
[ '', '', 2, 'Seconds', 1],
84-
[ '', 3, 1, 'Seconds', 1],
85-
[ '', '', 2, 'Seconds', 1],
86-
[ 5, 1, 1, 'Seconds', 1],
87-
[ '', '', 2, 'Seconds', 1],
88-
[ '', 2, 1, 'Seconds', 1],
89-
[ '', '', 2, 'Seconds', 1],
90-
[ '', 3, 1, 'Seconds', 1],
91-
[ '', '', 2, 'Seconds', 1],],
92-
pre=Set('motor_x', 1, completion=True),
93-
post=[Set('motor_x', orig_motor_x, completion=True),
94-
Set('motor_y', orig_motor_y, completion=True),],
95-
log_always=['neutrons', 'setpoint']
96-
)
97-
cmds = table.createScan()
44+
orig_motor_x = 0
45+
orig_motor_y = 0
46+
47+
# Custom settings configure the TableScan
48+
setScanSettings(LocalScanSettings())
49+
# Create table scan command
50+
# list all scan parameters
51+
table = TableScan(['motor_x', 'motor_y', 'loc://i(0)', "Wait For", "Value"],
52+
[ [ 1, 1, 1, 'Seconds', 1],
53+
[ '', '', 2, 'Seconds', 1],
54+
[ '', 2, 1, 'Seconds', 1],
55+
[ '', '', 2, 'Seconds', 1],
56+
[ '', 3, 1, 'Seconds', 1],
57+
[ '', '', 2, 'Seconds', 1],
58+
[ 2, 1, 1, 'Seconds', 1],
59+
[ '', '', 2, 'Seconds', 1],
60+
[ '', 2, 1, 'Seconds', 1],
61+
[ '', '', 2, 'Seconds', 1],
62+
[ '', 3, 1, 'Seconds', 1],
63+
[ '', '', 2, 'Seconds', 1],
64+
[ 3, 1, 1, 'Seconds', 1],
65+
[ '', '', 2, 'Seconds', 1],
66+
[ '', 2, 1, 'Seconds', 1],
67+
[ '', '', 2, 'Seconds', 1],
68+
[ '', 3, 1, 'Seconds', 1],
69+
[ '', '', 2, 'Seconds', 1],
70+
[ 4, 1, 1, 'Seconds', 1],
71+
[ '', '', 2, 'Seconds', 1],
72+
[ '', 2, 1, 'Seconds', 1],
73+
[ '', '', 2, 'Seconds', 1],
74+
[ '', 3, 1, 'Seconds', 1],
75+
[ '', '', 2, 'Seconds', 1],
76+
[ 5, 1, 1, 'Seconds', 1],
77+
[ '', '', 2, 'Seconds', 1],
78+
[ '', 2, 1, 'Seconds', 1],
79+
[ '', '', 2, 'Seconds', 1],
80+
[ '', 3, 1, 'Seconds', 1],
81+
[ '', '', 2, 'Seconds', 1],],
82+
pre=Set('motor_x', 1, completion=True),
83+
post=[Set('motor_x', orig_motor_x, completion=True),
84+
Set('motor_y', orig_motor_y, completion=True),],
85+
log_always=['neutrons', 'setpoint']
86+
)
87+
cmds = table.createScan()
9888

99-
try:
100-
client = ScanClient('localhost', 4810)
101-
scid = client.submit(cmds, name="2D table scan example")
102-
client.waitUntilDone(scid)
103-
print "Number of log calls: %d" % client.lastSerial(scid)
104-
105-
# get raw data back as a Python dict
106-
data = client.getData(scid)
107-
print data
108-
109-
# Create table for motor_x, motor_y and neutrons
110-
table = createTable(data, 'motor_x', 'motor_y', 'neutrons', 'setpoint')
111-
print "Position X: ", table[0]
112-
print "Position Y: ", table[1]
113-
print "Counts : ", table[2]
114-
print "Setpoint : ", table[3]
115-
116-
# Remove specific scan task
117-
client.delete(scid)
118-
# or Remove information for all completed scans
119-
client.clear()
120-
except:
121-
raise
89+
client = ScanClient('localhost', 4810)
90+
scid = client.submit(cmds, name="2D table scan example")
91+
client.waitUntilDone(scid)
92+
93+
# get raw data back as a Python dict
94+
data = client.getData(scid)
95+
96+
# Create table for motor_x, motor_y and neutrons
97+
table = createTable(data, 'motor_x', 'motor_y', 'neutrons', 'setpoint')
98+
print("Position X: ", table[0])
99+
print("Position Y: ", table[1])
100+
print("Counts : ", table[2])
101+
print("Setpoint : ", table[3])
102+
103+
# Remove specific scan task
104+
#client.delete(scid)
105+
# or Remove information for all completed scans
106+
#client.clear()
Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
'''
2-
This is an example how to use PyScanClient library to perform a 2D scan using table scan, and take multiple samples
3-
at each point.
4-
It needs an example EPICS database, simulation.db, which could be found at:
5-
https://github.com/ControlSystemStudio/cs-studio/blob/master/applications/plugins/org.csstudio.scan/examples/
6-
And it assumes the server running on localhost at port 4810.
2+
This is an example how to use PyScanClient library to perform a 2D scan using table scan
73
4+
In addition to the basic table scan operations, it uses
85
9-
It does the following:
10-
- set pv 'motor_x' to 1, which means to open a shutter, and wait until finish.
11-
- loop pv 'motor_x' from 1 to 5 with stepping size = 1 and wait until finish. at each step:
12-
- loop pv 'motor_y' from 1 to 3 with stepping size = 1, and wait until finish. at each step:
13-
- wait for 1 second
14-
- log pv 'motor_x', 'motor_y' and 'neutrons'
15-
- set pv 'motor_x' to original place
16-
- set pv 'motor_y' to original place
17-
- get logged data back
18-
- create a table for the results
19-
- clear scan server
6+
pre to move some motor, assuming that would be a motor that opens a shutter
207
21-
It does not demo:
22-
- read back and its tolerance to ensure
8+
post to restore motor positions
239
24-
Created on Apr 17, 2015
10+
start to do something at each "Wait For" step
2511
26-
@author: shen
12+
@author: shen, Kay Kasemir
2713
'''
2814

2915
from scan.client.scanclient import ScanClient
@@ -50,47 +36,41 @@ def __init__(self):
5036
# return device_name + ".RBV"
5137
# return device_name
5238

53-
if __name__ == '__main__':
54-
orig_motor_x = 0
55-
orig_motor_y = 0
56-
57-
# Custom settings configure the TableScan
58-
setScanSettings(LocalScanSettings())
59-
# Create table scan command
60-
# use function to generate scan range
61-
table = TableScan(['Comment', 'motor_x', 'motor_y', 'loc://i(0)', 'Wait For', 'Value'],
62-
[['Example', '', '', '', '', ''],
63-
['', 'range(1, 6, 1)', 'range(1, 4, 1)','range(1, 3, 1)', 'Seconds', 1],
64-
['', 1, 1, '', '', '']],
65-
pre=Set('motor_x', 1, completion=True),
66-
post=[Set('motor_x', orig_motor_x, completion=True),
67-
Set('motor_y', orig_motor_y, completion=True),],
68-
start=Set("neutrons", 0, completion=True, timeout=10),
69-
log_always=('neutrons', 'setpoint')
70-
)
39+
orig_motor_x = 0
40+
orig_motor_y = 0
41+
42+
# Custom settings configure the TableScan
43+
setScanSettings(LocalScanSettings())
44+
# Create table scan command
45+
# use function to generate scan range
46+
table = TableScan(['Comment', 'motor_x', 'motor_y', 'loc://i(0)', 'Wait For', 'Value'],
47+
[['Example', '', '', '', '', ''],
48+
['', 'range(1, 6, 1)', 'range(1, 4, 1)','range(1, 3, 1)', 'Seconds', 1],
49+
['', 1, 1, '', '', '']],
50+
pre=Set('motor_x', 1, completion=True),
51+
post=[Set('motor_x', orig_motor_x, completion=True),
52+
Set('motor_y', orig_motor_y, completion=True),],
53+
start=Set("neutrons", 0, completion=True, timeout=10),
54+
log_always=('neutrons', 'setpoint')
55+
)
7156

72-
cmds = table.createScan()
57+
cmds = table.createScan()
7358

74-
try:
75-
client = ScanClient('localhost', 4810)
76-
scid = client.submit(cmds, name="2D table scan example")
77-
client.waitUntilDone(scid)
78-
print "Number of log calls: %d" % client.lastSerial(scid)
79-
80-
# get raw data back as a Python dict
81-
data = client.getData(scid)
82-
print data
83-
84-
# Create table for motor_x, motor_y and neutrons
85-
table = createTable(data, 'motor_x', 'motor_y', 'neutrons', 'setpoint')
86-
print "Position X: ", table[0]
87-
print "Position Y: ", table[1]
88-
print "Counts : ", table[2]
89-
print "Setpoint : ", table[3]
90-
91-
# Remove specific scan task
92-
client.delete(scid)
93-
# or Remove information for all completed scans
94-
client.clear()
95-
except:
96-
raise
59+
client = ScanClient('localhost', 4810)
60+
scid = client.submit(cmds, name="2D table scan example")
61+
client.waitUntilDone(scid)
62+
63+
# get raw data back as a Python dict
64+
data = client.getData(scid)
65+
66+
# Create table for motor_x, motor_y and neutrons
67+
table = createTable(data, 'motor_x', 'motor_y', 'neutrons', 'setpoint')
68+
print("Position X: ", table[0])
69+
print("Position Y: ", table[1])
70+
print("Counts : ", table[2])
71+
print("Setpoint : ", table[3])
72+
73+
# Remove specific scan task
74+
#client.delete(scid)
75+
# or Remove information for all completed scans
76+
#client.clear()

0 commit comments

Comments
 (0)