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.00909995345022881, 'design_value': -0.00909995345022881, '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([[-0.01758468, -0.03303895, 0.00216133], [-0.01711307, -0.03578881, 0.00283783], [ 0.00189157, -0.00956714, 0.002403 ], [-0.00893899, 0.00192383, 0.00267012]])}
n_datums x n_variables
In [6]:
Copied!
result[1].shape
result[1].shape
Out[6]:
(4, 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']
matrix¶
In [9]:
Copied!
tao.matrix("beginning", "end")
tao.matrix("beginning", "end")
Out[9]:
{'mat6': array([[-9.85453321e-01, -1.78459151e-01, -2.95064264e-02, -3.72328912e-05, -1.28463592e-03, 1.69890832e-03], [ 1.94136498e-01, -9.79571649e-01, -7.19934541e-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 [10]:
Copied!
tao.merit()
tao.merit()
Out[10]:
411.826621947948
plot_list¶
In [11]:
Copied!
result = tao.plot_list("r")
result[0:2]
result = tao.plot_list("r")
result[0:2]
Out[11]:
[{'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 [12]:
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[12]:
5
spin_invariant¶
In [13]:
Copied!
tao.spin_invariant("l0")
tao.spin_invariant("l0")
Out[13]:
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 [14]:
Copied!
tt = tao.taylor_map("beginning", "end", order=2)
tt
tt = tao.taylor_map("beginning", "end", order=2)
tt
Out[14]:
{1: {(0, 0, 0, 0, 0, 0): -1.66366331935176e-05, (1, 0, 0, 0, 0, 0): -0.985196712004978, (0, 1, 0, 0, 0, 0): -0.179943541553879, (0, 0, 1, 0, 0, 0): -0.0296993930689338, (2, 0, 0, 0, 0, 0): 0.446108376360043, (1, 1, 0, 0, 0, 0): -1.00840412690811, (0, 2, 0, 0, 0, 0): 1.02621408598452, (1, 0, 1, 0, 0, 0): -0.826526310689417, (0, 1, 1, 0, 0, 0): 0.66738975238496, (0, 0, 2, 0, 0, 0): 44.7241376522403, (0, 0, 0, 1, 0, 0): -3.8970786579565e-05, (1, 0, 0, 1, 0, 0): -0.00123736887685912, (0, 1, 0, 1, 0, 0): -0.037111736450792, (0, 0, 1, 1, 0, 0): -4.03450589559728, (0, 0, 0, 0, 1, 0): -0.00131163342342555, (1, 0, 0, 0, 1, 0): -0.149523435209748, (0, 1, 0, 0, 1, 0): 0.0299335213222391, (0, 0, 1, 0, 1, 0): 0.105807471287395, (0, 0, 0, 0, 0, 1): 0.00175860481206504, (1, 0, 0, 0, 0, 1): 2.90297313273057, (0, 1, 0, 0, 0, 1): 3.49580088045975, (0, 0, 1, 0, 0, 1): 7.97083495391285, (0, 0, 0, 2, 0, 0): -0.0184811091774087, (0, 0, 0, 1, 1, 0): -0.00392766901308479, (0, 0, 0, 0, 2, 0): 0.000742824197924029, (0, 0, 0, 1, 0, 1): 0.0279423395134347, (0, 0, 0, 0, 1, 1): -0.0134033172010638, (0, 0, 0, 0, 0, 2): -2.38971166203837}, 2: {(0, 0, 0, 0, 0, 0): 0.00239048642773681, (1, 0, 0, 0, 0, 0): 0.195138002493118, (0, 1, 0, 0, 0, 0): -0.979350347755823, (0, 0, 1, 0, 0, 0): -0.00732021296016823, (2, 0, 0, 0, 0, 0): 1.32511843855489, (1, 1, 0, 0, 0, 0): -0.169253235386875, (0, 2, 0, 0, 0, 0): 0.295823351810883, (1, 0, 1, 0, 0, 0): -0.962191303413663, (0, 1, 1, 0, 0, 0): 0.697983597586343, (0, 0, 2, 0, 0, 0): 100.484273524397, (0, 0, 0, 1, 0, 0): 0.000900228227261182, (1, 0, 0, 1, 0, 0): 0.0452520169954341, (0, 1, 0, 1, 0, 0): 0.0097237595133609, (0, 0, 1, 1, 0, 0): -2.89154417467537, (0, 0, 0, 0, 1, 0): -0.005895603143855, (1, 0, 0, 0, 1, 0): -0.0608697594082146, (0, 1, 0, 0, 1, 0): 0.131510316963394, (0, 0, 1, 0, 1, 0): 0.0812502671502623, (0, 0, 0, 0, 0, 1): -0.038187245824526, (1, 0, 0, 0, 0, 1): -9.55221126615965, (0, 1, 0, 0, 0, 1): -5.33578285297173, (0, 0, 1, 0, 0, 1): 4.52924011737334, (0, 0, 0, 2, 0, 0): 0.0629079369977707, (0, 0, 0, 1, 1, 0): -0.0014986359189501, (0, 0, 0, 0, 2, 0): 0.000587989290476936, (0, 0, 0, 1, 0, 1): -0.318535808858965, (0, 0, 0, 0, 1, 1): 0.0412944222742314, (0, 0, 0, 0, 0, 2): 0.766034293311184}, 3: {(0, 0, 0, 0, 0, 0): 1.0515763215525e-06, (1, 0, 0, 0, 0, 0): -0.000864193360888606, (0, 1, 0, 0, 0, 0): 6.23497462052501e-05, (0, 0, 1, 0, 0, 0): -0.873566454497795, (2, 0, 0, 0, 0, 0): -0.0217553558075661, (1, 1, 0, 0, 0, 0): 0.000631287940430662, (0, 2, 0, 0, 0, 0): -0.0181605962615151, (1, 0, 1, 0, 0, 0): 4.98227518044368, (0, 1, 1, 0, 0, 0): -3.43330387827155, (0, 0, 2, 0, 0, 0): -0.305561100969401, (0, 0, 0, 1, 0, 0): -0.00856834872271459, (1, 0, 0, 1, 0, 0): -0.132656653072126, (0, 1, 0, 1, 0, 0): -0.0220531115086416, (0, 0, 1, 1, 0, 0): 0.00641085060252567, (0, 0, 0, 0, 1, 0): 1.68093509091971e-05, (1, 0, 0, 0, 1, 0): 0.00244665980642929, (0, 1, 0, 0, 1, 0): -0.00396412903128415, (0, 0, 1, 0, 1, 0): -0.299055161154543, (0, 0, 0, 0, 0, 1): 0.00264467550362422, (1, 0, 0, 0, 0, 1): 0.319510925969635, (0, 1, 0, 0, 0, 1): 0.0141710069668825, (0, 0, 1, 0, 0, 1): -8.26626635917965, (0, 0, 0, 2, 0, 0): -0.000318155048313442, (0, 0, 0, 1, 1, 0): 0.000633772509646714, (0, 0, 0, 0, 2, 0): -2.10025933004997e-05, (0, 0, 0, 1, 0, 1): 0.0846818381893599, (0, 0, 0, 0, 1, 1): -0.00127341267516617, (0, 0, 0, 0, 0, 2): 0.0218741869008492}, 4: {(0, 0, 0, 0, 0, 0): 1.82087246910577e-06, (1, 0, 0, 0, 0, 0): 0.0117108773262394, (0, 1, 0, 0, 0, 0): 0.0298731605867765, (0, 0, 1, 0, 0, 0): 26.6637945907346, (2, 0, 0, 0, 0, 0): 0.0868154212323665, (1, 1, 0, 0, 0, 0): 0.861044547172263, (0, 2, 0, 0, 0, 0): 0.190821110096209, (1, 0, 1, 0, 0, 0): 92.6293368528103, (0, 1, 1, 0, 0, 0): 46.0396575980066, (0, 0, 2, 0, 0, 0): 0.449570842655751, (0, 0, 0, 1, 0, 0): -0.883232864349573, (1, 0, 0, 1, 0, 0): -0.0824329586467389, (0, 1, 0, 1, 0, 0): 4.59607348905793, (0, 0, 1, 1, 0, 0): 0.60897643502805, (0, 0, 0, 0, 1, 0): 2.46914546389749e-05, (1, 0, 0, 0, 1, 0): 0.0364418315318748, (0, 1, 0, 0, 1, 0): 0.00478840540608626, (0, 0, 1, 0, 1, 0): -0.706485573601523, (0, 0, 0, 0, 0, 1): -0.0404817456322482, (1, 0, 0, 0, 0, 1): -2.75082552578488, (0, 1, 0, 0, 0, 1): -8.49872065727191, (0, 0, 1, 0, 0, 1): -131.350469361068, (0, 0, 0, 2, 0, 0): 0.00467518361903948, (0, 0, 0, 1, 1, 0): 0.276221869133946, (0, 0, 0, 0, 2, 0): -1.88224706689664e-05, (0, 0, 0, 1, 0, 1): 4.50404232648761, (0, 0, 0, 0, 1, 1): 0.00433743886438137, (0, 0, 0, 0, 0, 2): 0.120061980604865}, 5: {(0, 0, 0, 0, 0, 0): -0.000398882588661428, (1, 0, 0, 0, 0, 0): -0.0886758653273395, (0, 1, 0, 0, 0, 0): -0.0060967948123514, (0, 0, 1, 0, 0, 0): 0.0349098945733697, (2, 0, 0, 0, 0, 0): -4.53639223085315, (1, 1, 0, 0, 0, 0): -3.2334051439405, (0, 2, 0, 0, 0, 0): -2.00770854973623, (1, 0, 1, 0, 0, 0): 6.72858859764847, (0, 1, 1, 0, 0, 0): -7.66972772273577, (0, 0, 2, 0, 0, 0): -193.642632680539, (0, 0, 0, 1, 0, 0): -0.00268389911768967, (1, 0, 0, 1, 0, 0): -0.311175087335103, (0, 1, 0, 1, 0, 0): -0.0386833165335798, (0, 0, 1, 1, 0, 0): 7.80657911683649, (0, 0, 0, 0, 1, 0): 0.947807431197128, (1, 0, 0, 0, 1, 0): 0.0363903902713366, (0, 1, 0, 0, 1, 0): 0.00980936090295559, (0, 0, 1, 0, 1, 0): -0.0420597362133058, (0, 0, 0, 0, 0, 1): -8.79504640834357, (1, 0, 0, 0, 0, 1): 1.2315638580293, (0, 1, 0, 0, 0, 1): 5.22581195573426, (0, 0, 1, 0, 0, 1): 1.12002951921809, (0, 0, 0, 2, 0, 0): -0.0114705886603623, (0, 0, 0, 1, 1, 0): 0.00185583353730949, (0, 0, 0, 0, 2, 0): -0.000315440257262236, (0, 0, 0, 1, 0, 1): -0.00772176644266498, (0, 0, 0, 0, 1, 1): 0.0125758928191825, (0, 0, 0, 0, 0, 2): 0.358289157829607}, 6: {(0, 0, 0, 0, 0, 0): -7.15739821666171e-06, (1, 0, 0, 0, 0, 0): 0.00531272335951633, (0, 1, 0, 0, 0, 0): -0.000311133855338647, (0, 0, 1, 0, 0, 0): 0.00010621473381561, (2, 0, 0, 0, 0, 0): -0.00967837592758609, (1, 1, 0, 0, 0, 0): -0.176395203912931, (0, 2, 0, 0, 0, 0): -0.0275604615086023, (1, 0, 1, 0, 0, 0): -0.0170187224784856, (0, 1, 1, 0, 0, 0): 0.00530105920106155, (0, 0, 2, 0, 0, 0): 2.02217526853222, (0, 0, 0, 1, 0, 0): -1.59179293270388e-05, (1, 0, 0, 1, 0, 0): -0.00164372025748337, (0, 1, 0, 1, 0, 0): -0.00408624712371079, (0, 0, 1, 1, 0, 0): -0.155773826126224, (0, 0, 0, 0, 1, 0): 0.0115997890382654, (1, 0, 0, 0, 1, 0): -0.000233337216477128, (0, 1, 0, 0, 1, 0): 0.00142789278074805, (0, 0, 1, 0, 1, 0): 0.000135626705220613, (0, 0, 0, 0, 0, 1): 0.947365021136244, (1, 0, 0, 0, 0, 1): -0.0563794701399377, (0, 1, 0, 0, 0, 1): 0.013279594421484, (0, 0, 1, 0, 0, 1): 0.00296525300489641, (0, 0, 0, 2, 0, 0): -0.000889800676997357, (0, 0, 0, 1, 1, 0): -1.09840049095265e-07, (0, 0, 0, 0, 2, 0): 4.33483140832018e-06, (0, 0, 0, 1, 0, 1): -0.00200396832898983, (0, 0, 0, 0, 1, 1): 0.000904983137930894, (0, 0, 0, 0, 0, 2): 0.0095857815977119}}
In [15]:
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[15]:
(np.float64(-0.985453321293568), -0.985196712004978)
In [16]:
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[16]:
(np.float64(0.194136497704561), 0.195138002493118)
var_v_array¶
In [17]:
Copied!
result = tao.var_v_array("quad_k1")
result[0:2]
result = tao.var_v_array("quad_k1")
result[0:2]
Out[17]:
[{'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}]