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.00909995345022595, 'design_value': -0.00909995345022595, '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.826621947715
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.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]], 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.66366331513616e-05, (1, 0, 0, 0, 0, 0): -0.985196712063462, (0, 1, 0, 0, 0, 0): -0.179943541514639, (0, 0, 1, 0, 0, 0): -0.0296993930654002, (2, 0, 0, 0, 0, 0): 0.446080050090303, (1, 1, 0, 0, 0, 0): -1.00836695259332, (0, 2, 0, 0, 0, 0): 1.02620192427102, (1, 0, 1, 0, 0, 0): -0.826523119675318, (0, 1, 1, 0, 0, 0): 0.667387662894315, (0, 0, 2, 0, 0, 0): 44.7241375817543, (0, 0, 0, 1, 0, 0): -3.89707865943925e-05, (1, 0, 0, 1, 0, 0): -0.00123737685395045, (0, 1, 0, 1, 0, 0): -0.0371117312272826, (0, 0, 1, 1, 0, 0): -4.03450589582711, (0, 0, 0, 0, 1, 0): -0.00131163342312113, (1, 0, 0, 0, 1, 0): -0.149523202418056, (0, 1, 0, 0, 1, 0): 0.0299333690663621, (0, 0, 1, 0, 1, 0): 0.105807458185848, (0, 0, 0, 0, 0, 1): 0.00175860482975318, (1, 0, 0, 0, 0, 1): 2.90299023064608, (0, 1, 0, 0, 0, 1): 3.49578967445221, (0, 0, 1, 0, 0, 1): 7.97083399050265, (0, 0, 0, 2, 0, 0): -0.0184811091716994, (0, 0, 0, 1, 1, 0): -0.00392766898036096, (0, 0, 0, 0, 2, 0): 0.000742823719939607, (0, 0, 0, 1, 0, 1): 0.027942341946275, (0, 0, 0, 0, 1, 1): -0.013403387431672, (0, 0, 0, 0, 0, 2): -2.3897142470397}, 2: {(0, 0, 0, 0, 0, 0): 0.00239048642741783, (1, 0, 0, 0, 0, 0): 0.195138002368737, (0, 1, 0, 0, 0, 0): -0.979350347675676, (0, 0, 1, 0, 0, 0): -0.00732021295331954, (2, 0, 0, 0, 0, 0): 1.32505904937663, (1, 1, 0, 0, 0, 0): -0.16917530272479, (0, 2, 0, 0, 0, 0): 0.295797858306266, (1, 0, 1, 0, 0, 0): -0.9621846169196, (0, 1, 1, 0, 0, 0): 0.697979219698901, (0, 0, 2, 0, 0, 0): 100.484273383402, (0, 0, 0, 1, 0, 0): 0.000900228227237402, (1, 0, 0, 1, 0, 0): 0.0452520003837472, (0, 1, 0, 1, 0, 0): 0.00972377038641729, (0, 0, 1, 1, 0, 0): -2.89154417505193, (0, 0, 0, 0, 1, 0): -0.00589560314331813, (1, 0, 0, 0, 1, 0): -0.0608692714055395, (0, 1, 0, 0, 1, 0): 0.13150999781938, (0, 0, 1, 0, 1, 0): 0.0812502397012824, (0, 0, 0, 0, 0, 1): -0.0381872457865, (1, 0, 0, 0, 0, 1): -9.55217541917287, (0, 1, 0, 0, 0, 1): -5.33580634477532, (0, 0, 1, 0, 0, 1): 4.52923809862092, (0, 0, 0, 2, 0, 0): 0.0629079369975813, (0, 0, 0, 1, 1, 0): -0.00149863585082065, (0, 0, 0, 0, 2, 0): 0.000587988288617591, (0, 0, 0, 1, 0, 1): -0.31853580379055, (0, 0, 0, 0, 1, 1): 0.0412942750523069, (0, 0, 0, 0, 0, 2): 0.766028873757409}, 3: {(0, 0, 0, 0, 0, 0): 1.05157632157417e-06, (1, 0, 0, 0, 0, 0): -0.00086419336065796, (0, 1, 0, 0, 0, 0): 6.23497460537194e-05, (0, 0, 1, 0, 0, 0): -0.87356645449675, (2, 0, 0, 0, 0, 0): -0.021755249471304, (1, 1, 0, 0, 0, 0): 0.000631148367596489, (0, 2, 0, 0, 0, 0): -0.018160550592342, (1, 0, 1, 0, 0, 0): 4.98227515955175, (0, 1, 1, 0, 0, 0): -3.43330386460876, (0, 0, 2, 0, 0, 0): -0.30556110020581, (0, 0, 0, 1, 0, 0): -0.00856834872266093, (1, 0, 0, 1, 0, 0): -0.13265665274315, (0, 1, 0, 1, 0, 0): -0.022053111716497, (0, 0, 1, 1, 0, 0): 0.00641085058440853, (0, 0, 0, 0, 1, 0): 1.68093509068441e-05, (1, 0, 0, 0, 1, 0): 0.00244665893212093, (0, 1, 0, 0, 1, 0): -0.00396412845935878, (0, 0, 1, 0, 1, 0): -0.299055161067021, (0, 0, 0, 0, 0, 1): 0.00264467550344091, (1, 0, 0, 0, 0, 1): 0.319510861785281, (0, 1, 0, 0, 0, 1): 0.0141710490387243, (0, 0, 1, 0, 0, 1): -8.26626635263824, (0, 0, 0, 2, 0, 0): -0.000318155048246411, (0, 0, 0, 1, 1, 0): 0.000633772508382399, (0, 0, 0, 0, 2, 0): -2.10025915044401e-05, (0, 0, 0, 1, 0, 1): 0.0846818380963362, (0, 0, 0, 0, 1, 1): -0.0012734124114067, (0, 0, 0, 0, 0, 2): 0.0218741966043404}, 4: {(0, 0, 0, 0, 0, 0): 1.82087246780485e-06, (1, 0, 0, 0, 0, 0): 0.0117108773313685, (0, 1, 0, 0, 0, 0): 0.0298731605832433, (0, 0, 1, 0, 0, 0): 26.6637945907032, (2, 0, 0, 0, 0, 0): 0.0868180364409341, (1, 1, 0, 0, 0, 0): 0.861041114891274, (0, 2, 0, 0, 0, 0): 0.190822233002678, (1, 0, 1, 0, 0, 0): 92.629336261943, (0, 1, 1, 0, 0, 0): 46.0396579855868, (0, 0, 2, 0, 0, 0): 0.449570865988373, (0, 0, 0, 1, 0, 0): -0.883232864352547, (1, 0, 0, 1, 0, 0): -0.0824329609598552, (0, 1, 0, 1, 0, 0): 4.59607349036302, (0, 0, 1, 1, 0, 0): 0.608976435163437, (0, 0, 0, 0, 1, 0): 2.46914546163545e-05, (1, 0, 0, 0, 1, 0): 0.0364418100396165, (0, 1, 0, 0, 1, 0): 0.00478841946322139, (0, 0, 1, 0, 1, 0): -0.706485571312896, (0, 0, 0, 0, 0, 1): -0.0404817456332349, (1, 0, 0, 0, 0, 1): -2.75082710411505, (0, 1, 0, 0, 0, 1): -8.49871962280396, (0, 0, 1, 0, 0, 1): -131.350469207711, (0, 0, 0, 2, 0, 0): 0.00467518361805221, (0, 0, 0, 1, 1, 0): 0.276221869139032, (0, 0, 0, 0, 2, 0): -1.88224265409972e-05, (0, 0, 0, 1, 0, 1): 4.50404232654304, (0, 0, 0, 0, 1, 1): 0.00433744534749753, (0, 0, 0, 0, 0, 2): 0.120062219227653}, 5: {(0, 0, 0, 0, 0, 0): -0.00039888258851363, (1, 0, 0, 0, 0, 0): -0.0886758234119816, (0, 1, 0, 0, 0, 0): -0.00609682212298237, (0, 0, 1, 0, 0, 0): 0.0349098922286158, (2, 0, 0, 0, 0, 0): -4.51640017486213, (1, 1, 0, 0, 0, 0): -3.25963915927762, (0, 2, 0, 0, 0, 0): -1.99912692932177, (1, 0, 1, 0, 0, 0): 6.72633830337091, (0, 1, 1, 0, 0, 0): -7.66825439939564, (0, 0, 2, 0, 0, 0): -193.642586531618, (0, 0, 0, 1, 0, 0): -0.00268389911176547, (1, 0, 0, 1, 0, 0): -0.311169515084659, (0, 1, 0, 1, 0, 0): -0.038686963743137, (0, 0, 1, 1, 0, 0): 7.80657919317798, (0, 0, 0, 0, 1, 0): 0.947807431026407, (1, 0, 0, 0, 1, 0): 0.036226120179909, (0, 1, 0, 0, 1, 0): 0.00991678932840486, (0, 0, 1, 0, 1, 0): -0.0420504987878313, (0, 0, 0, 0, 0, 1): -8.79504642080991, (1, 0, 0, 0, 0, 1): 1.21949684764171, (0, 1, 0, 0, 0, 1): 5.23371985401311, (0, 0, 1, 0, 0, 1): 1.12070891686907, (0, 0, 0, 2, 0, 0): -0.0114705875677575, (0, 0, 0, 1, 1, 0): 0.00185581068256136, (0, 0, 0, 0, 2, 0): -0.0003151030224793, (0, 0, 0, 1, 0, 1): -0.00772346699498138, (0, 0, 0, 0, 1, 1): 0.012625449993809, (0, 0, 0, 0, 0, 2): 0.360113506485602}, 6: {(0, 0, 0, 0, 0, 0): -7.15739822073735e-06, (1, 0, 0, 0, 0, 0): 0.00531272360919483, (0, 1, 0, 0, 0, 0): -0.000311134017992899, (0, 0, 1, 0, 0, 0): 0.000106214719868989, (2, 0, 0, 0, 0, 0): -0.00955927141323882, (1, 1, 0, 0, 0, 0): -0.176551495462486, (0, 2, 0, 0, 0, 0): -0.0275093357227721, (1, 0, 1, 0, 0, 0): -0.0170321288048837, (0, 1, 1, 0, 0, 0): 0.00530983665538938, (0, 0, 2, 0, 0, 0): 2.02217554346347, (0, 0, 0, 1, 0, 0): -1.59179292923827e-05, (1, 0, 0, 1, 0, 0): -0.00164368706046954, (0, 1, 0, 1, 0, 0): -0.00408626885218236, (0, 0, 1, 1, 0, 0): -0.155773825671643, (0, 0, 0, 0, 1, 0): 0.0115997890372474, (1, 0, 0, 0, 1, 0): -0.000234315872922309, (0, 1, 0, 0, 1, 0): 0.00142853279692678, (0, 0, 1, 0, 1, 0): 0.000135681738128098, (0, 0, 0, 0, 0, 1): 0.947365021061999, (1, 0, 0, 0, 0, 1): -0.0564513604433887, (0, 1, 0, 0, 0, 1): 0.0133267064373976, (0, 0, 1, 0, 0, 1): 0.00296930057588038, (0, 0, 0, 2, 0, 0): -0.000889800670487865, (0, 0, 0, 1, 1, 0): -1.09976207694614e-07, (0, 0, 0, 0, 2, 0): 4.33684051518616e-06, (0, 0, 0, 1, 0, 1): -0.00200397846010455, (0, 0, 0, 0, 1, 1): 0.000905278380288931, (0, 0, 0, 0, 0, 2): 0.00959665031446971}}
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.985453321293565), -0.985196712063462)
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.194136497704606), 0.195138002368737)
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}]