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.00909995345025251,
'design_value': -0.00909995345025251,
'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.75846773e-02, -3.30389471e-02, 2.16132816e-03],
[-1.71130712e-02, -3.57888103e-02, 2.83783435e-03],
[ 1.89157403e-03, -9.56713880e-03, 2.40300212e-03],
[-8.93898584e-03, 1.92383163e-03, 2.67012009e-03],
[-1.10350722e-02, -1.42988398e-02, -1.66269348e-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.85453321e-01, -1.78459151e-01, -2.95064264e-02,
-3.72328913e-05, -1.28463592e-03, 1.69890832e-03],
[ 1.94136498e-01, -9.79571649e-01, -7.19934542e-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 [11]:
Copied!
tao.merit()
tao.merit()
Out[11]:
411.826621947878
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.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 [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.66366332456293e-05,
(1, 0, 0, 0, 0, 0): -0.985196712121264,
(0, 1, 0, 0, 0, 0): -0.179943541478742,
(0, 0, 1, 0, 0, 0): -0.0296993930626426,
(2, 0, 0, 0, 0, 0): 0.446058326311023,
(1, 1, 0, 0, 0, 0): -1.00833852447699,
(0, 2, 0, 0, 0, 0): 1.02619259590484,
(1, 0, 1, 0, 0, 0): -0.826520687167144,
(0, 1, 1, 0, 0, 0): 0.667386065515957,
(0, 0, 2, 0, 0, 0): 44.7241375430296,
(0, 0, 0, 1, 0, 0): -3.89707865886775e-05,
(1, 0, 0, 1, 0, 0): -0.00123738295721789,
(0, 1, 0, 1, 0, 0): -0.0371117272394673,
(0, 0, 1, 1, 0, 0): -4.03450589582482,
(0, 0, 0, 0, 1, 0): -0.00131163342304899,
(1, 0, 0, 0, 1, 0): -0.149523025774999,
(0, 1, 0, 0, 1, 0): 0.0299332532070033,
(0, 0, 1, 0, 1, 0): 0.105807448262342,
(0, 0, 0, 0, 0, 1): 0.0017586048422215,
(1, 0, 0, 0, 0, 1): 2.9030030814798,
(0, 1, 0, 0, 0, 1): 3.49578126799737,
(0, 0, 1, 0, 0, 1): 7.97083327019176,
(0, 0, 0, 2, 0, 0): -0.0184811091840202,
(0, 0, 0, 1, 1, 0): -0.00392766895555333,
(0, 0, 0, 0, 2, 0): 0.000742823360645864,
(0, 0, 0, 1, 0, 1): 0.0279423437756215,
(0, 0, 0, 0, 1, 1): -0.0134034397954057,
(0, 0, 0, 0, 0, 2): -2.38971615160145},
2: {(0, 0, 0, 0, 0, 0): 0.00239048642809983,
(1, 0, 0, 0, 0, 0): 0.195138002246204,
(0, 1, 0, 0, 0, 0): -0.979350347594541,
(0, 0, 1, 0, 0, 0): -0.00732021294645854,
(2, 0, 0, 0, 0, 0): 1.32501350455752,
(1, 1, 0, 0, 0, 0): -0.169115709139895,
(0, 2, 0, 0, 0, 0): 0.295778305661229,
(1, 0, 1, 0, 0, 0): -0.962179520582727,
(0, 1, 1, 0, 0, 0): 0.697975873366684,
(0, 0, 2, 0, 0, 0): 100.484273296565,
(0, 0, 0, 1, 0, 0): 0.000900228227227738,
(1, 0, 0, 1, 0, 0): 0.0452519876941472,
(0, 1, 0, 1, 0, 0): 0.00972377868257597,
(0, 0, 1, 1, 0, 0): -2.89154417505377,
(0, 0, 0, 0, 1, 0): -0.00589560314289985,
(1, 0, 0, 0, 1, 0): -0.0608689011364296,
(0, 1, 0, 0, 1, 0): 0.131509754988494,
(0, 0, 1, 0, 1, 0): 0.0812502189140855,
(0, 0, 0, 0, 0, 1): -0.0381872457546113,
(1, 0, 0, 0, 0, 1): -9.55214847781903,
(0, 1, 0, 0, 0, 1): -5.33582396672927,
(0, 0, 1, 0, 0, 1): 4.52923658962122,
(0, 0, 0, 2, 0, 0): 0.0629079369897762,
(0, 0, 0, 1, 1, 0): -0.00149863579922034,
(0, 0, 0, 0, 2, 0): 0.00058798753561731,
(0, 0, 0, 1, 0, 1): -0.318535799986569,
(0, 0, 0, 0, 1, 1): 0.0412941652923547,
(0, 0, 0, 0, 0, 2): 0.766024881007377},
3: {(0, 0, 0, 0, 0, 0): 1.05157632151015e-06,
(1, 0, 0, 0, 0, 0): -0.000864193360446935,
(0, 1, 0, 0, 0, 0): 6.23497459204656e-05,
(0, 0, 1, 0, 0, 0): -0.873566454497571,
(2, 0, 0, 0, 0, 0): -0.0217551679066695,
(1, 1, 0, 0, 0, 0): 0.000631041611254345,
(0, 2, 0, 0, 0, 0): -0.0181605155558876,
(1, 0, 1, 0, 0, 0): 4.98227514128505,
(0, 1, 1, 0, 0, 0): -3.43330385270312,
(0, 0, 2, 0, 0, 0): -0.305561099569877,
(0, 0, 0, 1, 0, 0): -0.00856834872269358,
(1, 0, 0, 1, 0, 0): -0.132656652399368,
(0, 1, 0, 1, 0, 0): -0.0220531119514065,
(0, 0, 1, 1, 0, 0): 0.00641085056732174,
(0, 0, 0, 0, 1, 0): 1.68093509090195e-05,
(1, 0, 0, 0, 1, 0): 0.00244665826849184,
(0, 1, 0, 0, 1, 0): -0.00396412802401157,
(0, 0, 1, 0, 1, 0): -0.29905516099748,
(0, 0, 0, 0, 0, 1): 0.00264467550362245,
(1, 0, 0, 0, 0, 1): 0.319510813535736,
(0, 1, 0, 0, 0, 1): 0.014171080608509,
(0, 0, 1, 0, 0, 1): -8.266266347989,
(0, 0, 0, 2, 0, 0): -0.000318155048238182,
(0, 0, 0, 1, 1, 0): 0.000633772506966269,
(0, 0, 0, 0, 2, 0): -2.10025901538229e-05,
(0, 0, 0, 1, 0, 1): 0.0846818379984263,
(0, 0, 0, 0, 1, 1): -0.00127341221467528,
(0, 0, 0, 0, 0, 2): 0.0218742037560527},
4: {(0, 0, 0, 0, 0, 0): 1.82087247179064e-06,
(1, 0, 0, 0, 0, 0): 0.0117108773368533,
(0, 1, 0, 0, 0, 0): 0.0298731605798312,
(0, 0, 1, 0, 0, 0): 26.6637945907102,
(2, 0, 0, 0, 0, 0): 0.0868200420083029,
(1, 1, 0, 0, 0, 0): 0.8610384903328,
(0, 2, 0, 0, 0, 0): 0.19082309431141,
(1, 0, 1, 0, 0, 0): 92.6293357792582,
(0, 1, 1, 0, 0, 0): 46.0396583081436,
(0, 0, 2, 0, 0, 0): 0.449570884476955,
(0, 0, 0, 1, 0, 0): -0.883232864350713,
(1, 0, 0, 1, 0, 0): -0.0824329634735449,
(0, 1, 0, 1, 0, 0): 4.59607349244204,
(0, 0, 1, 1, 0, 0): 0.608976435331689,
(0, 0, 0, 0, 1, 0): 2.46914545997493e-05,
(1, 0, 0, 0, 1, 0): 0.0364417937328459,
(0, 1, 0, 0, 1, 0): 0.00478843015976378,
(0, 0, 1, 0, 1, 0): -0.706485569132168,
(0, 0, 0, 0, 0, 1): -0.0404817456354234,
(1, 0, 0, 0, 0, 1): -2.75082829021182,
(0, 1, 0, 0, 0, 1): -8.4987188468425,
(0, 0, 1, 0, 0, 1): -131.350469030953,
(0, 0, 0, 2, 0, 0): 0.00467518361883737,
(0, 0, 0, 1, 1, 0): 0.276221869156002,
(0, 0, 0, 0, 2, 0): -1.88223933734819e-05,
(0, 0, 0, 1, 0, 1): 4.50404232824174,
(0, 0, 0, 0, 1, 1): 0.00433745018009462,
(0, 0, 0, 0, 0, 2): 0.120062394923405},
5: {(0, 0, 0, 0, 0, 0): -0.0003988825884087,
(1, 0, 0, 0, 0, 0): -0.0886757818800877,
(0, 1, 0, 0, 0, 0): -0.00609684953811599,
(0, 0, 1, 0, 0, 0): 0.034909889886605,
(2, 0, 0, 0, 0, 0): -4.50106872019802,
(1, 1, 0, 0, 0, 0): -3.27969945020054,
(0, 2, 0, 0, 0, 0): -1.99254524814805,
(1, 0, 1, 0, 0, 0): 6.72462332396018,
(0, 1, 1, 0, 0, 0): -7.66712831433067,
(0, 0, 2, 0, 0, 0): -193.642555364712,
(0, 0, 0, 1, 0, 0): -0.00268389910622195,
(1, 0, 0, 1, 0, 0): -0.311165263339368,
(0, 1, 0, 1, 0, 0): -0.0386897435547428,
(0, 0, 1, 1, 0, 0): 7.80657933692869,
(0, 0, 0, 0, 1, 0): 0.947807430858927,
(1, 0, 0, 0, 1, 0): 0.0361014826349926,
(0, 1, 0, 0, 1, 0): 0.00999852777331073,
(0, 0, 1, 0, 1, 0): -0.0420435036582939,
(0, 0, 0, 0, 0, 1): -8.79504643278262,
(1, 0, 0, 0, 0, 1): 1.21042761716272,
(0, 1, 0, 0, 0, 1): 5.23965173025358,
(0, 0, 1, 0, 0, 1): 1.12121672815098,
(0, 0, 0, 2, 0, 0): -0.0114705865790572,
(0, 0, 0, 1, 1, 0): 0.00185579339025802,
(0, 0, 0, 0, 2, 0): -0.000314849544374751,
(0, 0, 0, 1, 0, 1): -0.0077247420909248,
(0, 0, 0, 0, 1, 1): 0.0126623969906059,
(0, 0, 0, 0, 0, 2): 0.361457619509646},
6: {(0, 0, 0, 0, 0, 0): -7.15739821347128e-06,
(1, 0, 0, 0, 0, 0): 0.00531272385671303,
(0, 1, 0, 0, 0, 0): -0.000311134181441769,
(0, 0, 1, 0, 0, 0): 0.000106214705868044,
(2, 0, 0, 0, 0, 0): -0.00946793283705544,
(1, 1, 0, 0, 0, 0): -0.176671006538042,
(0, 2, 0, 0, 0, 0): -0.0274701247270216,
(1, 0, 1, 0, 0, 0): -0.0170423459502539,
(0, 1, 1, 0, 0, 0): 0.00531654541026005,
(0, 0, 2, 0, 0, 0): 2.0221757291505,
(0, 0, 0, 1, 0, 0): -1.59179292579666e-05,
(1, 0, 0, 1, 0, 0): -0.00164366173047226,
(0, 1, 0, 1, 0, 0): -0.00408628541305317,
(0, 0, 1, 1, 0, 0): -0.155773824815097,
(0, 0, 0, 0, 1, 0): 0.0115997890362496,
(1, 0, 0, 0, 1, 0): -0.000235058414882435,
(0, 1, 0, 0, 1, 0): 0.0014290197627285,
(0, 0, 1, 0, 1, 0): 0.000135723412355262,
(0, 0, 0, 0, 0, 1): 0.947365020990759,
(1, 0, 0, 0, 0, 1): -0.0565053911766849,
(0, 1, 0, 0, 0, 1): 0.0133620460957031,
(0, 0, 1, 0, 0, 1): 0.0029723259034095,
(0, 0, 0, 2, 0, 0): -0.000889800664572912,
(0, 0, 0, 1, 1, 0): -1.10079227839222e-07,
(0, 0, 0, 0, 2, 0): 4.33835054814222e-06,
(0, 0, 0, 1, 0, 1): -0.00200398605661098,
(0, 0, 0, 0, 1, 1): 0.000905498497623791,
(0, 0, 0, 0, 0, 2): 0.00960465798550142}}
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.98545332129372), -0.985196712121264)
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.194136497704582), 0.195138002246204)
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.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}]
In [ ]:
Copied!