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.009100179874913385,
'design_value': -0.009100179874913385,
'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.75789242e-02, -3.30354483e-02, 2.16286137e-03],
[-1.71064367e-02, -3.57846863e-02, 2.83962238e-03],
[ 1.89536295e-03, -9.56357860e-03, 2.40380960e-03],
[-8.93617989e-03, 1.92800442e-03, 2.67051862e-03],
[-1.10369164e-02, -1.42981636e-02, -1.70878525e-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.85351881e-01, -1.79149170e-01, -2.97356752e-02,
-3.70462286e-05, -1.28671061e-03, 1.68915708e-03],
[ 1.94467999e-01, -9.79476701e-01, -7.29693507e-03,
9.00535961e-04, -5.89680437e-03, -3.81575900e-02],
[-8.64910621e-04, 6.03097224e-05, -8.76142848e-01,
-8.41647594e-03, 1.68277640e-05, 2.64944119e-03],
[ 1.17019159e-02, 2.99069569e-02, 2.66277123e+01,
-8.85604231e-01, 2.27914325e-05, -4.04365144e-02],
[-8.86366329e-02, -6.17258533e-03, 3.48596331e-02,
-2.68804351e-03, 9.47817675e-01, -8.79514114e+00],
[ 5.30932160e-03, -2.91193146e-04, 1.07897584e-04,
-1.59235542e-05, 1.15997844e-02, 9.47355135e-01]]),
'vec0': array([ 3.94559261e-04, 4.73104939e-03, 1.84806156e-06, -9.61056028e-05,
-7.06064978e-05, 5.03620733e-06])}
merit¶
In [11]:
Copied!
tao.merit()
tao.merit()
Out[11]:
411.8662079389297
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.99835699, 0.05730026],
[ 0. , 0.99835699, 0.05730026],
[-0.05286846, 0.99704208, 0.05578538],
...,
[-0.24326456, 0.96860133, 0.05132084],
[-0.29421348, 0.95443762, 0.04987246],
[-0.29421348, 0.95443762, 0.04987246]], 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.666920161841325e-05,
(1, 0, 0, 0, 0, 0): -0.9851968585153759,
(0, 1, 0, 0, 0, 0): -0.1799432166811766,
(0, 0, 1, 0, 0, 0): -0.02969994714740817,
(2, 0, 0, 0, 0, 0): 0.446161656765041,
(1, 1, 0, 0, 0, 0): -1.008456864431267,
(0, 2, 0, 0, 0, 0): 1.026179617184976,
(1, 0, 1, 0, 0, 0): -0.8264286555235889,
(0, 1, 1, 0, 0, 0): 0.6675822481864937,
(0, 0, 2, 0, 0, 0): 44.721397721057,
(0, 0, 0, 1, 0, 0): -3.894825442545077e-05,
(1, 0, 0, 1, 0, 0): -0.001248496906540398,
(0, 1, 0, 1, 0, 0): -0.03710910643053156,
(0, 0, 1, 1, 0, 0): -4.034568109780643,
(0, 0, 0, 0, 1, 0): -0.001311629730985873,
(1, 0, 0, 0, 1, 0): -0.1495236036241807,
(0, 1, 0, 0, 1, 0): 0.02993309294244235,
(0, 0, 1, 0, 1, 0): 0.1058049063063431,
(0, 0, 0, 0, 0, 1): 0.001759157799789709,
(1, 0, 0, 0, 0, 1): 2.902952517857053,
(0, 1, 0, 0, 0, 1): 3.495763067513963,
(0, 0, 1, 0, 0, 1): 7.970312001093014,
(0, 0, 0, 2, 0, 0): -0.01847489806658208,
(0, 0, 0, 1, 1, 0): -0.003927640222696216,
(0, 0, 0, 0, 2, 0): 0.0007428095980003094,
(0, 0, 0, 1, 0, 1): 0.02794537651100455,
(0, 0, 0, 0, 1, 1): -0.01340325033543881,
(0, 0, 0, 0, 0, 2): -2.38973417398325},
2: {(0, 0, 0, 0, 0, 0): 0.002390323331818056,
(1, 0, 0, 0, 0, 0): 0.1951380196591954,
(0, 1, 0, 0, 0, 0): -0.9793502600537423,
(0, 0, 1, 0, 0, 0): -0.007321532079511708,
(2, 0, 0, 0, 0, 0): 1.325192160158742,
(1, 1, 0, 0, 0, 0): -0.1693884097596789,
(0, 2, 0, 0, 0, 0): 0.2958651703291606,
(1, 0, 1, 0, 0, 0): -0.9625310533482303,
(0, 1, 1, 0, 0, 0): 0.6977816673002778,
(0, 0, 2, 0, 0, 0): 100.486720065922,
(0, 0, 0, 1, 0, 0): 0.0009002513176170819,
(1, 0, 0, 1, 0, 0): 0.04524517217846296,
(0, 1, 0, 1, 0, 0): 0.00973301792536872,
(0, 0, 1, 1, 0, 0): -2.891755311356318,
(0, 0, 0, 0, 1, 0): -0.005895582043734337,
(1, 0, 0, 0, 1, 0): -0.06086925950481124,
(0, 1, 0, 0, 1, 0): 0.1315109095806674,
(0, 0, 1, 0, 1, 0): 0.08124983875575768,
(0, 0, 0, 0, 0, 1): -0.03818821065479909,
(1, 0, 0, 0, 0, 1): -9.55205584487926,
(0, 1, 0, 0, 0, 1): -5.335702964791745,
(0, 0, 1, 0, 0, 1): 4.529220436095169,
(0, 0, 0, 2, 0, 0): 0.06290614073194582,
(0, 0, 0, 1, 1, 0): -0.001498556755164408,
(0, 0, 0, 0, 2, 0): 0.0005879464559548268,
(0, 0, 0, 1, 0, 1): -0.3185252310850368,
(0, 0, 0, 0, 1, 1): 0.04129485359556571,
(0, 0, 0, 0, 0, 2): 0.7660390688663289},
3: {(0, 0, 0, 0, 0, 0): 1.057697177471081e-06,
(1, 0, 0, 0, 0, 0): -0.0008642295128027683,
(0, 1, 0, 0, 0, 0): 6.236824650204212e-05,
(0, 0, 1, 0, 0, 0): -0.8735669508511756,
(2, 0, 0, 0, 0, 0): -0.02175289363985146,
(1, 1, 0, 0, 0, 0): 0.0006216519365911128,
(0, 2, 0, 0, 0, 0): -0.01816136388762486,
(1, 0, 1, 0, 0, 0): 4.98250160244981,
(0, 1, 1, 0, 0, 0): -3.433275196350619,
(0, 0, 2, 0, 0, 0): -0.3068317210226228,
(0, 0, 0, 1, 0, 0): -0.008568353132214036,
(1, 0, 0, 1, 0, 0): -0.1326576046416237,
(0, 1, 0, 1, 0, 0): -0.022041664895233,
(0, 0, 1, 1, 0, 0): 0.006476353519819268,
(0, 0, 0, 0, 1, 0): 1.681079819633976e-05,
(1, 0, 0, 0, 1, 0): 0.002446570779033474,
(0, 1, 0, 0, 1, 0): -0.003964097683606785,
(0, 0, 1, 0, 1, 0): -0.2990558404622628,
(0, 0, 0, 0, 0, 1): 0.002644736875115787,
(1, 0, 0, 0, 0, 1): 0.3195006077789789,
(0, 1, 0, 0, 0, 1): 0.01417637360982395,
(0, 0, 1, 0, 0, 1): -8.266390090309235,
(0, 0, 0, 2, 0, 0): -0.000318477578825192,
(0, 0, 0, 1, 1, 0): 0.0006338089343829599,
(0, 0, 0, 0, 2, 0): -2.100260411865817e-05,
(0, 0, 0, 1, 0, 1): 0.08468500978301581,
(0, 0, 0, 0, 1, 1): -0.001273455042372849,
(0, 0, 0, 0, 0, 2): 0.02187024559067716},
4: {(0, 0, 0, 0, 0, 0): 1.638462746943122e-06,
(1, 0, 0, 0, 0, 0): 0.01171037411496832,
(0, 1, 0, 0, 0, 0): 0.02987292649363344,
(0, 0, 1, 0, 0, 0): 26.66380299388956,
(2, 0, 0, 0, 0, 0): 0.08655738076016695,
(1, 1, 0, 0, 0, 0): 0.8611700271235128,
(0, 2, 0, 0, 0, 0): 0.1907142190730759,
(1, 0, 1, 0, 0, 0): 92.6265074611843,
(0, 1, 1, 0, 0, 0): 46.04581194178382,
(0, 0, 2, 0, 0, 0): 0.4199128511731608,
(0, 0, 0, 1, 0, 0): -0.8832321468049853,
(1, 0, 0, 1, 0, 0): -0.08265450923645798,
(0, 1, 0, 1, 0, 0): 4.595750293999642,
(0, 0, 1, 1, 0, 0): 0.6089580687522151,
(0, 0, 0, 0, 1, 0): 2.469748204510592e-05,
(1, 0, 0, 0, 1, 0): 0.03644335777673507,
(0, 1, 0, 0, 1, 0): 0.004790250705693585,
(0, 0, 1, 0, 1, 0): -0.7065279857448418,
(0, 0, 0, 0, 0, 1): -0.04048225892111305,
(1, 0, 0, 0, 0, 1): -2.750658609053394,
(0, 1, 0, 0, 0, 1): -8.498292277980854,
(0, 0, 1, 0, 0, 1): -131.3607165929754,
(0, 0, 0, 2, 0, 0): 0.00465181463087483,
(0, 0, 0, 1, 1, 0): 0.2762206065350969,
(0, 0, 0, 0, 2, 0): -1.881444468700011e-05,
(0, 0, 0, 1, 0, 1): 4.503958748148876,
(0, 0, 0, 0, 1, 1): 0.004339229471796604,
(0, 0, 0, 0, 0, 2): 0.1201307256680159},
5: {(0, 0, 0, 0, 0, 0): -0.0003989999996957329,
(1, 0, 0, 0, 0, 0): -0.08867652792838153,
(0, 1, 0, 0, 0, 0): -0.0060974139298439,
(0, 0, 1, 0, 0, 0): 0.03491135055800593,
(2, 0, 0, 0, 0, 0): -4.562310572074815,
(1, 1, 0, 0, 0, 0): -3.199253136275818,
(0, 2, 0, 0, 0, 0): -2.018852785653966,
(1, 0, 1, 0, 0, 0): 6.731394618263752,
(0, 1, 1, 0, 0, 0): -7.671098234423743,
(0, 0, 2, 0, 0, 0): -193.6491267378209,
(0, 0, 0, 1, 0, 0): -0.002683961498230645,
(1, 0, 0, 1, 0, 0): -0.3111725476594368,
(0, 1, 0, 1, 0, 0): -0.03867965342993006,
(0, 0, 1, 1, 0, 0): 7.806587485072856,
(0, 0, 0, 0, 1, 0): 0.9478074334592169,
(1, 0, 0, 0, 1, 0): 0.03660426790726292,
(0, 1, 0, 0, 1, 0): 0.009668916318218654,
(0, 0, 1, 0, 1, 0): -0.04207167516739369,
(0, 0, 0, 0, 0, 1): -8.79504552651686,
(1, 0, 0, 0, 0, 1): 1.247415204702234,
(0, 1, 0, 0, 0, 1): 5.21545854181059,
(0, 0, 1, 0, 0, 1): 1.118983761140667,
(0, 0, 0, 2, 0, 0): -0.01147188399590403,
(0, 0, 0, 1, 1, 0): 0.001855929904472773,
(0, 0, 0, 0, 2, 0): -0.0003162411406177675,
(0, 0, 0, 1, 0, 1): -0.007711291020986367,
(0, 0, 0, 0, 1, 1): 0.01251135551340499,
(0, 0, 0, 0, 0, 2): 0.3558855869528053},
6: {(0, 0, 0, 0, 0, 0): -7.161356684919204e-06,
(1, 0, 0, 0, 0, 0): 0.005312693710729154,
(0, 1, 0, 0, 0, 0): -0.0003111437363593986,
(0, 0, 1, 0, 0, 0): 0.0001061871025308821,
(2, 0, 0, 0, 0, 0): -0.009832852271567457,
(1, 1, 0, 0, 0, 0): -0.1761916427431588,
(0, 2, 0, 0, 0, 0): -0.02762664933806441,
(1, 0, 1, 0, 0, 0): -0.01700297270538415,
(0, 1, 1, 0, 0, 0): 0.005292022698513504,
(0, 0, 2, 0, 0, 0): 2.022148323469748,
(0, 0, 0, 1, 0, 0): -1.591752459232057e-05,
(1, 0, 0, 1, 0, 0): -0.001643678893776031,
(0, 1, 0, 1, 0, 0): -0.004086218626750979,
(0, 0, 1, 1, 0, 0): -0.1557737221334306,
(0, 0, 0, 0, 1, 0): 0.01159978927421549,
(1, 0, 0, 0, 1, 0): -0.0002319831440521575,
(0, 1, 0, 0, 1, 0): 0.001427045950811164,
(0, 0, 1, 0, 1, 0): 0.0001355695021803557,
(0, 0, 0, 0, 0, 1): 0.9473650230829532,
(1, 0, 0, 0, 0, 1): -0.05628494800756738,
(0, 1, 0, 0, 0, 1): 0.01321862585357653,
(0, 0, 1, 0, 0, 1): 0.002961222009110281,
(0, 0, 0, 2, 0, 0): -0.0008898360924138965,
(0, 0, 0, 1, 1, 0): -1.099686851049882e-07,
(0, 0, 0, 0, 2, 0): 4.41302026623815e-06,
(0, 0, 0, 1, 0, 1): -0.00200391228023326,
(0, 0, 0, 0, 1, 1): 0.0009038212121290096,
(0, 0, 0, 0, 0, 2): 0.009574786794414147}}
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.9853518809950229), -0.9851968585153759)
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.194467998829055), 0.1951380196591954)
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!