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/python_test/cesr/tao.init -noplot')
tao=Tao('-init $ACC_ROOT_DIR/regression_tests/python_test/cesr/tao.init -noplot')
derivative¶
In [3]:
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 [4]:
Copied!
result = tao.derivative()
result
result = tao.derivative()
result
Out[4]:
{1: array([[-0.01758468, -0.03303896, 0.00216133], [-0.01711307, -0.03578883, 0.00283783], [ 0.00189157, -0.00956715, 0.002403 ], [-0.00893899, 0.00192382, 0.00267012]])}
n_datums x n_variables
In [5]:
Copied!
result[1].shape
result[1].shape
Out[5]:
(4, 3)
ele_control_var¶
In [6]:
Copied!
tao.ele_control_var('H01W')
tao.ele_control_var('H01W')
Out[6]:
{'HKICK': 0.0}
lat_ele_list¶
In [7]:
Copied!
result = tao.lat_ele_list()
result[0:5]
result = tao.lat_ele_list()
result[0:5]
Out[7]:
['BEGINNING', 'IP_L0', 'CLEO_SOL#3', 'DET_00W', 'CLEO_SOL#4']
matrix¶
In [8]:
Copied!
tao.matrix('beginning', 'end')
tao.matrix('beginning', 'end')
Out[8]:
{'mat6': array([[-9.85453321e-01, -1.78459151e-01, -2.95064264e-02, -3.72328920e-05, -1.28463592e-03, 1.69891481e-03], [ 1.94136498e-01, -9.79571649e-01, -7.19934556e-03, 8.91976973e-04, -5.89572298e-03, -3.81443391e-02], [-8.56326179e-04, 6.02559417e-05, -8.76189776e-01, -8.41353620e-03, 1.67854914e-05, 2.64910024e-03], [ 1.16108945e-02, 2.96794811e-02, 2.66272919e+01, -8.85649651e-01, 2.27202186e-05, -4.04349281e-02], [-8.86152432e-02, -6.13453812e-03, 3.48586755e-02, -2.68733712e-03, 9.47817598e-01, -8.79515336e+00], [ 5.30821801e-03, -2.93203403e-04, 1.07833933e-04, -1.59653540e-05, 1.15997844e-02, 9.47355103e-01]]), 'vec0': array([ 3.92874185e-04, 4.73093997e-03, 1.86151032e-06, -9.57458177e-05, -7.06703195e-05, 5.03940861e-06])}
merit¶
In [9]:
Copied!
tao.merit()
tao.merit()
Out[9]:
411.826621947845
plot_list¶
In [10]:
Copied!
result = tao.plot_list('r')
result[0:2]
result = tao.plot_list('r')
result[0:2]
Out[10]:
[{'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 [11]:
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[11]:
5
spin_invariant¶
In [12]:
Copied!
tao.spin_invariant('l0')
tao.spin_invariant('l0')
Out[12]:
array([[ 0. , 0.99835693, 0.05730134], [ 0. , 0.99835693, 0.05730134], [-0.05286846, 0.99704202, 0.05578657], ..., [-0.24326432, 0.96860132, 0.05132215], [-0.29421324, 0.95443762, 0.04987387], [-0.29421324, 0.95443762, 0.04987387]])
taylor_map¶
In [13]:
Copied!
tt = tao.taylor_map('beginning', 'end', order=2)
tt
tt = tao.taylor_map('beginning', 'end', order=2)
tt
Out[13]:
{1: {(0, 0, 0, 0, 0, 0): -1.66366332601307e-05, (1, 0, 0, 0, 0, 0): -0.985196712119849, (0, 1, 0, 0, 0, 0): -0.17994354147886, (0, 0, 1, 0, 0, 0): -0.0296993930624785, (2, 0, 0, 0, 0, 0): 0.446035109687681, (1, 1, 0, 0, 0, 0): -1.00830805320129, (0, 2, 0, 0, 0, 0): 1.02618260820533, (1, 0, 1, 0, 0, 0): -0.826518069338921, (0, 1, 1, 0, 0, 0): 0.667384351613117, (0, 0, 2, 0, 0, 0): 44.7241374657912, (0, 0, 0, 1, 0, 0): -3.89707865939949e-05, (1, 0, 0, 1, 0, 0): -0.00123738942379549, (0, 1, 0, 1, 0, 0): -0.0371117229911406, (0, 0, 1, 1, 0, 0): -4.03450589552225, (0, 0, 0, 0, 1, 0): -0.00131163342298458, (1, 0, 0, 0, 1, 0): -0.149522830215827, (0, 1, 0, 0, 1, 0): 0.02993312487446, (0, 0, 1, 0, 1, 0): 0.10580743725882, (0, 0, 0, 0, 0, 1): 0.00175860484437048, (1, 0, 0, 0, 0, 1): 2.90301787044488, (0, 1, 0, 0, 0, 1): 3.49577156783013, (0, 0, 1, 0, 0, 1): 7.97083243963905, (0, 0, 0, 2, 0, 0): -0.0184811091788232, (0, 0, 0, 1, 1, 0): -0.00392766892829161, (0, 0, 0, 0, 2, 0): 0.000742822949788133, (0, 0, 0, 1, 0, 1): 0.0279423458347018, (0, 0, 0, 0, 1, 1): -0.0134035018484371, (0, 0, 0, 0, 0, 2): -2.38971849234666}, 2: {(0, 0, 0, 0, 0, 0): 0.00239048642780657, (1, 0, 0, 0, 0, 0): 0.195138002251368, (0, 1, 0, 0, 0, 0): -0.979350347597212, (0, 0, 1, 0, 0, 0): -0.00732021294637251, (2, 0, 0, 0, 0, 0): 1.32496482271115, (1, 1, 0, 0, 0, 0): -0.169051815247669, (0, 2, 0, 0, 0, 0): 0.295757362731708, (1, 0, 1, 0, 0, 0): -0.962174031407233, (0, 1, 1, 0, 0, 0): 0.697972279522991, (0, 0, 2, 0, 0, 0): 100.484273138117, (0, 0, 0, 1, 0, 0): 0.000900228227228298, (1, 0, 0, 1, 0, 0): 0.0452519741325243, (0, 1, 0, 1, 0, 0): 0.00972378758918665, (0, 0, 1, 1, 0, 0): -2.89154417462971, (0, 0, 0, 0, 1, 0): -0.0058956031428734, (1, 0, 0, 0, 1, 0): -0.0608684910749376, (0, 1, 0, 0, 1, 0): 0.131509485895043, (0, 0, 1, 0, 1, 0): 0.0812501958421715, (0, 0, 0, 0, 0, 1): -0.0381872457523367, (1, 0, 0, 0, 0, 1): -9.55211746743359, (0, 1, 0, 0, 0, 1): -5.33584430615958, (0, 0, 1, 0, 0, 1): 4.52923484817316, (0, 0, 0, 2, 0, 0): 0.0629079369885579, (0, 0, 0, 1, 1, 0): -0.00149863574209327, (0, 0, 0, 0, 2, 0): 0.00058798667411987, (0, 0, 0, 1, 0, 1): -0.318535795672364, (0, 0, 0, 0, 1, 1): 0.0412940351778409, (0, 0, 0, 0, 0, 2): 0.76601997278978}, 3: {(0, 0, 0, 0, 0, 0): 1.0515763216609e-06, (1, 0, 0, 0, 0, 0): -0.000864193360451855, (0, 1, 0, 0, 0, 0): 6.23497459210984e-05, (0, 0, 1, 0, 0, 0): -0.873566454499895, (2, 0, 0, 0, 0, 0): -0.0217550808042083, (1, 1, 0, 0, 0, 0): 0.000630927291902906, (0, 2, 0, 0, 0, 0): -0.0181604780847751, (1, 0, 1, 0, 0, 0): 4.98227513200016, (0, 1, 1, 0, 0, 0): -3.4333038464796, (0, 0, 2, 0, 0, 0): -0.305561099314914, (0, 0, 0, 1, 0, 0): -0.00856834872273157, (1, 0, 0, 1, 0, 0): -0.132656652388745, (0, 1, 0, 1, 0, 0): -0.0220531119498717, (0, 0, 1, 1, 0, 0): 0.00641085056761062, (0, 0, 0, 0, 1, 0): 1.68093509078226e-05, (1, 0, 0, 0, 1, 0): 0.00244665753480257, (0, 1, 0, 0, 1, 0): -0.00396412754254092, (0, 0, 1, 0, 1, 0): -0.299055160952994, (0, 0, 0, 0, 0, 1): 0.00264467550352783, (1, 0, 0, 0, 0, 1): 0.319510758049708, (0, 1, 0, 0, 0, 1): 0.0141711170025867, (0, 0, 1, 0, 0, 1): -8.26626634426424, (0, 0, 0, 2, 0, 0): -0.000318155048226441, (0, 0, 0, 1, 1, 0): 0.000633772506825134, (0, 0, 0, 0, 2, 0): -2.10025886123832e-05, (0, 0, 0, 1, 0, 1): 0.0846818379830365, (0, 0, 0, 0, 1, 1): -0.00127341198186583, (0, 0, 0, 0, 0, 2): 0.0218742125374431}, 4: {(0, 0, 0, 0, 0, 0): 1.82087247131977e-06, (1, 0, 0, 0, 0, 0): 0.0117108773369882, (0, 1, 0, 0, 0, 0): 0.0298731605797835, (0, 0, 1, 0, 0, 0): 26.6637945906609, (2, 0, 0, 0, 0, 0): 0.0868221858129598, (1, 1, 0, 0, 0, 0): 0.86103567651534, (0, 2, 0, 0, 0, 0): 0.190824016565316, (1, 0, 1, 0, 0, 0): 92.6293355303031, (0, 1, 1, 0, 0, 0): 46.0396584639104, (0, 0, 2, 0, 0, 0): 0.449570890860524, (0, 0, 0, 1, 0, 0): -0.883232864347685, (1, 0, 0, 1, 0, 0): -0.0824329630587235, (0, 1, 0, 1, 0, 0): 4.59607349167949, (0, 0, 1, 1, 0, 0): 0.608976435276033, (0, 0, 0, 0, 1, 0): 2.4691454598523e-05, (1, 0, 0, 0, 1, 0): 0.0364417756743412, (0, 1, 0, 0, 1, 0): 0.00478844201012632, (0, 0, 1, 0, 1, 0): -0.706485568151731, (0, 0, 0, 0, 0, 1): -0.0404817456350846, (1, 0, 0, 0, 0, 1): -2.75082965585596, (0, 1, 0, 0, 0, 1): -8.49871795108685, (0, 0, 1, 0, 0, 1): -131.350468959094, (0, 0, 0, 2, 0, 0): 0.00467518361799328, (0, 0, 0, 1, 1, 0): 0.276221869149317, (0, 0, 0, 0, 2, 0): -1.88223554340163e-05, (0, 0, 0, 1, 0, 1): 4.50404232758137, (0, 0, 0, 0, 1, 1): 0.00433745591028218, (0, 0, 0, 0, 0, 2): 0.120062611084724}, 5: {(0, 0, 0, 0, 0, 0): -0.000398882588691682, (1, 0, 0, 0, 0, 0): -0.0886757830666738, (0, 1, 0, 0, 0, 0): -0.00609684852614364, (0, 0, 1, 0, 0, 0): 0.0349098899729758, (2, 0, 0, 0, 0, 0): -4.48468034439034, (1, 1, 0, 0, 0, 0): -3.30120883823249, (0, 2, 0, 0, 0, 0): -1.98549498347646, (1, 0, 1, 0, 0, 0): 6.72277540400784, (0, 1, 1, 0, 0, 0): -7.6659184728811, (0, 0, 2, 0, 0, 0): -193.642502871923, (0, 0, 0, 1, 0, 0): -0.00268389910630068, (1, 0, 0, 1, 0, 0): -0.311160697510315, (0, 1, 0, 1, 0, 0): -0.0386927423048583, (0, 0, 1, 1, 0, 0): 7.80657907173444, (0, 0, 0, 0, 1, 0): 0.947807430858377, (1, 0, 0, 0, 1, 0): 0.0359634388474073, (0, 1, 0, 0, 1, 0): 0.0100891161863174, (0, 0, 1, 0, 1, 0): -0.0420357368238885, (0, 0, 0, 0, 0, 1): -8.79504643341939, (1, 0, 0, 0, 0, 1): 1.19998827069517, (0, 1, 0, 0, 0, 1): 5.24649885594377, (0, 0, 1, 0, 0, 1): 1.12180295443156, (0, 0, 0, 2, 0, 0): -0.0114705862748437, (0, 0, 0, 1, 1, 0): 0.00185577416561418, (0, 0, 0, 0, 2, 0): -0.000314559544069885, (0, 0, 0, 1, 0, 1): -0.00772619373441908, (0, 0, 0, 0, 1, 1): 0.0127061989949057, (0, 0, 0, 0, 0, 2): 0.363109905501546}, 6: {(0, 0, 0, 0, 0, 0): -7.15739820507555e-06, (1, 0, 0, 0, 0, 0): 0.00531272384962832, (0, 1, 0, 0, 0, 0): -0.000311134175372412, (0, 0, 1, 0, 0, 0): 0.000106214706401075, (2, 0, 0, 0, 0, 0): -0.00937029754594035, (1, 1, 0, 0, 0, 0): -0.176799150721886, (0, 2, 0, 0, 0, 0): -0.0274281220955725, (1, 0, 1, 0, 0, 0): -0.0170533551050314, (0, 1, 1, 0, 0, 0): 0.00532375315763478, (0, 0, 2, 0, 0, 0): 2.02217604187271, (0, 0, 0, 1, 0, 0): -1.59179292590083e-05, (1, 0, 0, 1, 0, 0): -0.00164363452912023, (0, 1, 0, 1, 0, 0): -0.00408630327838242, (0, 0, 1, 1, 0, 0): -0.155773826394074, (0, 0, 0, 0, 1, 0): 0.0115997890362465, (1, 0, 0, 0, 1, 0): -0.000235880823383565, (0, 1, 0, 0, 1, 0): 0.0014295594515164, (0, 0, 1, 0, 1, 0): 0.000135769683986905, (0, 0, 0, 0, 0, 1): 0.947365020986965, (1, 0, 0, 0, 0, 1): -0.0565675845483893, (0, 1, 0, 0, 0, 1): 0.0134028384613013, (0, 0, 1, 0, 0, 1): 0.00297581839887475, (0, 0, 0, 2, 0, 0): -0.000889800662803543, (0, 0, 0, 1, 1, 0): -1.10193760593274e-07, (0, 0, 0, 0, 2, 0): 4.34007834305251e-06, (0, 0, 0, 1, 0, 1): -0.00200399470489132, (0, 0, 0, 0, 1, 1): 0.00090575945041951, (0, 0, 0, 0, 0, 2): 0.00961450164308911}}
In [14]:
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[14]:
(-0.98545332129361, -0.985196712119849)
In [15]:
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[15]:
(0.194136497705356, 0.195138002251368)
var_v_array¶
In [16]:
Copied!
result = tao.var_v_array('quad_k1')
result[0:2]
result = tao.var_v_array('quad_k1')
result[0:2]
Out[16]:
[{'ix_v1': 0, 'var_attrib_name': 'Q00W[K1]', 'meas_value': 0.0, 'model_value': -0.841784836453016, 'design_value': -0.841784836453016, '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}]