sc_linac
Live¶
In [1]:
Copied!
import lcls_live
import os
os.__file__
import lcls_live
import os
os.__file__
Out[1]:
'/Users/mpe/miniconda3/envs/lcls-live-dev/lib/python3.8/os.py'
In [2]:
Copied!
# Useful for debugging
%load_ext autoreload
%autoreload 2
%config InlineBackend.figure_format = 'retina'
%matplotlib inline
# Useful for debugging
%load_ext autoreload
%autoreload 2
%config InlineBackend.figure_format = 'retina'
%matplotlib inline
In [3]:
Copied!
from lcls_live.datamaps import get_datamaps
from lcls_live.archiver import lcls_archiver_restore
from lcls_live.tools import isotime
import matplotlib.pyplot as plt
import numpy as np
import os
from lcls_live.datamaps import get_datamaps
from lcls_live.archiver import lcls_archiver_restore
from lcls_live.tools import isotime
import matplotlib.pyplot as plt
import numpy as np
import os
In [4]:
Copied!
# Pick a model and slice
MODEL = 'sc_bsyd' # or sc_diag0 or sc_inj
BEGELE = 'BEGINNING'
#ENDELE = 'OTR0H04'
#ENDELE = 'ENDCOL0'
ENDELE = 'END'
# Pick a model and slice
MODEL = 'sc_bsyd' # or sc_diag0 or sc_inj
BEGELE = 'BEGINNING'
#ENDELE = 'OTR0H04'
#ENDELE = 'ENDCOL0'
ENDELE = 'END'
Bmad model¶
In [5]:
Copied!
from pytao import Tao
import pandas as pd
from pytao import Tao
import pandas as pd
In [6]:
Copied!
tao = Tao(f'-init $LCLS_LATTICE/bmad/models/{MODEL}/tao.init -slice {BEGELE}:{ENDELE}')
tao.cmd('place floor bpm_orbit')
tao.cmd('place middle energy')
tao.cmd('sc floor -10 10')
def ele_info(ele):
dat = tao.ele_head(ele)
dat.update(tao.ele_gen_attribs(ele))
return dat
def ele_table(match="*"):
ix_ele = tao.lat_list(match, "ele.ix_ele", flags="-no_slaves")
dat = list(map(ele_info, ix_ele))
df = pd.DataFrame(dat, index=ix_ele)
df.L.fillna(0, inplace=True)
df['s_center'] = df['s'] - df['L']/2
df['s_beginning'] = df['s'] - df['L']
return df
df = ele_table()
# Elements with device names
devices = df[df['alias'] != '']
#devices['name alias s'.split()]
tao = Tao(f'-init $LCLS_LATTICE/bmad/models/{MODEL}/tao.init -slice {BEGELE}:{ENDELE}')
tao.cmd('place floor bpm_orbit')
tao.cmd('place middle energy')
tao.cmd('sc floor -10 10')
def ele_info(ele):
dat = tao.ele_head(ele)
dat.update(tao.ele_gen_attribs(ele))
return dat
def ele_table(match="*"):
ix_ele = tao.lat_list(match, "ele.ix_ele", flags="-no_slaves")
dat = list(map(ele_info, ix_ele))
df = pd.DataFrame(dat, index=ix_ele)
df.L.fillna(0, inplace=True)
df['s_center'] = df['s'] - df['L']/2
df['s_beginning'] = df['s'] - df['L']
return df
df = ele_table()
# Elements with device names
devices = df[df['alias'] != '']
#devices['name alias s'.split()]
In [7]:
Copied!
tao.cmd('x_scale * 0 800')
print(tao.cmd('sho var'))
tao.cmd('x_scale * 0 800')
print(tao.cmd('sho var'))
[' Name Using for Optimization', ' begtwiss[1:6]', ' gradient_L0[1:8]', ' phi0_L0[1:8]', ' q_HTR[1:8]', ' q_L1[1:5]', ' q_L2[1:4]', ' q_L3[1:4]', ' linac_phase[1:4]', ' q_COL1[1:4]', ' q_EMIT2[1:4]', ' bc1[1:1]', ' bc2[1:1]', ' xcor[1:93]', ' ycor[1:93]']
Datamaps, and all PVs needed¶
In [8]:
Copied!
from copy import deepcopy
def filter_datamap(dm, bmad_names):
bnames = dm.data['bmad_name']
bmad_names = set(bmad_names)
ix = bnames[[name in bmad_names for name in bnames]].index
dm2 = deepcopy(dm)
dm2.data = dm.data.loc[ix]
return dm2
from copy import deepcopy
def filter_datamap(dm, bmad_names):
bnames = dm.data['bmad_name']
bmad_names = set(bmad_names)
ix = bnames[[name in bmad_names for name in bnames]].index
dm2 = deepcopy(dm)
dm2.data = dm.data.loc[ix]
return dm2
In [9]:
Copied!
DM0 = get_datamaps(MODEL)
DM0.keys()
DM0 = get_datamaps(MODEL)
DM0.keys()
Out[9]:
dict_keys(['bpms', 'cavities', 'correctors', 'tao_energy_measurements', 'quad', 'quad_corrector', 'solenoid'])
In [10]:
Copied!
good_names = set(df['name'])
bad_eles = [] # any bad eles
for ele in bad_eles:
good_names.remove(ele)
DM = {}
for name, dm in DM0.items():
if name == 'tao_energy_measurements':
# don't filter
DM[name] = dm
else:
DM[name] = filter_datamap(dm, good_names)
DM['cavities'];
good_names = set(df['name'])
bad_eles = [] # any bad eles
for ele in bad_eles:
good_names.remove(ele)
DM = {}
for name, dm in DM0.items():
if name == 'tao_energy_measurements':
# don't filter
DM[name] = dm
else:
DM[name] = filter_datamap(dm, good_names)
DM['cavities'];
In [11]:
Copied!
# datamaps to exclude
DENYLIST = [
#'bpms',
# 'cavities',
'correctors',
#'quad',
]
# datamaps to exclude
DENYLIST = [
#'bpms',
# 'cavities',
'correctors',
#'quad',
]
In [20]:
Copied!
# PVs needed
PVLIST = []
for name, dm in DM.items():
if name in DENYLIST:
continue
PVLIST.extend(dm.pvlist)
PVLIST = list(set(PVLIST))
len(PVLIST)
PVLIST[0:10]
# PVs needed
PVLIST = []
for name, dm in DM.items():
if name in DENYLIST:
continue
PVLIST.extend(dm.pvlist)
PVLIST = list(set(PVLIST))
len(PVLIST)
PVLIST[0:10]
Out[20]:
['BPMS:EMIT2:150:X', 'ACCL:L2B:0630:AACTMEAN', 'ACCL:L2B:0770:AACTMEAN', 'BPMS:HTR:760:X', 'ACCL:L3B:3530:PACTMEAN', 'ACCL:L2B:1250:PACTMEAN', 'ACCL:L2B:1470:PACTMEAN', 'ACCL:L1B:H220:PACTMEAN', 'ACCL:L3B:2080:AACTMEAN', 'ACCL:L3B:1970:AACTMEAN']
In [21]:
Copied!
os.environ['http_proxy']='socks5h://localhost:8080'
os.environ['HTTPS_PROXY']='socks5h://localhost:8080'
os.environ['ALL_PROXY']='socks5h://localhost:8080'
PVDATA=lcls_archiver_restore(PVLIST, '2023-06-08T23:09:50.000000-07:00')
os.environ['http_proxy']='socks5h://localhost:8080'
os.environ['HTTPS_PROXY']='socks5h://localhost:8080'
os.environ['ALL_PROXY']='socks5h://localhost:8080'
PVDATA=lcls_archiver_restore(PVLIST, '2023-06-08T23:09:50.000000-07:00')
Requesting: http://lcls-archapp.slac.stanford.edu/retrieval/data/getDataAtTime?at=2023-06-08T23:09:50.000000-07:00&includeProxies=true Warning: Missing PV: BPMS:EMIT2:150:X Warning: Missing PV: BPMS:HTR:760:X Warning: Missing PV: BPMS:DOG:740:X Warning: Missing PV: BPMS:SPD:955:TMIT Warning: Missing PV: BPMS:DOG:575:Y Warning: Missing PV: BPMS:BPN16:400:Y Warning: Missing PV: BPMS:COL1:120:Y Warning: Missing PV: BPMS:DOG:120:TMIT Warning: Missing PV: BPMS:EXT:748:X Warning: Missing PV: BPMS:BPN24:400:Y Warning: Missing PV: BPMS:SLTD:895:Y Warning: Missing PV: BPMS:DOG:355:TMIT Warning: Missing PV: BPMS:DOG:280:X Warning: Missing PV: BPMS:BPN22:400:TMIT Warning: Missing PV: BPMS:L3B:1783:Y Warning: Missing PV: BPMS:BPN26:400:TMIT Warning: Missing PV: BPMS:L2B:1383:X Warning: Missing PV: BPMS:L2B:1183:Y Warning: Missing PV: BPMS:BPN13:400:Y Warning: Missing PV: BPMS:L3B:1883:TMIT Warning: Missing PV: BPMS:BC1B:125:Y Warning: Missing PV: BPMS:L3B:3383:Y Warning: Missing PV: BPMS:DOG:230:Y Warning: Missing PV: BPMS:BPN26:400:X Warning: Missing PV: BPMS:L3B:2483:Y Warning: Missing PV: BPMS:DOG:250:TMIT Warning: Missing PV: BPMS:COL0:400:Y Warning: Missing PV: BPMS:L3B:2283:Y Warning: Missing PV: BPMS:SLTD:625:Y Warning: Missing PV: BPMS:COL1:800:Y Warning: Missing PV: BPMS:L3B:2383:X Warning: Missing PV: BPMS:BPN27:400:TMIT Warning: Missing PV: BPMS:HTR:540:X Warning: Missing PV: BPMS:BPN15:400:X Warning: Missing PV: BPMS:BPN15:400:Y Warning: Missing PV: ACCL:GUNB:455:AACT_AVG Warning: Missing PV: BPMS:BPN17:400:Y Warning: Missing PV: BPMS:L2B:0883:TMIT Warning: Missing PV: BPMS:COL0:940:X Warning: Missing PV: BPMS:L1B:0283:X Warning: Missing PV: BPMS:DOG:335:X Warning: Missing PV: BPMS:BPN19:400:X Warning: Missing PV: BPMS:BC2B:530:Y Warning: Missing PV: BPMS:HTR:960:X Warning: Missing PV: BPMS:DOG:200:X Warning: Missing PV: BPMS:DOG:740:TMIT Warning: Missing PV: BPMS:COL0:800:X Warning: Missing PV: BPMS:L3B:2083:X Warning: Missing PV: BPMS:L3B:2883:TMIT Warning: Missing PV: BPMS:L0B:0183:X Warning: Missing PV: BPMS:BPN28:400:X Warning: Missing PV: BPMS:L3B:2183:TMIT Warning: Missing PV: BPMS:BPN14:400:TMIT Warning: Missing PV: BPMS:L2B:0483:X Warning: Missing PV: BPMS:BPN23:400:TMIT Warning: Missing PV: BPMS:EMIT2:900:TMIT Warning: Missing PV: BPMS:HTR:980:X Warning: Missing PV: BPMS:DOG:150:X Warning: Missing PV: BPMS:L3B:2183:X Warning: Missing PV: BPMS:COL0:320:X Warning: Missing PV: BPMS:L3B:3483:Y Warning: Missing PV: BPMS:L2B:0783:Y Warning: Missing PV: BPMS:COL1:880:Y Warning: Missing PV: BPMS:SPD:525:TMIT Warning: Missing PV: BPMS:L2B:0583:TMIT Warning: Missing PV: BPMS:COL0:940:Y Warning: Missing PV: BPMS:COL1:280:Y Warning: Missing PV: BPMS:SPD:955:X Warning: Missing PV: BPMS:HTR:320:Y Warning: Missing PV: BPMS:SPD:420:TMIT Warning: Missing PV: BPMS:EMIT2:300:Y Warning: Missing PV: BPMS:L2B:0483:Y Warning: Missing PV: BPMS:BPN25:400:Y Warning: Missing PV: BPMS:DOG:135:TMIT Warning: Missing PV: BPMS:COL0:400:X Warning: Missing PV: BPMS:BPN18:400:X Warning: Missing PV: BPMS:BPN18:400:Y Warning: Missing PV: BPMS:COL1:640:TMIT Warning: Missing PV: BPMS:BPN20:400:Y Warning: Missing PV: BPMS:COL1:560:Y Warning: Missing PV: BPMS:DOG:355:Y Warning: Missing PV: BPMS:L3B:3183:X Warning: Missing PV: BPMS:EXT:351:X Warning: Missing PV: BPMS:L2B:0983:TMIT Warning: Missing PV: BPMS:COL1:640:Y Warning: Missing PV: BPMS:L2B:1583:Y Warning: Missing PV: BPMS:L1B:H283:TMIT Warning: Missing PV: BPMS:DOG:120:X Warning: Missing PV: BPMS:COL1:960:TMIT Warning: Missing PV: BPMS:L3B:1783:X Warning: Missing PV: BPMS:COL1:260:X Warning: Missing PV: BPMS:COL0:880:X Warning: Missing PV: BPMS:L2B:1083:Y Warning: Missing PV: BPMS:L2B:0683:X Warning: Missing PV: BPMS:L3B:2583:TMIT Warning: Missing PV: BPMS:HTR:540:Y Warning: Missing PV: BPMS:COL0:135:TMIT Warning: Missing PV: BPMS:COL0:720:TMIT Warning: Missing PV: BPMS:COL0:720:X Warning: Missing PV: BPMS:EMIT2:150:Y Warning: Missing PV: BPMS:L3B:1883:X Warning: Missing PV: BPMS:COL1:720:Y Warning: Missing PV: BPMS:SLTD:895:X Warning: Missing PV: BPMS:COL1:120:TMIT Warning: Missing PV: BPMS:COL0:280:TMIT Warning: Missing PV: BPMS:DOG:230:X Warning: Missing PV: BPMS:HTR:365:Y Warning: Missing PV: BPMS:EXT:748:Y Warning: Missing PV: BPMS:L3B:2783:X Warning: Missing PV: BPMS:COL0:560:Y Warning: Missing PV: BPMS:BPN17:400:X Warning: Missing PV: BPMS:COL0:480:Y Warning: Missing PV: BPMS:L3B:2783:Y Warning: Missing PV: BPMS:COL0:640:X Warning: Missing PV: BPMS:BPN20:400:X Warning: Missing PV: BPMS:L3B:3383:X Warning: Missing PV: BPMS:BPN15:400:TMIT Warning: Missing PV: BPMS:DOG:200:TMIT Warning: Missing PV: BPMS:COL0:880:TMIT Warning: Missing PV: ACCL:GUNB:455:PACT_AVG Warning: Missing PV: BPMS:BC2B:150:X Warning: Missing PV: BPMS:DOG:405:X Warning: Missing PV: BPMS:BPN25:400:X Warning: Missing PV: BPMS:COL0:720:Y Warning: Missing PV: BPMS:COL0:260:TMIT Warning: Missing PV: BPMS:L3B:2683:X Warning: Missing PV: BPMS:L3B:2083:Y Warning: Missing PV: BPMS:COL0:240:TMIT Warning: Missing PV: BPMS:COL1:960:X Warning: Missing PV: BPMS:L3B:2983:TMIT Warning: Missing PV: BPMS:L3B:2383:Y Warning: Missing PV: BPMS:L2B:1283:Y Warning: Missing PV: BPMS:L3B:1683:Y Warning: Missing PV: BPMS:COL1:320:Y Warning: Missing PV: BPMS:SPD:135:Y Warning: Missing PV: BPMS:L2B:0783:TMIT Warning: Missing PV: BPMS:BPN28:400:Y Warning: Missing PV: BPMS:COL1:260:Y Warning: Missing PV: BPMS:COL0:135:Y Warning: Missing PV: BPMS:COL1:800:TMIT Warning: Missing PV: BPMS:SLTD:625:X Warning: Missing PV: BPMS:L2B:0883:Y Warning: Missing PV: BPMS:BPN13:400:X Warning: Missing PV: BPMS:HTR:760:TMIT Warning: Missing PV: BPMS:DOG:180:X Warning: Missing PV: BPMS:L1B:H183:TMIT Warning: Missing PV: BPMS:BC2B:530:TMIT Warning: Missing PV: BPMS:L3B:2983:X Warning: Missing PV: BPMS:L2B:0983:Y Warning: Missing PV: BPMS:L2B:0583:Y Warning: Missing PV: BPMS:L2B:1083:TMIT Warning: Missing PV: BPMS:L3B:2483:TMIT Warning: Missing PV: BPMS:L2B:0583:X Warning: Missing PV: BPMS:COL1:260:TMIT Warning: Missing PV: BPMS:HTR:320:TMIT Warning: Missing PV: BPMS:L1B:0383:Y Warning: Missing PV: BPMS:SPD:570:TMIT Warning: Missing PV: BPMS:COL0:240:Y Warning: Missing PV: BPMS:HTR:120:X Warning: Missing PV: BPMS:SPD:135:TMIT Warning: Missing PV: BPMS:COL0:480:TMIT Warning: Missing PV: BPMS:L2B:1583:TMIT Warning: Missing PV: BPMS:L3B:3283:Y Warning: Missing PV: BPMS:COL0:640:TMIT Warning: Missing PV: BPMS:COL0:880:Y Warning: Missing PV: BPMS:COL1:280:X Warning: Missing PV: BPMS:SPD:420:X Warning: Missing PV: BPMS:SPD:525:Y Warning: Missing PV: BPMS:COL0:560:TMIT Warning: Missing PV: BPMS:BC2B:530:X Warning: Missing PV: BPMS:BPN28:200:X Warning: Missing PV: BPMS:BPN19:400:TMIT Warning: Missing PV: BPMS:HTR:320:X Warning: Missing PV: BPMS:BPN21:400:X Warning: Missing PV: BPMS:HTR:960:Y Warning: Missing PV: BPMS:DOG:910:Y Warning: Missing PV: BPMS:L1B:H183:Y Warning: Missing PV: BPMS:L0B:0183:Y Warning: Missing PV: BPMS:HTR:980:TMIT Warning: Missing PV: BPMS:EMIT2:300:TMIT Warning: Missing PV: BPMS:L3B:1683:TMIT Warning: Missing PV: BPMS:BC1B:440:X Warning: Missing PV: BPMS:L3B:2083:TMIT Warning: Missing PV: BPMS:COL1:560:X Warning: Missing PV: BPMS:BPN20:400:TMIT Warning: Missing PV: BPMS:BPN25:400:TMIT Warning: Missing PV: BPMS:L1B:H283:X Warning: Missing PV: BPMS:DOG:165:X Warning: Missing PV: BPMS:L3B:1983:Y Warning: Missing PV: BPMS:COL0:480:X Warning: Missing PV: BPMS:HTR:120:Y Warning: Missing PV: BPMS:HTR:960:TMIT Warning: Missing PV: BPMS:EXT:351:Y Warning: Missing PV: BPMS:L1B:0383:TMIT Warning: Missing PV: BPMS:L3B:1983:X Warning: Missing PV: BPMS:BPN14:400:X Warning: Missing PV: BPMS:HTR:860:Y Warning: Missing PV: BPMS:HTR:460:TMIT Warning: Missing PV: BPMS:L2B:0783:X Warning: Missing PV: BPMS:EMIT2:800:X Warning: Missing PV: BPMS:BPN19:400:Y Warning: Missing PV: BPMS:BPN26:400:Y Warning: Missing PV: BPMS:COL1:400:X Warning: Missing PV: BPMS:L3B:1883:Y Warning: Missing PV: BPMS:BPN16:400:TMIT Warning: Missing PV: BPMS:L3B:2183:Y Warning: Missing PV: BPMS:L3B:3583:TMIT Warning: Missing PV: BPMS:DOG:355:X Warning: Missing PV: BPMS:COL1:720:X Warning: Missing PV: BPMS:COL0:260:X Warning: Missing PV: BPMS:DOG:150:TMIT Warning: Missing PV: BPMS:L2B:1183:X Warning: Missing PV: BPMS:BC2B:150:Y Warning: Missing PV: BPMS:L2B:1083:X Warning: Missing PV: BPMS:COL1:880:TMIT Warning: Missing PV: BPMS:DOG:215:X Warning: Missing PV: BPMS:L1B:0283:Y Warning: Missing PV: BPMS:BPN17:400:TMIT Warning: Missing PV: BPMS:SPD:340:TMIT Warning: Missing PV: BPMS:SPD:340:Y Warning: Missing PV: BPMS:L2B:1383:TMIT Warning: Missing PV: BPMS:L2B:1383:Y Warning: Missing PV: BPMS:L3B:2683:Y Warning: Missing PV: BPMS:BPN22:400:Y Warning: Missing PV: BPMS:L1B:H183:X Warning: Missing PV: BPMS:HTR:460:X Warning: Missing PV: BPMS:BC1B:125:X Warning: Missing PV: BPMS:DOG:135:Y Warning: Missing PV: BPMS:COL1:960:Y Warning: Missing PV: BPMS:COL0:800:Y Warning: Missing PV: BPMS:L2B:0883:X Warning: Missing PV: BPMS:BPN27:400:X Warning: Missing PV: BPMS:L2B:1483:X Warning: Missing PV: BPMS:L3B:3183:TMIT Warning: Missing PV: BPMS:SPD:700:X Warning: Missing PV: BPMS:L3B:2883:X Warning: Missing PV: BPMS:COL1:720:TMIT Warning: Missing PV: BPMS:SPD:570:Y Warning: Missing PV: BPMS:L3B:2483:X Warning: Missing PV: BPMS:L3B:3083:X Warning: Missing PV: BPMS:BC1B:440:Y Warning: Missing PV: BPMS:COL0:940:TMIT Warning: Missing PV: BPMS:L3B:2783:TMIT Warning: Missing PV: BPMS:BPN28:200:Y Warning: Missing PV: BPMS:COL1:560:TMIT Warning: Missing PV: BPMS:COL0:800:TMIT Warning: Missing PV: BPMS:DOG:280:Y Warning: Missing PV: BPMS:COL1:880:X Warning: Missing PV: BPMS:BPN28:400:TMIT Warning: Missing PV: BPMS:HTR:365:X Warning: Missing PV: BPMS:L3B:2583:Y Warning: Missing PV: BPMS:EMIT2:300:X Warning: Missing PV: BPMS:L3B:3583:Y Warning: Missing PV: BPMS:SPD:135:X Warning: Missing PV: BPMS:HTR:830:Y Warning: Missing PV: BPMS:L3B:2283:X Warning: Missing PV: BPMS:L2B:1283:TMIT Warning: Missing PV: BPMS:COL1:320:X Warning: Missing PV: BPMS:L3B:2583:X Warning: Missing PV: BPMS:COL0:260:Y Warning: Missing PV: BPMS:SPD:255:X Warning: Missing PV: BPMS:COL1:640:X Warning: Missing PV: BPMS:BPN24:400:X Warning: Missing PV: BPMS:EMIT2:800:TMIT Warning: Missing PV: BPMS:EMIT2:800:Y Warning: Missing PV: BPMS:L2B:1483:Y Warning: Missing PV: BPMS:SPD:570:X Warning: Missing PV: BPMS:COL1:480:X Warning: Missing PV: BPMS:DOG:335:TMIT Warning: Missing PV: BPMS:L3B:3583:X Warning: Missing PV: BPMS:EMIT2:900:X Warning: Missing PV: BPMS:DOG:910:TMIT Warning: Missing PV: BPMS:L3B:3183:Y Warning: Missing PV: BPMS:COL1:400:Y Warning: Missing PV: BPMS:DOG:180:TMIT Warning: Missing PV: BPMS:L3B:2983:Y Warning: Missing PV: BPMS:BPN21:400:Y Warning: Missing PV: BPMS:BC1B:440:TMIT Warning: Missing PV: BPMS:COL0:135:X Warning: Missing PV: BPMS:DOG:135:X Warning: Missing PV: BPMS:DOG:165:TMIT Warning: Missing PV: BPMS:COL1:120:X Warning: Missing PV: BPMS:DOG:200:Y Warning: Missing PV: BPMS:DOG:575:X Warning: Missing PV: BPMS:COL1:480:TMIT Warning: Missing PV: BPMS:DOG:910:X Warning: Missing PV: BPMS:HTR:760:Y Warning: Missing PV: BPMS:DOG:180:Y Warning: Missing PV: BPMS:L3B:3283:TMIT Warning: Missing PV: BPMS:L3B:3483:TMIT Warning: Missing PV: BPMS:COL0:400:TMIT Warning: Missing PV: BPMS:DOG:120:Y Warning: Missing PV: BPMS:HTR:980:Y Warning: Missing PV: BPMS:BPN27:400:Y Warning: Missing PV: BPMS:COL0:280:Y Warning: Missing PV: BPMS:L1B:0283:TMIT Warning: Missing PV: BPMS:SPD:955:Y Warning: Missing PV: BPMS:L3B:3083:TMIT Warning: Missing PV: BPMS:SPD:700:TMIT Warning: Missing PV: BPMS:L3B:3083:Y Warning: Missing PV: BPMS:COL1:400:TMIT Warning: Missing PV: BPMS:EMIT2:900:Y Warning: Missing PV: BPMS:HTR:830:TMIT Warning: Missing PV: BPMS:EXT:748:TMIT Warning: Missing PV: BPMS:COL1:480:Y Warning: Missing PV: BPMS:L3B:2283:TMIT Warning: Missing PV: BPMS:EXT:351:TMIT Warning: Missing PV: BPMS:COL1:280:TMIT Warning: Missing PV: BPMS:BC2B:150:TMIT Warning: Missing PV: BPMS:L1B:0383:X Warning: Missing PV: BPMS:BPN14:400:Y Warning: Missing PV: BPMS:SPD:700:Y Warning: Missing PV: BPMS:L2B:0483:TMIT Warning: Missing PV: BPMS:COL1:800:X Warning: Missing PV: BPMS:L3B:1983:TMIT Warning: Missing PV: BPMS:COL0:280:X Warning: Missing PV: BPMS:L2B:1183:TMIT Warning: Missing PV: BPMS:HTR:540:TMIT Warning: Missing PV: BPMS:L3B:3283:X Warning: Missing PV: BPMS:SPD:525:X Warning: Missing PV: BPMS:L3B:2383:TMIT Warning: Missing PV: BPMS:BPN28:200:TMIT Warning: Missing PV: BPMS:BPN16:400:X Warning: Missing PV: BPMS:COL0:640:Y Warning: Missing PV: BPMS:SPD:420:Y Warning: Missing PV: BPMS:BPN23:400:X Warning: Missing PV: BPMS:DOG:740:Y Warning: Missing PV: BPMS:L3B:3483:X Warning: Missing PV: BPMS:L2B:1583:X Warning: Missing PV: BPMS:L2B:0683:TMIT Warning: Missing PV: BPMS:DOG:230:TMIT Warning: Missing PV: BPMS:SPD:340:X Warning: Missing PV: BPMS:COL0:320:Y Warning: Missing PV: BPMS:L0B:0183:TMIT Warning: Missing PV: BPMS:DOG:150:Y Warning: Missing PV: BPMS:DOG:405:TMIT Warning: Missing PV: BPMS:BC1B:125:TMIT Warning: Missing PV: BPMS:HTR:830:X Warning: Missing PV: BPMS:HTR:860:X Warning: Missing PV: BPMS:L3B:2683:TMIT Warning: Missing PV: BPMS:SLTD:625:TMIT Warning: Missing PV: BPMS:HTR:120:TMIT Warning: Missing PV: BPMS:COL0:240:X Warning: Missing PV: BPMS:COL0:560:X Warning: Missing PV: BPMS:HTR:365:TMIT Warning: Missing PV: BPMS:BPN13:400:TMIT Warning: Missing PV: BPMS:DOG:335:Y Warning: Missing PV: BPMS:DOG:215:TMIT Warning: Missing PV: BPMS:DOG:165:Y Warning: Missing PV: BPMS:COL0:320:TMIT Warning: Missing PV: BPMS:COL1:320:TMIT Warning: Missing PV: BPMS:DOG:280:TMIT Warning: Missing PV: BPMS:L3B:2883:Y Warning: Missing PV: BPMS:SLTD:895:TMIT Warning: Missing PV: BPMS:DOG:250:X Warning: Missing PV: BPMS:BPN23:400:Y Warning: Missing PV: BPMS:L1B:H283:Y Warning: Missing PV: BPMS:SPD:255:Y Warning: Missing PV: BPMS:L2B:0983:X Warning: Missing PV: BPMS:L2B:0683:Y Warning: Missing PV: BPMS:DOG:215:Y Warning: Missing PV: BPMS:L3B:1783:TMIT Warning: Missing PV: BPMS:DOG:250:Y Warning: Missing PV: BPMS:L3B:3383:TMIT Warning: Missing PV: BPMS:L2B:1283:X Warning: Missing PV: BPMS:BPN22:400:X Warning: Missing PV: BPMS:EMIT2:150:TMIT Warning: Missing PV: BPMS:DOG:405:Y Warning: Missing PV: BPMS:SPD:255:TMIT Warning: Missing PV: BPMS:L3B:1683:X Warning: Missing PV: BPMS:BPN24:400:TMIT Warning: Missing PV: BPMS:BPN21:400:TMIT Warning: Missing PV: BPMS:HTR:860:TMIT Warning: Missing PV: BPMS:HTR:460:Y Warning: Missing PV: BPMS:L2B:1483:TMIT Warning: Missing PV: BPMS:BPN18:400:TMIT Warning: Missing PV: BPMS:DOG:575:TMIT
In [26]:
Copied!
cmds=tao_commands(PVDATA)
save_cmds(cmds,filename='live_pvs_bsyd_08-06-23T23:09:50.tao')
cmds=tao_commands(PVDATA)
save_cmds(cmds,filename='live_pvs_bsyd_08-06-23T23:09:50.tao')
EPICS¶
In [ ]:
Copied!
import epics
from epics import caget_many, caget
from time import sleep, time
def caget_dict(pvlist):
return dict(zip(pvlist, caget_many(pvlist)))
import epics
from epics import caget_many, caget
from time import sleep, time
def caget_dict(pvlist):
return dict(zip(pvlist, caget_many(pvlist)))
In [ ]:
Copied!
caget('KLYS:LI22:11:KPHR')
caget('KLYS:LI22:11:KPHR')
In [ ]:
Copied!
# Test get
PVDATA = caget_dict(PVLIST)
BAD_DEVICES = set()
PVLIST_GOOD = []
for k, v in PVDATA.items():
if v is None:
#print('Bad PV:', k)
device = ':'.join((k.split(':')[:-1]))
BAD_DEVICES.add(device)
else:
PVLIST_GOOD.append(k)
# Get bmad names
bdf = devices[['alias', 'name']].set_index('alias')
BAD_NAMES = list(bdf.loc[list(BAD_DEVICES)]['name'])
#BAD_NAMES
#BAD_DEVICES, BAD_NAMES
print(len(BAD_DEVICES))
print(len(PVLIST_GOOD))
# Test get
PVDATA = caget_dict(PVLIST)
BAD_DEVICES = set()
PVLIST_GOOD = []
for k, v in PVDATA.items():
if v is None:
#print('Bad PV:', k)
device = ':'.join((k.split(':')[:-1]))
BAD_DEVICES.add(device)
else:
PVLIST_GOOD.append(k)
# Get bmad names
bdf = devices[['alias', 'name']].set_index('alias')
BAD_NAMES = list(bdf.loc[list(BAD_DEVICES)]['name'])
#BAD_NAMES
#BAD_DEVICES, BAD_NAMES
print(len(BAD_DEVICES))
print(len(PVLIST_GOOD))
In [ ]:
Copied!
MONITOR = {pvname:epics.PV(pvname) for pvname in PVLIST_GOOD}
sleep(1) # Wait for all to connect
MONITOR = {pvname:epics.PV(pvname) for pvname in PVLIST_GOOD}
sleep(1) # Wait for all to connect
In [ ]:
Copied!
def get_pvdata():
itime = isotime()
pvdata = {k:MONITOR[k].get() for k in MONITOR}
return pvdata
PVDATA = get_pvdata()
def get_pvdata():
itime = isotime()
pvdata = {k:MONITOR[k].get() for k in MONITOR}
return pvdata
PVDATA = get_pvdata()
In [ ]:
Copied!
#print(PVDATA);
#print(PVDATA);
Fiter datamamps again¶
In [15]:
Copied!
for name in BAD_NAMES:
good_names.remove(name)
for name in BAD_NAMES:
good_names.remove(name)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[15], line 1 ----> 1 for name in BAD_NAMES: 2 good_names.remove(name) NameError: name 'BAD_NAMES' is not defined
In [23]:
Copied!
DM_GOOD = {}
for name, dm in DM.items():
if name == 'tao_energy_measurements':
# don't filter
DM_GOOD[name] = dm
else:
DM_GOOD[name] = filter_datamap(dm, good_names)
DM_GOOD = {}
for name, dm in DM.items():
if name == 'tao_energy_measurements':
# don't filter
DM_GOOD[name] = dm
else:
DM_GOOD[name] = filter_datamap(dm, good_names)
In [ ]:
Copied!
print(DM_GOOD['bpms'])
print(DM_GOOD['bpms'])
Tao conveniences¶
In [17]:
Copied!
def tao_commands(pvdata):
cmds = []
for name, dm in DM_GOOD.items():
cmds.extend(dm.as_tao(pvdata))
return cmds
def tao_commands(pvdata):
cmds = []
for name, dm in DM_GOOD.items():
cmds.extend(dm.as_tao(pvdata))
return cmds
In [ ]:
Copied!
In [18]:
Copied!
def save_cmds(cmds, filename='cmds.tao'): # Write to file for running with vanilla Tao
with open(filename, 'w') as f:
f.write('set global lattice_calc_on = F\n')
f.write('set global plot_on = F\n')
f.write('set ele quad::* field_master = T')
f.write('set ele SC_L* is_on = F')
for cmd in cmds:
f.write(cmd+'\n')
f.write('set global lattice_calc_on = T\n')
f.write('set global plot_on = T\n')
def save_cmds(cmds, filename='cmds.tao'): # Write to file for running with vanilla Tao
with open(filename, 'w') as f:
f.write('set global lattice_calc_on = F\n')
f.write('set global plot_on = F\n')
f.write('set ele quad::* field_master = T')
f.write('set ele SC_L* is_on = F')
for cmd in cmds:
f.write(cmd+'\n')
f.write('set global lattice_calc_on = T\n')
f.write('set global plot_on = T\n')
In [ ]:
Copied!
# Match HTR to design
def set_htr_twiss(tao):
cmds="""
vv
vd
set data HTR.begtwiss|meas = HTR.begtwiss|design
use dat HTR.begtwiss[1:4]
use var begtwiss[1:4]
olmdif
""".split('\n')
tao.cmds(cmds)
tao.cmd('set global lattice_calc_on = T')
tao.cmd('run')
tao.cmd('set global plot_on = T')
#set_htr_twiss(tao)
# Match HTR to design
def set_htr_twiss(tao):
cmds="""
vv
vd
set data HTR.begtwiss|meas = HTR.begtwiss|design
use dat HTR.begtwiss[1:4]
use var begtwiss[1:4]
olmdif
""".split('\n')
tao.cmds(cmds)
tao.cmd('set global lattice_calc_on = T')
tao.cmd('run')
tao.cmd('set global plot_on = T')
#set_htr_twiss(tao)
In [ ]:
Copied!
# mat2 x, y for PyEmittance
def get_mats():
mat6 = tao.matrix('Q0H01#2', 'OTR0H04')['mat6']
mat2x = mat6[0:2, 0:2]
mat2y = mat6[2:4, 2:4]
return mat2x, mat2y
# mat2 x, y for PyEmittance
def get_mats():
mat6 = tao.matrix('Q0H01#2', 'OTR0H04')['mat6']
mat2x = mat6[0:2, 0:2]
mat2y = mat6[2:4, 2:4]
return mat2x, mat2y
Form commands using PVDATA and datamaps¶
In [ ]:
Copied!
# Master switches for element scaling
tao.cmd('set ele quad::* field_master = T')
# Turn off phase overlays
tao.cmd('set ele SC_L* is_on = F', raises=False)
if MODEL == 'sc_inj':
tao.cmd('set ele lcavity::* autoscale_phase = T')
# Master switches for element scaling
tao.cmd('set ele quad::* field_master = T')
# Turn off phase overlays
tao.cmd('set ele SC_L* is_on = F', raises=False)
if MODEL == 'sc_inj':
tao.cmd('set ele lcavity::* autoscale_phase = T')
In [ ]:
Copied!
pvdata = get_pvdata()
cmds=tao_commands(pvdata)
save_cmds(cmds,filename='live_pvs_26_05_23_1500.tao')
pvdata = get_pvdata()
cmds=tao_commands(pvdata)
save_cmds(cmds,filename='live_pvs_26_05_23_1500.tao')
In [ ]:
Copied!
tao.cmd('scale top 0 5000')
tao.cmd('scale top 0 5000')
Continuous loop¶
In [ ]:
Copied!
def run1():
#sleep(.001)
t1 = time()
pvdata = get_pvdata()
cmds = tao_commands(pvdata)
tao.cmd('set global plot_on = F;set global lattice_calc_on = F')
tao.cmds(cmds); # Apply
tao.cmd('set global lattice_calc_on = T')
tao.cmd('set global plot_on = T')
#toggle_beam()
dt = time()-t1
#print(dt)
def run1():
#sleep(.001)
t1 = time()
pvdata = get_pvdata()
cmds = tao_commands(pvdata)
tao.cmd('set global plot_on = F;set global lattice_calc_on = F')
tao.cmds(cmds); # Apply
tao.cmd('set global lattice_calc_on = T')
tao.cmd('set global plot_on = T')
#toggle_beam()
dt = time()-t1
#print(dt)
In [ ]:
Copied!
tao.cmd('set var *|model=*|design')
tao.cmd('set global lattice_calc_on=T')
tao.cmd('set var *|model=*|design')
tao.cmd('set global lattice_calc_on=T')
In [ ]:
Copied!
%%time
run1()
%%time
run1()
In [ ]:
Copied!
# Set twiss
set_htr_twiss(tao)
# Set twiss
set_htr_twiss(tao)
In [ ]:
Copied!
# Check charge (pC)
df = pd.DataFrame(tao.data_d_array('orbit', 'charge'))
df['charge_live'] =df['meas_value']*1e12
df[['ele_name', 'charge_live']]
# Check charge (pC)
df = pd.DataFrame(tao.data_d_array('orbit', 'charge'))
df['charge_live'] =df['meas_value']*1e12
df[['ele_name', 'charge_live']]
In [ ]:
Copied!
tao.cmd('set var *|model=*|design')
tao.cmd('set var *|model=*|design')
In [ ]:
Copied!
%%tao
use dat orbit.x
use dat orbit.y
sc floor -5 5
sc top
x_scale * 0 50
sc top
%%tao
use dat orbit.x
use dat orbit.y
sc floor -5 5
sc top
x_scale * 0 50
sc top
Continuous run¶
In [ ]:
Copied!
# Run forever
while True:
run1()
# Run forever
while True:
run1()