In [1]:
import os
import phantasy
import scan
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
machine = "FRIB_FLAME"
mp = phantasy.MachinePortal(machine=machine, segment='LINAC')
In [3]:
all_cavities = mp.get_elements(type='CAV')
cav = all_cavities[0]
print(cav)
In [4]:
# set
device_set = str(cav.pv(field='PHA', handle='setpoint')[0])
print(device_set)
In [5]:
# read
device_read = str(cav.pv(field='PHA', handle='readback')[0])
print(device_read)
In [6]:
mp.next_elements(cav, count=10, type='BPM', range='0::1')
Out[6]:
In [7]:
bpm1, bpm2 = mp.next_elements(cav, count=10, type='BPM', range='0::1')[2:5:2]
In [8]:
bpm1, bpm2
Out[8]:
In [9]:
mp.get_elements(srange=(cav.se, bpm2.sb))
Out[9]:
In [10]:
cavs_to_turn_off = mp.get_elements(type='CAV', srange=(cav.se, bpm2.sb))
In [11]:
cavs_to_turn_off
Out[11]:
In [12]:
cavs_pv_amp = [str(c.pv(field='AMP', handle='setpoint')[0]) for c in cavs_to_turn_off]
cavs_pv_pha = [str(c.pv(field='PHA', handle='setpoint')[0]) for c in cavs_to_turn_off]
In [13]:
cavs_settings0 = phantasy.caget(cavs_pv_amp + cavs_pv_pha)
In [14]:
cavs_settings0
Out[14]:
In [15]:
phantasy.caput(cavs_pv_amp + cavs_pv_pha, [0.0]*len(cavs_pv_amp+cavs_pv_pha), wait=True)
Out[15]:
In [16]:
[(c.AMP, c.PHA) for c in cavs_to_turn_off]
Out[16]:
Scan tasks are globally managed by SCAN SERVER, what the users have to do is create task by using classes from phantasy
, then submit to SERVER. Scan procedure state could be checked interactively in python terminal or in Scan Monitor of CSS; SCAN SERVER also can respond specific request comes from scan client, i.e. python terminal or CSS.
In [17]:
device_set_setting0 = phantasy.caget(device_set)
In [18]:
print(device_set_setting0)
In [19]:
log_devices = [str(bpm1.pv(field='PHA', handle='readback')[0]), str(bpm2.pv(field='PHA', handle='readback')[0]),
str(bpm1.pv(field='ENG', handle='readback')[0]), str(bpm2.pv(field='ENG', handle='readback')[0]),
device_read]
In [20]:
print(log_devices)
In [21]:
scantask = phantasy.ScanClient1D()
In [22]:
scantask
Out[22]:
In [23]:
scantask.device_set = device_set
scantask.device_read = device_read
scantask.log_devices = log_devices
scantask.timeout = 5.0
scantask.tolerance = 0.5
scantask.scan_start = 0.0
scantask.scan_stop = 360.0
scantask.scan_step = 10.0
scantask.delay = 1.0
scantask.n_sample = 5
scantask.name = 'Cavity Tunning Demo'
scantask.pre_scan = []
post_cmds = [scan.Set(device_set, device_set_setting0)]
for k,v in zip(cavs_pv_amp + cavs_pv_pha, cavs_settings0):
post_cmds.append(scan.Set(k, v))
scantask.post_scan = post_cmds
scantask.build_scan(completion=True)
Out[23]:
In [24]:
#print(scantask.simulate_scan())
In [32]:
sid = scantask.submit_scan()
In [35]:
print(scantask)
In [36]:
scan_id = sid
n = 5
client = phantasy.ScanClient1D()
In [37]:
scandata = client.get_data(scan_id, n)
In [38]:
scandata.get_all_names()
Out[38]:
In [39]:
ks = scandata.get_all_names()
idx = 4
mean_data1= scandata.get_average(ks[0])
mean_data2 = scandata.get_average(ks[idx])
std_data1 = scandata.get_errorbar(ks[0])
std_data2 = scandata.get_errorbar(ks[idx])
In [40]:
fig = plt.figure()
ax = fig.add_subplot(111)
ebplt = ax.errorbar(mean_data1, mean_data2, xerr=std_data1, yerr=std_data2)
ax.set_xlabel(ks[1])
ax.set_ylabel(ks[idx])
Out[40]: