Special Parsers¶
Some of the Tao python commands output special structures in a ; delimited fashion. Some PyTao methods parse these into more useful structures.
In [1]:
Copied!
from pytao import Tao
from pytao import Tao
In [2]:
Copied!
tao = Tao("-init $ACC_ROOT_DIR/regression_tests/pipe_test/cesr/tao.init -noplot")
tao = Tao("-init $ACC_ROOT_DIR/regression_tests/pipe_test/cesr/tao.init -noplot")
data_d_array¶
In [3]:
Copied!
tao.data_d_array("orbit", "x")[7]
tao.data_d_array("orbit", "x")[7]
Out[3]:
{'ix_d1': 7,
'data_type': 'orbit.x',
'merit_type': 'target',
'ele_ref_name': '',
'ele_start_name': '',
'ele_name': 'DET_07W',
'meas_value': 0.0,
'model_value': -0.009099953450224905,
'design_value': -0.009099953450224905,
'useit_opt': False,
'useit_plot': False,
'good_user': True,
'weight': 1000000.0,
'exists': True}
derivative¶
In [4]:
Copied!
tao.cmd("veto var *;veto dat *;")
tao.cmd("use var quad_k1[3:5]")
tao.cmd("set dat orbit.x[1:5]|meas=0")
tao.cmd("use dat orbit.x[1:5]");
tao.cmd("veto var *;veto dat *;")
tao.cmd("use var quad_k1[3:5]")
tao.cmd("set dat orbit.x[1:5]|meas=0")
tao.cmd("use dat orbit.x[1:5]");
In [5]:
Copied!
result = tao.derivative()
result
result = tao.derivative()
result
Out[5]:
{1: array([[-1.75846772e-02, -3.30389470e-02, 2.16132818e-03],
[-1.71130711e-02, -3.57888102e-02, 2.83783437e-03],
[ 1.89157404e-03, -9.56713881e-03, 2.40300210e-03],
[-8.93898601e-03, 1.92383152e-03, 2.67011998e-03],
[-1.10350726e-02, -1.42988399e-02, -1.66271090e-05]])}
n_datums x n_variables
In [6]:
Copied!
result[1].shape
result[1].shape
Out[6]:
(5, 3)
ele_control_var¶
In [7]:
Copied!
tao.ele_control_var("H01W")
tao.ele_control_var("H01W")
Out[7]:
{'HKICK': 0.0}
lat_ele_list¶
In [8]:
Copied!
result = tao.lat_ele_list()
result[0:5]
result = tao.lat_ele_list()
result[0:5]
Out[8]:
['BEGINNING', 'IP_L0', 'CLEO_SOL#3', 'DET_00W', 'CLEO_SOL#4']
lord_control¶
In [9]:
Copied!
tao.lord_control('sex_20w')
tao.lord_control('sex_20w')
Out[9]:
[{'index': 992,
'name': 'RAW_XQUNE_1',
'key': 'Group',
'attribute': 'K2',
'expression': '0.4034E-01*COMMAND',
'value': 0.0},
{'index': 993,
'name': 'RAW_XQUNE_2',
'key': 'Group',
'attribute': 'K2',
'expression': '0.9150E-02*COMMAND',
'value': 0.0},
{'index': 994,
'name': 'RAW_XQUNE_3',
'key': 'Group',
'attribute': 'K2',
'expression': '0.0000E+00*COMMAND',
'value': 0.0},
{'index': 995,
'name': 'RAW_XQUNE_4',
'key': 'Group',
'attribute': 'K2',
'expression': '0.0000E+00*COMMAND',
'value': 0.0}]
matrix¶
In [10]:
Copied!
tao.matrix("beginning", "end")
tao.matrix("beginning", "end")
Out[10]:
{'mat6': array([[-9.85453321e-01, -1.78459151e-01, -2.95064264e-02,
-3.72328913e-05, -1.28463592e-03, 1.69890832e-03],
[ 1.94136498e-01, -9.79571649e-01, -7.19934542e-03,
8.91976963e-04, -5.89572298e-03, -3.81443689e-02],
[-8.56326169e-04, 6.02559410e-05, -8.76189778e-01,
-8.41353610e-03, 1.67854914e-05, 2.64910033e-03],
[ 1.16108943e-02, 2.96794811e-02, 2.66272918e+01,
-8.85649653e-01, 2.27202188e-05, -4.04349279e-02],
[-8.86152164e-02, -6.13453961e-03, 3.48586759e-02,
-2.68733720e-03, 9.47817657e-01, -8.79514378e+00],
[ 5.30821801e-03, -2.93203403e-04, 1.07833932e-04,
-1.59653540e-05, 1.15997844e-02, 9.47355161e-01]]),
'vec0': array([ 3.92874185e-04, 4.73093997e-03, 1.86151033e-06, -9.57458176e-05,
-7.06702237e-05, 5.03940903e-06])}
merit¶
In [11]:
Copied!
tao.merit()
tao.merit()
Out[11]:
411.8266219477228
plot_list¶
In [12]:
Copied!
result = tao.plot_list("r")
result[0:2]
result = tao.plot_list("r")
result[0:2]
Out[12]:
[{'region': 'top',
'ix': 1,
'plot_name': '',
'visible': False,
'x1': 0.0,
'x2': 1.0,
'y1': 0.48,
'y2': 0.95},
{'region': 'bottom',
'ix': 2,
'plot_name': '',
'visible': False,
'x1': 0.0,
'x2': 1.0,
'y1': 0.0,
'y2': 0.48}]
In [13]:
Copied!
# 't' gives a mapping of template plot to index
result = tao.plot_list("t")
result["cbar"]
# 't' gives a mapping of template plot to index
result = tao.plot_list("t")
result["cbar"]
Out[13]:
5
slave_control¶
In [14]:
Copied!
tao.slave_control("ASYM_IR")
tao.slave_control("ASYM_IR")
Out[14]:
[{'branch': 0,
'index': 870,
'name': 'Q00W',
'key': 'Quadrupole',
'attribute': 'TILT',
'expression': '-0.005394*COMMAND',
'value': 0.0},
{'branch': 0,
'index': 871,
'name': 'Q00E',
'key': 'Quadrupole',
'attribute': 'TILT',
'expression': '0.005394*COMMAND',
'value': 0.0},
{'branch': 0,
'index': 10,
'name': 'Q01W',
'key': 'Quadrupole',
'attribute': 'TILT',
'expression': '-0.008269*COMMAND',
'value': 0.0},
{'branch': 0,
'index': 860,
'name': 'Q01E',
'key': 'Quadrupole',
'attribute': 'TILT',
'expression': '0.008269*COMMAND',
'value': 0.0},
{'branch': 0,
'index': 14,
'name': 'Q02W',
'key': 'Quadrupole',
'attribute': 'TILT',
'expression': '-0.016*COMMAND',
'value': 0.0},
{'branch': 0,
'index': 856,
'name': 'Q02E',
'key': 'Quadrupole',
'attribute': 'TILT',
'expression': '0.016*COMMAND',
'value': 0.0}]
In [15]:
Copied!
tao.slave_control('cleo_sol')
tao.slave_control('cleo_sol')
Out[15]:
[{'branch': 0,
'index': 865,
'name': 'Q00E\\CLEO_SOL',
'key': 'Sol_Quad',
'attribute': '',
'expression': '',
'value': None},
{'branch': 0,
'index': 866,
'name': 'CLEO_SOL#1',
'key': 'Solenoid',
'attribute': '',
'expression': '',
'value': None},
{'branch': 0,
'index': 868,
'name': 'CLEO_SOL#2',
'key': 'Solenoid',
'attribute': '',
'expression': '',
'value': None},
{'branch': 0,
'index': 2,
'name': 'CLEO_SOL#3',
'key': 'Solenoid',
'attribute': '',
'expression': '',
'value': None},
{'branch': 0,
'index': 4,
'name': 'CLEO_SOL#4',
'key': 'Solenoid',
'attribute': '',
'expression': '',
'value': None},
{'branch': 0,
'index': 5,
'name': 'Q00W\\CLEO_SOL',
'key': 'Sol_Quad',
'attribute': '',
'expression': '',
'value': None}]
spin_invariant¶
In [16]:
Copied!
tao.spin_invariant("l0")
tao.spin_invariant("l0")
Out[16]:
array([[ 0. , 0.99835696, 0.05730085],
[ 0. , 0.99835696, 0.05730085],
[-0.05286846, 0.99704205, 0.05578608],
...,
[-0.24326431, 0.96860134, 0.05132168],
[-0.29421324, 0.95443764, 0.0498734 ],
[-0.29421324, 0.95443764, 0.0498734 ]], shape=(870, 3))
taylor_map¶
In [17]:
Copied!
tt = tao.taylor_map("beginning", "end", order=2)
tt
tt = tao.taylor_map("beginning", "end", order=2)
tt
Out[17]:
{1: {(0, 0, 0, 0, 0, 0): -1.663663315876102e-05,
(1, 0, 0, 0, 0, 0): -0.9851967120532419,
(0, 1, 0, 0, 0, 0): -0.1799435415211994,
(0, 0, 1, 0, 0, 0): -0.02969939306602652,
(2, 0, 0, 0, 0, 0): 0.4460783429544521,
(1, 1, 0, 0, 0, 0): -1.008364774867299,
(0, 2, 0, 0, 0, 0): 1.026201197382483,
(1, 0, 1, 0, 0, 0): -0.8265229408633691,
(0, 1, 1, 0, 0, 0): 0.6673875434755423,
(0, 0, 2, 0, 0, 0): 44.72413756828593,
(0, 0, 0, 1, 0, 0): -3.897078658961921e-05,
(1, 0, 0, 1, 0, 0): -0.001237377290622893,
(0, 1, 0, 1, 0, 0): -0.03711173094227151,
(0, 0, 1, 1, 0, 0): -4.034505895762329,
(0, 0, 0, 0, 1, 0): -0.001311633423231367,
(1, 0, 0, 0, 1, 0): -0.1495231877499288,
(0, 1, 0, 0, 1, 0): 0.02993335931356712,
(0, 0, 1, 0, 1, 0): 0.1058074573970632,
(0, 0, 0, 0, 0, 1): 0.001758604820315196,
(1, 0, 0, 0, 0, 1): 2.902991412640358,
(0, 1, 0, 0, 0, 1): 3.495788909509791,
(0, 0, 1, 0, 0, 1): 7.970833926690308,
(0, 0, 0, 2, 0, 0): -0.01848110916841533,
(0, 0, 0, 1, 1, 0): -0.003927668978393678,
(0, 0, 0, 0, 2, 0): 0.0007428236883565149,
(0, 0, 0, 1, 0, 1): 0.02794234209755205,
(0, 0, 0, 0, 1, 1): -0.01340339247994965,
(0, 0, 0, 0, 0, 2): -2.389714447683831},
2: {(0, 0, 0, 0, 0, 0): 0.002390486427588625,
(1, 0, 0, 0, 0, 0): 0.1951380023906334,
(0, 1, 0, 0, 0, 0): -0.9793503476890666,
(0, 0, 1, 0, 0, 0): -0.007320212954621833,
(2, 0, 0, 0, 0, 0): 1.325055468622104,
(1, 1, 0, 0, 0, 0): -0.1691707336263001,
(0, 2, 0, 0, 0, 0): 0.2957963327689206,
(1, 0, 1, 0, 0, 0): -0.9621842411807667,
(0, 1, 1, 0, 0, 0): 0.6979789686747241,
(0, 0, 2, 0, 0, 0): 100.4842733690747,
(0, 0, 0, 1, 0, 0): 0.0009002282272501049,
(1, 0, 0, 1, 0, 0): 0.04525199944493575,
(0, 1, 0, 1, 0, 0): 0.009723770997434291,
(0, 0, 1, 1, 0, 0): -2.891544174807158,
(0, 0, 0, 0, 1, 0): -0.005895603143420603,
(1, 0, 0, 0, 1, 0): -0.06086924062652637,
(0, 1, 0, 0, 1, 0): 0.1315099773514083,
(0, 0, 1, 0, 1, 0): 0.08125023804303201,
(0, 0, 0, 0, 0, 1): -0.03818724579207342,
(1, 0, 0, 0, 0, 1): -9.552172939831097,
(0, 1, 0, 0, 0, 1): -5.335807949391839,
(0, 0, 1, 0, 0, 1): 4.529237964569154,
(0, 0, 0, 2, 0, 0): 0.06290793699358867,
(0, 0, 0, 1, 1, 0): -0.001498635846625714,
(0, 0, 0, 0, 2, 0): 0.0005879882223331649,
(0, 0, 0, 1, 0, 1): -0.318535803469644,
(0, 0, 0, 0, 1, 1): 0.04129426446116587,
(0, 0, 0, 0, 0, 2): 0.7660284528539104},
3: {(0, 0, 0, 0, 0, 0): 1.051576321570468e-06,
(1, 0, 0, 0, 0, 0): -0.0008641933607053454,
(0, 1, 0, 0, 0, 0): 6.23497460807503e-05,
(0, 0, 1, 0, 0, 0): -0.8735664544953124,
(2, 0, 0, 0, 0, 0): -0.02175524307656655,
(1, 1, 0, 0, 0, 0): 0.0006311402157647755,
(0, 2, 0, 0, 0, 0): -0.01816054787218362,
(1, 0, 1, 0, 0, 0): 4.982275160500788,
(0, 1, 1, 0, 0, 0): -3.433303865073222,
(0, 0, 2, 0, 0, 0): -0.3055611002607757,
(0, 0, 0, 1, 0, 0): -0.008568348722761597,
(1, 0, 0, 1, 0, 0): -0.1326566527873965,
(0, 1, 0, 1, 0, 0): -0.02205311167694413,
(0, 0, 1, 1, 0, 0): 0.006410850588371118,
(0, 0, 0, 0, 1, 0): 1.680935090771447e-05,
(1, 0, 0, 0, 1, 0): 0.002446658877249613,
(0, 1, 0, 0, 1, 0): -0.003964128422886273,
(0, 0, 1, 0, 1, 0): -0.2990551610717777,
(0, 0, 0, 0, 0, 1): 0.002644675503506971,
(1, 0, 0, 0, 0, 1): 0.3195108573564526,
(0, 1, 0, 0, 0, 1): 0.01417105190318864,
(0, 0, 1, 0, 0, 1): -8.266266353028323,
(0, 0, 0, 2, 0, 0): -0.0003181550482630839,
(0, 0, 0, 1, 1, 0): 0.0006337725085954185,
(0, 0, 0, 0, 2, 0): -2.100259138637954e-05,
(0, 0, 0, 1, 0, 1): 0.08468183811109095,
(0, 0, 0, 0, 1, 1): -0.001273412392493152,
(0, 0, 0, 0, 0, 2): 0.02187419735749623},
4: {(0, 0, 0, 0, 0, 0): 1.820872467229003e-06,
(1, 0, 0, 0, 0, 0): 0.01171087733065387,
(0, 1, 0, 0, 0, 0): 0.02987316058380224,
(0, 0, 1, 0, 0, 0): 26.66379459078713,
(2, 0, 0, 0, 0, 0): 0.08681819415300558,
(1, 1, 0, 0, 0, 0): 0.8610409137330804,
(0, 2, 0, 0, 0, 0): 0.1908223001602236,
(1, 0, 1, 0, 0, 0): 92.62933629771324,
(0, 1, 1, 0, 0, 0): 46.03965797710588,
(0, 0, 2, 0, 0, 0): 0.4495708655835476,
(0, 0, 0, 1, 0, 0): -0.8832328643502095,
(1, 0, 0, 1, 0, 0): -0.08243296060628674,
(0, 1, 0, 1, 0, 0): 4.596073489832832,
(0, 0, 1, 1, 0, 0): 0.6089764351181065,
(0, 0, 0, 0, 1, 0): 2.469145462406307e-05,
(1, 0, 0, 0, 1, 0): 0.0364418086845746,
(0, 1, 0, 0, 1, 0): 0.004788420364244233,
(0, 0, 1, 0, 1, 0): -0.7064855714141111,
(0, 0, 0, 0, 0, 1): -0.04048174563271338,
(1, 0, 0, 0, 0, 1): -2.750827213353186,
(0, 1, 0, 0, 0, 1): -8.498719552160969,
(0, 0, 1, 0, 0, 1): -131.3504692179984,
(0, 0, 0, 2, 0, 0): 0.00467518361783611,
(0, 0, 0, 1, 1, 0): 0.2762218691377479,
(0, 0, 0, 0, 2, 0): -1.882242362295555e-05,
(0, 0, 0, 1, 0, 1): 4.504042326501212,
(0, 0, 0, 0, 1, 1): 0.004337445813969101,
(0, 0, 0, 0, 0, 2): 0.1200622377732416},
5: {(0, 0, 0, 0, 0, 0): -0.0003988825885104795,
(1, 0, 0, 0, 0, 0): -0.08867583047350568,
(0, 1, 0, 0, 0, 0): -0.006096817614073755,
(0, 0, 1, 0, 0, 0): 0.03490989261913222,
(2, 0, 0, 0, 0, 0): -4.515194603683058,
(1, 1, 0, 0, 0, 0): -3.26117753783096,
(0, 2, 0, 0, 0, 0): -1.998613279599774,
(1, 0, 1, 0, 0, 0): 6.726211695256906,
(0, 1, 1, 0, 0, 0): -7.668169817142868,
(0, 0, 2, 0, 0, 0): -193.6425802145972,
(0, 0, 0, 1, 0, 0): -0.002683899112795019,
(1, 0, 0, 1, 0, 0): -0.3111691959498127,
(0, 1, 0, 1, 0, 0): -0.03868717200268324,
(0, 0, 1, 1, 0, 0): 7.806579107423324,
(0, 0, 0, 0, 1, 0): 0.9478074310531234,
(1, 0, 0, 0, 1, 0): 0.03621575683611694,
(0, 1, 0, 0, 1, 0): 0.00992368129841801,
(0, 0, 1, 0, 1, 0): -0.0420499399343808,
(0, 0, 0, 0, 0, 1): -8.795046419066633,
(1, 0, 0, 0, 0, 1): 1.218662133715915,
(0, 1, 0, 0, 0, 1): 5.234260115388981,
(0, 0, 1, 0, 0, 1): 1.120754082998407,
(0, 0, 0, 2, 0, 0): -0.01147058767200288,
(0, 0, 0, 1, 1, 0): 0.001855809256983272,
(0, 0, 0, 0, 2, 0): -0.0003150806991335138,
(0, 0, 0, 1, 0, 1): -0.007723575895862872,
(0, 0, 0, 0, 1, 1): 0.01262901590201659,
(0, 0, 0, 0, 0, 2): 0.3602552148611204},
6: {(0, 0, 0, 0, 0, 0): -7.157398214836433e-06,
(1, 0, 0, 0, 0, 0): 0.005312723567152446,
(0, 1, 0, 0, 0, 0): -0.0003111339911674757,
(0, 0, 1, 0, 0, 0): 0.0001062147221827918,
(2, 0, 0, 0, 0, 0): -0.00955208908821292,
(1, 1, 0, 0, 0, 0): -0.1765606605545084,
(0, 2, 0, 0, 0, 0): -0.02750627559470687,
(1, 0, 1, 0, 0, 0): -0.01703288309120158,
(0, 1, 1, 0, 0, 0): 0.005310340565191788,
(0, 0, 2, 0, 0, 0): 2.022175581138407,
(0, 0, 0, 1, 0, 0): -1.591792929819402e-05,
(1, 0, 0, 1, 0, 0): -0.001643685159161703,
(0, 1, 0, 1, 0, 0): -0.004086270092928905,
(0, 0, 1, 1, 0, 0): -0.155773826182358,
(0, 0, 0, 0, 1, 0): 0.01159978903740704,
(1, 0, 0, 0, 1, 0): -0.0002343776131378632,
(0, 1, 0, 0, 1, 0): 0.001428573856244945,
(0, 0, 1, 0, 1, 0): 0.0001356850675340411,
(0, 0, 0, 0, 0, 1): 0.9473650210725785,
(1, 0, 0, 0, 0, 1): -0.05645633330622575,
(0, 1, 0, 0, 0, 1): 0.01332992508854709,
(0, 0, 1, 0, 0, 1): 0.002969569656971666,
(0, 0, 0, 2, 0, 0): -0.0008898006711384877,
(0, 0, 0, 1, 1, 0): -1.099847007657961e-07,
(0, 0, 0, 0, 2, 0): 4.336973485425701e-06,
(0, 0, 0, 1, 0, 1): -0.002003979108909902,
(0, 0, 0, 0, 1, 1): 0.0009052996247140288,
(0, 0, 0, 0, 0, 2): 0.009597494557152697}}
In [18]:
Copied!
# Compare some terms with the matrix calc:
tao.matrix("beginning", "end")["mat6"][0, 0], tt[1][(1, 0, 0, 0, 0, 0)]
# Compare some terms with the matrix calc:
tao.matrix("beginning", "end")["mat6"][0, 0], tt[1][(1, 0, 0, 0, 0, 0)]
Out[18]:
(np.float64(-0.9854533212937209), -0.9851967120532419)
In [19]:
Copied!
tao.matrix("beginning", "end")["mat6"][1, 0], tt[2][(1, 0, 0, 0, 0, 0)]
tao.matrix("beginning", "end")["mat6"][1, 0], tt[2][(1, 0, 0, 0, 0, 0)]
Out[19]:
(np.float64(0.1941364977045709), 0.1951380023906334)
var_v_array¶
In [20]:
Copied!
result = tao.var_v_array("quad_k1")
result[0:2]
result = tao.var_v_array("quad_k1")
result[0:2]
Out[20]:
[{'ix_v1': 0,
'var_attrib_name': 'Q00W[K1]',
'meas_value': 0.0,
'model_value': -0.8417848364530158,
'design_value': -0.8417848364530158,
'useit_opt': False,
'good_user': False,
'weight': 100000.0},
{'ix_v1': 3,
'var_attrib_name': 'Q03W[K1]',
'meas_value': 0.0,
'model_value': -0.128947,
'design_value': -0.128947,
'useit_opt': True,
'good_user': True,
'weight': 100000.0}]
In [ ]:
Copied!