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.826621947818
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.66366331115156e-05, (1, 0, 0, 0, 0, 0): -0.985196712111442, (0, 1, 0, 0, 0, 0): -0.179943541486669, (0, 0, 1, 0, 0, 0): -0.0296993930632307, (2, 0, 0, 0, 0, 0): 0.446039758039339, (1, 1, 0, 0, 0, 0): -1.00831415832746, (0, 2, 0, 0, 0, 0): 1.02618461032673, (1, 0, 1, 0, 0, 0): -0.826518592905612, (0, 1, 1, 0, 0, 0): 0.667384697274018, (0, 0, 2, 0, 0, 0): 44.7241374811635, (0, 0, 0, 1, 0, 0): -3.89707865919933e-05, (1, 0, 0, 1, 0, 0): -0.00123738810680118, (0, 1, 0, 1, 0, 0): -0.0371117238484747, (0, 0, 1, 1, 0, 0): -4.03450589559614, (0, 0, 0, 0, 1, 0): -0.00131163342304087, (1, 0, 0, 0, 1, 0): -0.14952286875742, (0, 1, 0, 0, 1, 0): 0.0299331503900679, (0, 0, 1, 0, 1, 0): 0.105807439430582, (0, 0, 0, 0, 0, 1): 0.00175860484055667, (1, 0, 0, 0, 0, 1): 2.90301503579463, (0, 1, 0, 0, 0, 1): 3.49577342807786, (0, 0, 1, 0, 0, 1): 7.97083259886438, (0, 0, 0, 2, 0, 0): -0.018481109179836, (0, 0, 0, 1, 1, 0): -0.00392766893369852, (0, 0, 0, 0, 2, 0): 0.000742823029135284, (0, 0, 0, 1, 0, 1): 0.0279423454311215, (0, 0, 0, 0, 1, 1): -0.0134034901619688, (0, 0, 0, 0, 0, 2): -2.38971806146948}, 2: {(0, 0, 0, 0, 0, 0): 0.00239048642790061, (1, 0, 0, 0, 0, 0): 0.195138002263371, (0, 1, 0, 0, 0, 0): -0.979350347610129, (0, 0, 1, 0, 0, 0): -0.0073202129480413, (2, 0, 0, 0, 0, 0): 1.32497456853872, (1, 1, 0, 0, 0, 0): -0.169064614132808, (0, 2, 0, 0, 0, 0): 0.295761559774822, (1, 0, 1, 0, 0, 0): -0.962175128484806, (0, 1, 1, 0, 0, 0): 0.697973003829092, (0, 0, 2, 0, 0, 0): 100.484273163747, (0, 0, 0, 1, 0, 0): 0.00090022822723298, (1, 0, 0, 1, 0, 0): 0.0452519768781158, (0, 1, 0, 1, 0, 0): 0.00972378580366483, (0, 0, 1, 1, 0, 0): -2.89154417444632, (0, 0, 0, 0, 1, 0): -0.00589560314294963, (1, 0, 0, 0, 1, 0): -0.0608685718749318, (0, 1, 0, 0, 1, 0): 0.131509539377717, (0, 0, 1, 0, 1, 0): 0.0812502003910028, (0, 0, 0, 0, 0, 1): -0.0381872457583541, (1, 0, 0, 0, 0, 1): -9.55212341075726, (0, 1, 0, 0, 0, 1): -5.33584040660139, (0, 0, 1, 0, 0, 1): 4.52923518168616, (0, 0, 0, 2, 0, 0): 0.0629079369931611, (0, 0, 0, 1, 1, 0): -0.00149863575334188, (0, 0, 0, 0, 2, 0): 0.000587986840439191, (0, 0, 0, 1, 0, 1): -0.318535796509916, (0, 0, 0, 0, 1, 1): 0.0412940596773397, (0, 0, 0, 0, 0, 2): 0.766020876298347}, 3: {(0, 0, 0, 0, 0, 0): 1.05157632154144e-06, (1, 0, 0, 0, 0, 0): -0.000864193360488003, (0, 1, 0, 0, 0, 0): 6.23497459449462e-05, (0, 0, 1, 0, 0, 0): -0.87356645449471, (2, 0, 0, 0, 0, 0): -0.0217550982537178, (1, 1, 0, 0, 0, 0): 0.000630950212311589, (0, 2, 0, 0, 0, 0): -0.0181604856026937, (1, 0, 1, 0, 0, 0): 4.98227513521268, (0, 1, 1, 0, 0, 0): -3.43330384882678, (0, 0, 2, 0, 0, 0): -0.305561099436065, (0, 0, 0, 1, 0, 0): -0.0085683487227424, (1, 0, 0, 1, 0, 0): -0.132656652445596, (0, 1, 0, 1, 0, 0): -0.022053111917853, (0, 0, 1, 1, 0, 0): 0.00641085056971534, (0, 0, 0, 0, 1, 0): 1.68093509081016e-05, (1, 0, 0, 0, 1, 0): 0.00244665767953348, (0, 1, 0, 0, 1, 0): -0.00396412763837813, (0, 0, 1, 0, 1, 0): -0.299055160971007, (0, 0, 0, 0, 0, 1): 0.00264467550354261, (1, 0, 0, 0, 0, 1): 0.319510768688998, (0, 1, 0, 0, 0, 1): 0.0141711100170147, (0, 0, 1, 0, 0, 1): -8.26626634568988, (0, 0, 0, 2, 0, 0): -0.000318155048237356, (0, 0, 0, 1, 1, 0): 0.000633772507112499, (0, 0, 0, 0, 2, 0): -2.10025889104558e-05, (0, 0, 0, 1, 0, 1): 0.0846818380003504, (0, 0, 0, 0, 1, 1): -0.00127341202574409, (0, 0, 0, 0, 0, 2): 0.0218742109205179}, 4: {(0, 0, 0, 0, 0, 0): 1.8208724604107e-06, (1, 0, 0, 0, 0, 0): 0.0117108773359901, (0, 1, 0, 0, 0, 0): 0.029873160580592, (0, 0, 1, 0, 0, 0): 26.6637945908523, (2, 0, 0, 0, 0, 0): 0.0868217566846232, (1, 1, 0, 0, 0, 0): 0.861036240207068, (0, 2, 0, 0, 0, 0): 0.190823831702157, (1, 0, 1, 0, 0, 0): 92.6293356320696, (0, 1, 1, 0, 0, 0): 46.0396584002012, (0, 0, 2, 0, 0, 0): 0.449570887195235, (0, 0, 0, 1, 0, 0): -0.883232864350671, (1, 0, 0, 1, 0, 0): -0.0824329623200235, (0, 1, 0, 1, 0, 0): 4.59607349167232, (0, 0, 1, 1, 0, 0): 0.608976435281232, (0, 0, 0, 0, 1, 0): 2.46914546014198e-05, (1, 0, 0, 0, 1, 0): 0.0364417792329716, (0, 1, 0, 0, 1, 0): 0.00478843965419027, (0, 0, 1, 0, 1, 0): -0.706485568569288, (0, 0, 0, 0, 0, 1): -0.0404817456352183, (1, 0, 0, 0, 0, 1): -2.75082939419576, (0, 1, 0, 0, 0, 1): -8.49871812290191, (0, 0, 1, 0, 0, 1): -131.350468992036, (0, 0, 0, 2, 0, 0): 0.00467518361850745, (0, 0, 0, 1, 1, 0): 0.276221869152016, (0, 0, 0, 0, 2, 0): -1.88223627597008e-05, (0, 0, 0, 1, 0, 1): 4.50404232782958, (0, 0, 0, 0, 1, 1): 0.00433745483153057, (0, 0, 0, 0, 0, 2): 0.120062571322928}, 5: {(0, 0, 0, 0, 0, 0): -0.000398882588575164, (1, 0, 0, 0, 0, 0): -0.0886757894723777, (0, 1, 0, 0, 0, 0): -0.00609684427624298, (0, 0, 1, 0, 0, 0): 0.0349098903372756, (2, 0, 0, 0, 0, 0): -4.48796105572809, (1, 1, 0, 0, 0, 0): -3.29690042367572, (0, 2, 0, 0, 0, 0): -1.98690777289525, (1, 0, 1, 0, 0, 0): 6.72314463485622, (0, 1, 1, 0, 0, 0): -7.6661622238168, (0, 0, 2, 0, 0, 0): -193.642510634029, (0, 0, 0, 1, 0, 0): -0.00268389910720762, (1, 0, 0, 1, 0, 0): -0.311161618279117, (0, 1, 0, 1, 0, 0): -0.0386921433403685, (0, 0, 1, 1, 0, 0): 7.8065790646898, (0, 0, 0, 0, 1, 0): 0.947807430885755, (1, 0, 0, 0, 1, 0): 0.0359906378947653, (0, 1, 0, 0, 1, 0): 0.0100711124539497, (0, 0, 1, 0, 1, 0): -0.0420372674981191, (0, 0, 0, 0, 0, 1): -8.79504643133774, (1, 0, 0, 0, 0, 1): 1.20198899523853, (0, 1, 0, 0, 0, 1): 5.24518611418161, (0, 0, 1, 0, 0, 1): 1.12169072423127, (0, 0, 0, 2, 0, 0): -0.0114705864406938, (0, 0, 0, 1, 1, 0): 0.00185577793390013, (0, 0, 0, 0, 2, 0): -0.000314615528510323, (0, 0, 0, 1, 0, 1): -0.00772591233718414, (0, 0, 0, 0, 1, 1): 0.0126979515998576, (0, 0, 0, 0, 0, 2): 0.362805752237921}, 6: {(0, 0, 0, 0, 0, 0): -7.15739821544826e-06, (1, 0, 0, 0, 0, 0): 0.00531272381144168, (0, 1, 0, 0, 0, 0): -0.000311134150053816, (0, 0, 1, 0, 0, 0): 0.000106214708568258, (2, 0, 0, 0, 0, 0): -0.00938984271738104, (1, 1, 0, 0, 0, 0): -0.176773482956579, (0, 2, 0, 0, 0, 0): -0.02743653896352, (1, 0, 1, 0, 0, 0): -0.017051155381275, (0, 1, 1, 0, 0, 0): 0.00532230098211495, (0, 0, 2, 0, 0, 0): 2.02217599565802, (0, 0, 0, 1, 0, 0): -1.59179292643227e-05, (1, 0, 0, 1, 0, 0): -0.0016436400146696, (0, 1, 0, 1, 0, 0): -0.00408629971002025, (0, 0, 1, 1, 0, 0): -0.155773826437622, (0, 0, 0, 0, 1, 0): 0.0115997890364088, (1, 0, 0, 0, 1, 0): -0.00023571878219268, (0, 1, 0, 0, 1, 0): 0.00142945219236257, (0, 0, 1, 0, 1, 0): 0.000135760564837267, (0, 0, 0, 0, 0, 1): 0.947365020999293, (1, 0, 0, 0, 0, 1): -0.0565556650381081, (0, 1, 0, 0, 0, 1): 0.0133950177217135, (0, 0, 1, 0, 0, 1): 0.00297514978084482, (0, 0, 0, 2, 0, 0): -0.000889800663761675, (0, 0, 0, 1, 1, 0): -1.10171310733973e-07, (0, 0, 0, 0, 2, 0): 4.33974479439785e-06, (0, 0, 0, 1, 0, 1): -0.00200399302844186, (0, 0, 0, 0, 1, 1): 0.000905710315980399, (0, 0, 0, 0, 0, 2): 0.00961268961354989}}
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.98545332129356), -0.985196712111442)
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.194136497704558), 0.195138002263371)
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}]