from pytao import Tao
tao=Tao('-init $ACC_ROOT_DIR/bmad-doc/tao_examples/cesr/tao.init -noplot')
Send a command¶
Anything that you would normally type at a Tao> prompt can be sent as a string. The return is a list of output strings. To send a command:
tao.cmd('show lat 1:10')
['# Values shown are for the Exit End of each Element:', '# Index name key s l beta phi_a eta orbit beta phi_b eta orbit Track', '# a [2pi] x x [mm] b [2pi] y y [mm] State', ' 1 IP_L0 Marker 0.000 0.000 0.95 0.000 -0.00 -0.017 0.02 0.000 0.00 0.001 Alive', ' 2 CLEO_SOL#3 Solenoid 0.622 0.622 1.34 0.093 -0.02 1.470 21.81 0.244 0.00 0.041 Alive', ' 3 DET_00W Marker 0.622 0.000 1.34 0.093 -0.02 1.470 21.81 0.244 0.00 0.041 Alive', ' 4 CLEO_SOL#4 Solenoid 0.638 0.016 1.36 0.094 -0.02 1.507 22.92 0.244 0.00 0.043 Alive', ' 5 Q00W\\CLEO_SOL Sol_Quad 1.755 1.117 7.73 0.160 -0.09 5.505 88.01 0.247 -0.01 0.486 Alive', ' 6 Q00W#1 Quadrupole 2.163 0.408 15.96 0.166 -0.13 8.151 76.38 0.248 -0.01 0.717 Alive', ' 7 D003 Drift 2.493 0.331 27.02 0.169 -0.17 10.705 60.25 0.249 -0.02 0.931 Alive', ' 8 DET_01W Marker 2.493 0.000 27.02 0.169 -0.17 10.705 60.25 0.249 -0.02 0.931 Alive', ' 9 D004 Drift 2.924 0.431 45.79 0.171 -0.22 14.030 42.12 0.250 -0.02 1.209 Alive', ' 10 Q01W Quadrupole 3.874 0.950 66.94 0.173 -0.26 16.851 28.95 0.255 -0.02 1.213 Alive', '# Index name key s l beta phi_a eta orbit beta phi_b eta orbit Track', '# a [2pi] x x [mm] b [2pi] y y [mm] State', '# Values shown are for the Exit End of each Element:']
Send a list of commands. This returns the corresponding list of outputs:
tao.cmds(
['set lattice model=design',
'set ele Q00W x_offset = 1e-6']
)
[[], []]
Jupyter magic %%tao¶
This is an alternative way to send commands to Tao directly in the jupyter notebook, using the %%tao magic. Multiple lines can be executed.
%%tao
sho lat 1:10
sho ele 4
------------------------- Tao> sho lat 1:10 # Values shown are for the Exit End of each Element: # Index name key s l beta phi_a eta orbit beta phi_b eta orbit Track # a [2pi] x x [mm] b [2pi] y y [mm] State 1 IP_L0 Marker 0.000 0.000 0.95 0.000 -0.00 -0.018 0.02 0.000 0.00 0.001 Alive 2 CLEO_SOL#3 Solenoid 0.622 0.622 1.34 0.093 -0.02 1.469 21.81 0.244 0.00 0.042 Alive 3 DET_00W Marker 0.622 0.000 1.34 0.093 -0.02 1.469 21.81 0.244 0.00 0.042 Alive 4 CLEO_SOL#4 Solenoid 0.638 0.016 1.36 0.094 -0.02 1.507 22.92 0.244 0.00 0.044 Alive 5 Q00W\CLEO_SOL Sol_Quad 1.755 1.117 7.73 0.160 -0.09 5.505 88.01 0.247 -0.01 0.487 Alive 6 Q00W#1 Quadrupole 2.163 0.408 15.96 0.166 -0.13 8.151 76.38 0.248 -0.01 0.719 Alive 7 D003 Drift 2.493 0.331 27.02 0.169 -0.17 10.705 60.25 0.249 -0.02 0.932 Alive 8 DET_01W Marker 2.493 0.000 27.02 0.169 -0.17 10.705 60.25 0.249 -0.02 0.932 Alive 9 D004 Drift 2.924 0.431 45.79 0.171 -0.22 14.030 42.12 0.250 -0.02 1.210 Alive 10 Q01W Quadrupole 3.874 0.950 66.94 0.173 -0.26 16.851 28.95 0.255 -0.02 1.213 Alive # Index name key s l beta phi_a eta orbit beta phi_b eta orbit Track # a [2pi] x x [mm] b [2pi] y y [mm] State # Values shown are for the Exit End of each Element: ------------------------- Tao> sho ele 4 Element # 4 Element Name: CLEO_SOL#4 Key: Solenoid S_start, S: 0.622301, 0.637956 Ref_time: 2.127992E-09 Attribute values [Only non-zero values shown]: 1 L = 1.5655000E-02 m 31 L_SOFT_EDGE = 0.0000000E+00 m 3 R_SOLENOID = 0.0000000E+00 m 5 KS = -8.5023386E-02 1/m 49 BS_FIELD = 1.5000000E+00 T 10 FRINGE_TYPE = None (1) 11 FRINGE_AT = No_End (4) 13 SPIN_FRINGE_ON = T (1) 17 STATIC_LINEAR_MAP = F (0) 47 PTC_CANONICAL_COORDS = T (1) 50 DELTA_REF_TIME = 5.2219459E-11 sec 53 P0C = 5.2890000E+09 eV BETA = 1.0000000E+00 54 E_TOT = 5.2890000E+09 eV GAMMA = 1.0350315E+04 65 INTEGRATOR_ORDER = 0 67 DS_STEP = 2.0000000E-01 m 66 NUM_STEPS = 1 68 CSR_DS_STEP = 0.0000000E+00 m TRACKING_METHOD = Bmad_Standard APERTURE_AT = Exit_End MAT6_CALC_METHOD = Bmad_Standard APERTURE_TYPE = Rectangular SPIN_TRACKING_METHOD = Tracking OFFSET_MOVES_APERTURE = F PTC_INTEGRATION_TYPE = Matrix_Kick SYMPLECTIFY = F CSR_METHOD = Off FIELD_MASTER = F SPACE_CHARGE_METHOD = Off LONGITUDINAL ORIENTATION = 1 FIELD_CALC = Refer_to_Lords. Slave_status: Super_Slave Associated Super_Lord(s): Index Name Type 872 CLEO_SOL Solenoid Lord_status: Not_a_Lord Twiss at end of element: A B Cbar C_mat Beta (m) 1.36490320 22.91977153 | -0.11412810 0.00652709 -0.08500246 0.03650694 Alpha -0.65684268 -35.88090663 | -0.16215602 0.00350746 -0.09239919 0.03194148 Gamma (1/m) 1.04875005 56.21519652 | Gamma_c = 0.99967089 Mode_Flip = F Phi (rad) 0.59356742 1.53299612 X Y Z Eta (m) -0.02444437 0.00057682 -0.02453396 0.00007942 0.00005371 Etap -0.03500697 -0.00133149 -0.03509127 -0.00204809 1.00000000 Sigma 0.00052589 0.00002028 0.00000000 0.00000000 Orbit: Electron State: Alive Position[mm] Momentum[mrad] Spin | X: 1.50654732 2.38873152 | t_particle [sec]: 2.12933094E-09 E_tot: 5.28896E+09 Y: 0.04370624 0.06771334 | t_part-t_ref [sec]: 1.33877127E-12 PC: 5.28896E+09 Z: -0.40135353 -0.00717210 | (t_ref-t_part)*Vel [m]: -4.01353529E-04 Beta: 0.999999995 ------------------------- Tao>
Interface commands¶
Output above from the show
command is designed to be human-readable. In general you should not try to parse these strings for data. For data, Tao has a special set of commands to send back data suitable for parsing in Python (or other software).
Below are the raw commands.
%%tao
help python
------------------------- Tao> help python The "python" command is like the "show" command in that the "python" command prints information to the terminal. The difference is that the output from the "show" command is meant for viewing by the user while the output of the "python" command is meant for easy parsing. Format: python {-append <file_name>} {-noprint} <subcommand> <arguments> python {-write <file_name>} {-noprint} <subcommand> <arguments> The "python" command has "-append" and "-write" optional arguments which can be used to write the results to a file. The "python -append" command will appended to the output file. The "python -write" command will first erase the contents of the output file. Example: python -write d2.dat data_d2 ! Write to file "d2.dat" The "-noprint" option suppresses printing and is useful when writing large amounts of data to a file. The "python" command can be used to pass information to a parent process when Tao is run as a subprocess. The parent process may be any scripting program like Python, Perl, Tcl, etc. In particular, see the "Python/GUI Interface" chapter for details on how to run Tao as a Python subprocess. In terms of long term maintainability, the advantage of using the "python" command in the scripts over the "show" command comes from the fact that the output syntax of "show" commands can (and does) change. For further documentation on the python command and interfacing to python is in the "Python/GUI Interface chapter . Documentation on interfacing Python scripts to Tao's python command is given in the "Tao Python Command section . List of possible "<what_to_print>" choices: beam, beam_init, branch1, bunch_comb, bunch_params, bunch1, bmad_com, building_wall_list, building_wall_graph, building_wall_point, building_wall_section, constraints, da_params, da_aperture, data, data_d2_create, data_d2_destroy, data_d_array, data_d1_array, data_d2, data_d2_array, data_set_design_value, data_parameter, datum_create, datum_has_ele, derivative, ele:ac_kicker, ele:cartesian_map, ele:chamber_wall, ele:control_var, ele:cylindrical_map, ele:elec_multipoles, ele:floor, ele:grid_field, ele:gen_attribs, ele:head, ele:lord_slave, ele:mat6, ele:methods, ele:multipoles, ele:orbit, ele:param, ele:photon, ele:spin_taylor, ele:taylor, ele:taylor_field, ele:twiss, ele:wake, ele:wall3d, em_field, enum, evaluate, floor_plan, floor_orbit, global, help, inum, lat_branch_list, lat_calc_done, lat_ele_list, lat_list, lat_param_units, matrix, merit, orbit_at_s, place_buffer, plot_curve, plot_graph, plot_histogram, plot_lat_layout, plot_line, plot_plot_manage, plot_graph_manage, plot_curve_manage, plot_list, plot_symbol, plot_transfer, plot1, ptc_com, ring_general, shape_list, shape_manage, shape_pattern_list, shape_pattern_manage, shape_pattern_point_manage, shape_set, show, species_to_int, species_to_str, spin_polarization, spin_resonance, super_universe, twiss_at_s, universe, var_v1_create, var_v1_destroy, var_create, var_general, var_v1_array, var_v_array, var, wave ------------------------- Tao>
This data is returned as specially formatted lists
tao.cmd('python orbit_at_s end')
['x;REAL;F; -1.77207910292112E-05', 'px;REAL;F; 2.39054798135166E-03', 'y;REAL;F; 9.77805901311320E-07', 'py;REAL;F; 2.91412238054611E-06', 'z;REAL;F; -3.99530687252325E-04', 'pz;REAL;F; -7.17210141059523E-06', 'spin;REAL_ARR;F; 0.00000000000000E+00; 0.00000000000000E+00; 0.00000000000000E+00', 'field;REAL_ARR;F; 0.00000000000000E+00; 0.00000000000000E+00', 'phase;REAL_ARR;F; 0.00000000000000E+00; 0.00000000000000E+00', 's;REAL;F; 7.68426421416168E+02', 't;REAL;F; 2.56319600136698E-06', 'charge;REAL;F; 0.00000000000000E+00', 'dt_ref;REAL;F; 0.00000000000000E+00', 'p0c;REAL;F; 5.28899997531481E+09', 'beta;REAL;F; 9.99999995332664E-01', 'ix_ele;INT;F;868', 'state;STR;F;Alive', 'direction;INT;F;1', 'species;SPECIES;F;Electron', 'location;STR;F;Downstream_End']
Some commands have 'array_out' options. For example, this seems to return nothing:
tao.cmd('python lat_list -array_out 1@0>>Q*|model orbit.floor.x')
[]
But calling .cmd_real
on the same command will get the data from an internal pointer:
tao.cmd_real('python lat_list -array_out 1@0>>Q*|model orbit.floor.x')
array([ 0.00000000e+00, 5.50519227e-03, 8.15061849e-03, 1.68506712e-02, 1.30498232e-02, -1.28475438e-01, -6.17368437e-01, -1.63573126e+00, -3.15361609e+00, -4.96008216e+00, -8.44394576e+00, -1.25353213e+01, -1.53643077e+01, -1.93160719e+01, -2.35334256e+01, -2.86596035e+01, -3.40012341e+01, -4.11157702e+01, -4.73379418e+01, -5.39309791e+01, -6.08761235e+01, -6.66395259e+01, -7.38887343e+01, -8.14004767e+01, -8.91380421e+01, -9.70602503e+01, -1.07067453e+02, -1.15219118e+02, -1.23415239e+02, -1.31835984e+02, -1.39984608e+02, -1.48267474e+02, -1.57243533e+02, -1.65204340e+02, -1.72728163e+02, -1.80184446e+02, -1.85357654e+02, -1.92035945e+02, -2.00803297e+02, -2.06870811e+02, -2.12665465e+02, -2.18176442e+02, -2.23048894e+02, -2.27424214e+02, -2.31268351e+02, -2.34552350e+02, -2.35722776e+02, -2.38140768e+02, -2.39786174e+02, -2.41460795e+02, -2.42244506e+02, -2.42601932e+02, -2.42642705e+02, -2.42650645e+02, -2.42653709e+02, -2.42654860e+02, -2.42659283e+02, -2.42665715e+02, -2.42598206e+02, -2.42184674e+02, -2.41366882e+02, -2.39606403e+02, -2.37970183e+02, -2.35481963e+02, -2.34317756e+02, -2.30993039e+02, -2.27125231e+02, -2.22727551e+02, -2.17816004e+02, -2.12280141e+02, -2.06437555e+02, -2.00332917e+02, -1.91531576e+02, -1.84820355e+02, -1.79653411e+02, -1.72176809e+02, -1.64644374e+02, -1.56674250e+02, -1.47685973e+02, -1.39396225e+02, -1.31238484e+02, -1.22815238e+02, -1.14621366e+02, -1.06478606e+02, -9.64783788e+01, -8.85696847e+01, -8.08418091e+01, -7.33402427e+01, -6.61118703e+01, -6.03400294e+01, -5.34245487e+01, -4.68515948e+01, -4.06754335e+01, -3.36162850e+01, -2.82979320e+01, -2.32077253e+01, -1.88775830e+01, -1.50782620e+01, -1.22578107e+01, -8.16225874e+00, -4.68317228e+00, -2.92445682e+00, -1.48689125e+00, -5.48022495e-01, -1.20827634e-01, -1.39453226e-02, -1.41528499e-02, 1.91718054e-06, -5.55948643e-03, -1.54020138e-03])
Tao method commands¶
For convenience, all of these commands are available as methods of the Tao class, and automatically parse the output.
For example, to get the orbit at an s
position:
tao.orbit_at_s(s_offset=1.2)
{'x': 0.0031086901274779, 'px': 0.0034460056817536, 'y': 0.000183189785860305, 'py': 0.000248941211797618, 'z': -0.0004036816716607, 'pz': -7.17210141039588e-06, 'spin': array([0., 0., 0.]), 'field': array([0., 0.]), 'phase': array([0., 0.]), 's': 1.2, 't': 4.00411569818167e-09, 'charge': 0.0, 'dt_ref': 0.0, 'p0c': 5288999975.31481, 'beta': 0.999999995332663, 'ix_ele': 5, 'state': 'Alive', 'direction': 1, 'species': 'Electron', 'location': 'Inside'}
Some commands return arrays:
tao.evaluate('data::cbar.11[1:10]|model')
array([ 2.81123079e-03, -1.06250116e-03, 1.37663897e-04, 3.08061468e-04, -3.66558773e-04, -3.42869828e-04, -9.92518410e-06, 1.28279236e-03, 2.66250275e-03, 2.68364505e-03])
lat_list¶
lat_list
can be used to efficiently extract array data. By default this returns an array of floats:
s = tao.lat_list('*', 'ele.s', verbose=True)
s[0:5]
python lat_list -array_out -track_only @>>*|model ele.s
array([0. , 0. , 0.622301, 0.622301, 0.637956])
These particulars keys will return integers:
state = tao.lat_list('*', 'orbit.state')
ix = tao.lat_list('*', 'ele.ix_ele')
state.dtype, ix.dtype
(dtype('<i4'), dtype('<i4'))
And this one will return a list of strings:
names = tao.lat_list('*', 'ele.name')
names[0:5]
['BEGINNING', 'IP_L0', 'CLEO_SOL#3', 'DET_00W', 'CLEO_SOL#4']
%config InlineBackend.figure_format = 'retina'
import matplotlib.pyplot as plt
import numpy as np
Simple plot of this data
plt.plot(
tao.lat_list('*', 'ele.s'),
tao.lat_list('*', 'orbit.vec.1'),
marker='.'
)
[<matplotlib.lines.Line2D at 0x14c1cd430>]
Be careful with the flags. The defaults are:
plt.plot(tao.lat_list('*', 'ele.s', flags='-array_out -track_only'))
[<matplotlib.lines.Line2D at 0x14c2e3af0>]
-index_order
will return
plt.plot(tao.lat_list('*', 'ele.s', flags='-array_out -index_order'))
[<matplotlib.lines.Line2D at 0x14c36b310>]
All method commands¶
There are many method commands. Please explore the documentation to find the ones that will best suit your needs.
from pytao import interface_commands
all_cmds = [name for name in dir(interface_commands) if not name.startswith('__')]
print(all_cmds)
['beam', 'beam_init', 'bmad_com', 'branch1', 'building_wall_graph', 'building_wall_list', 'building_wall_point', 'building_wall_section', 'bunch1', 'bunch_comb', 'bunch_params', 'constraints', 'da_aperture', 'da_params', 'data', 'data_d1_array', 'data_d2', 'data_d2_array', 'data_d2_create', 'data_d2_destroy', 'data_d_array', 'data_parameter', 'data_set_design_value', 'datum_create', 'datum_has_ele', 'derivative', 'ele_ac_kicker', 'ele_cartesian_map', 'ele_chamber_wall', 'ele_control_var', 'ele_cylindrical_map', 'ele_elec_multipoles', 'ele_floor', 'ele_gen_attribs', 'ele_grid_field', 'ele_head', 'ele_lord_slave', 'ele_mat6', 'ele_methods', 'ele_multipoles', 'ele_orbit', 'ele_param', 'ele_photon', 'ele_spin_taylor', 'ele_taylor', 'ele_taylor_field', 'ele_twiss', 'ele_wake', 'ele_wall3d', 'em_field', 'enum', 'evaluate', 'floor_orbit', 'floor_plan', 'help', 'inum', 'lat_branch_list', 'lat_calc_done', 'lat_ele_list', 'lat_list', 'lat_param_units', 'matrix', 'merit', 'orbit_at_s', 'parse_tao_python_data', 'place_buffer', 'plot1', 'plot_curve', 'plot_curve_manage', 'plot_graph', 'plot_graph_manage', 'plot_histogram', 'plot_lat_layout', 'plot_line', 'plot_list', 'plot_symbol', 'plot_template_manage', 'plot_transfer', 'ptc_com', 'ring_general', 'shape_list', 'shape_manage', 'shape_pattern_list', 'shape_pattern_manage', 'shape_pattern_point_manage', 'shape_set', 'show', 'species_to_int', 'species_to_str', 'spin_polarization', 'spin_resonance', 'super_universe', 'tao_global', 'tao_parameter_dict', 'twiss_at_s', 'universe', 'var', 'var_create', 'var_general', 'var_v1_array', 'var_v1_create', 'var_v1_destroy', 'var_v_array', 'wave']
There are many commands:
len(all_cmds)
104
Other Tao instances¶
Unfortunately there can only be one Tao instance per process, because the internal structures are held in memory and accessed via ctypes. So this will replace the current Tao session in memory.
This looks like a new object:
tao2=Tao('-init $ACC_ROOT_DIR/bmad-doc/tao_examples/csr_beam_tracking/tao.init -noplot')
but internally connects to:
tao.lat_list('*', 'ele.name')
['BEGINNING', 'MAR.CSR', 'FF.PIP00B', 'FF.BEN01', 'FF.PIP01', 'FF.BEN02', 'FF.PIP02A', 'MAR.END', 'END']
Bunch data¶
This example has bunch data. There are three methods:
tao.bunch_params
to get a dict of statistical datatao.bunch1
to get coordinate data arraystao.bunch_data
to get a dict of many coordinate arrays. These can be used to instantiate a ParticleGroup object from the openPMD-beamphysics package.
Statistical data:
stats = tao.bunch_params('end')
stats.keys()
dict_keys(['beta_x', 'alpha_x', 'gamma_x', 'phi_x', 'eta_x', 'etap_x', 'sigma_x', 'sigma_p_x', 'emit_x', 'norm_emit_x', 'beta_y', 'alpha_y', 'gamma_y', 'phi_y', 'eta_y', 'etap_y', 'sigma_y', 'sigma_p_y', 'emit_y', 'norm_emit_y', 'beta_z', 'alpha_z', 'gamma_z', 'phi_z', 'eta_z', 'etap_z', 'sigma_z', 'sigma_p_z', 'emit_z', 'norm_emit_z', 'beta_a', 'alpha_a', 'gamma_a', 'phi_a', 'eta_a', 'etap_a', 'sigma_a', 'sigma_p_a', 'emit_a', 'norm_emit_a', 'beta_b', 'alpha_b', 'gamma_b', 'phi_b', 'eta_b', 'etap_b', 'sigma_b', 'sigma_p_b', 'emit_b', 'norm_emit_b', 'beta_c', 'alpha_c', 'gamma_c', 'phi_c', 'eta_c', 'etap_c', 'sigma_c', 'sigma_p_c', 'emit_c', 'norm_emit_c', 'sigma_11', 'sigma_12', 'sigma_13', 'sigma_14', 'sigma_15', 'sigma_16', 'sigma_21', 'sigma_22', 'sigma_23', 'sigma_24', 'sigma_25', 'sigma_26', 'sigma_31', 'sigma_32', 'sigma_33', 'sigma_34', 'sigma_35', 'sigma_36', 'sigma_41', 'sigma_42', 'sigma_43', 'sigma_44', 'sigma_45', 'sigma_46', 'sigma_51', 'sigma_52', 'sigma_53', 'sigma_54', 'sigma_55', 'sigma_56', 'sigma_61', 'sigma_62', 'sigma_63', 'sigma_64', 'sigma_65', 'sigma_66', 'rel_min_1', 'rel_max_1', 'centroid_vec_1', 'rel_min_2', 'rel_max_2', 'centroid_vec_2', 'rel_min_3', 'rel_max_3', 'centroid_vec_3', 'rel_min_4', 'rel_max_4', 'centroid_vec_4', 'rel_min_5', 'rel_max_5', 'centroid_vec_5', 'rel_min_6', 'rel_max_6', 'centroid_vec_6', 'centroid_t', 'centroid_p0c', 'centroid_beta', 'ix_ele', 'direction', 'species', 'location', 's', 'charge_live', 'n_particle_tot', 'n_particle_live', 'n_particle_lost_in_ele', 'beam_saved'])
Array data:
x = tao.bunch1('end', coordinate='x')
px = tao.bunch1('end', coordinate='px')
plt.scatter(x, px)
<matplotlib.collections.PathCollection at 0x14c3eef10>
The state will be returned as an integer array.
state = tao.bunch1('end', coordinate='state')
state.dtype
dtype('<i4')
ParticleGroup from openPMD-beamphysics¶
openPMD-beamphysics is an external package that can be useful for further bunch analysis, plotting, and conversion.
https://github.com/ChristopherMayes/openPMD-beamphysics
Here is example usage to extract bunch data and instantiate as a ParticleGroup
object.
Note that the momentum units in openPMD-beamphysics are in eV/c, whereas Bmad's momenta are normalized by a refrence momentum.
from pmd_beamphysics import ParticleGroup
This data is suitable for the ParticleGroup
class
data = tao.bunch_data('end')
data.keys()
dict_keys(['x', 'px', 'y', 'py', 't', 'pz', 'status', 'weight', 'z', 'species'])
P = ParticleGroup(data=data)
P.plot('x', 'px')
Tao's write format is already in the openPMD-beamphysics, so particles can be written and read in this way as well.
tao.cmd('write beam -at end test.h5')
['[INFO] tao_write_cmd:', ' Written: test.h5']
P2 = ParticleGroup('test.h5')
P2.plot('x', 'px')
# Cleanup
!rm test.h5
Error handling and Debugging¶
All methods have a raises=True
option. This will raise a RuntimeError if any errors are seen from Tao.
tao.lat_list('*', 'ele.s')
array([0. , 0. , 0.06 , 0.193, 0.263, 0.385, 0.445, 0.445, 0.445])
try:
tao.lat_list('*', 'ele.saa')
except Exception as ex:
print(ex)
ERROR detected: [ERROR | 2022-OCT-13 15:38:28] tao_python_cmd: "python lat_list -array_out -track_only @>>*|model ele.saa": Bad {who}: ele.saa INVALID
This suppresses the exceptions, returning None
tao.lat_list('*', 'ele.saa', raises=False)
try:
tao.cmd('safaf')
except Exception as ex:
print(ex)
Command: safaf causes error: ERROR detected: [ERROR | 2022-OCT-13 15:38:28] tao_command: UNRECOGNIZED COMMAND: safaf
This returns the lines
tao.cmd('safaf', raises=False)
['[ERROR | 2022-OCT-13 15:38:28] tao_command:', ' UNRECOGNIZED COMMAND: safaf']
Logging¶
All input commands are recorded as debug messages using standard Python logging.
Enable stdout to see the log messages:
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
tao.cmd('sho ele 2');
DEBUG:pytao.tao_ctypes.core:Tao> sho ele 2
Cleanup¶
!rm csr_wake.dat