Advanced usageĀ¶
InĀ [1]:
Copied!
# Useful for debugging
%load_ext autoreload
%autoreload 2
%pylab --no-import-all inline
%config InlineBackend.figure_format = 'retina'
# Useful for debugging
%load_ext autoreload
%autoreload 2
%pylab --no-import-all inline
%config InlineBackend.figure_format = 'retina'
%pylab is deprecated, use %matplotlib inline and import the required libraries. Populating the interactive namespace from numpy and matplotlib
InĀ [2]:
Copied!
from pytao import Tao, TaoModel, util, run_tao
from pytao.tao_ctypes.evaluate import evaluate_tao
import os
from pytao import Tao, TaoModel, util, run_tao
from pytao.tao_ctypes.evaluate import evaluate_tao
import os
Inititialize TaoĀ¶
InĀ [3]:
Copied!
INPUT_FILE = os.path.expandvars('$ACC_ROOT_DIR/bmad-doc/tao_examples/csr_beam_tracking/tao.init')
assert os.path.exists(os.path.expandvars(INPUT_FILE))
INPUT_FILE = os.path.expandvars('$ACC_ROOT_DIR/bmad-doc/tao_examples/csr_beam_tracking/tao.init')
assert os.path.exists(os.path.expandvars(INPUT_FILE))
run_taoĀ¶
InĀ [4]:
Copied!
M=run_tao(input_file=INPUT_FILE, ploton=True)
M
M=run_tao(input_file=INPUT_FILE, ploton=True)
M
Out[4]:
<pytao.tao_ctypes.core.TaoModel at 0x12f257a90>
evaluate_taoĀ¶
InĀ [5]:
Copied!
res = evaluate_tao(settings={
'space_charge_com:ds_track_step':0.001},
input_file=INPUT_FILE,
run_commands=['set global track_type=beam'],
expressions = ['lat::orbit.x[FF.PIP02A]', 'beam::norm_emit.x[end]'],
ploton=False,
archive_csr_wake=True,
beam_archive_path = '.')
res
res = evaluate_tao(settings={
'space_charge_com:ds_track_step':0.001},
input_file=INPUT_FILE,
run_commands=['set global track_type=beam'],
expressions = ['lat::orbit.x[FF.PIP02A]', 'beam::norm_emit.x[end]'],
ploton=False,
archive_csr_wake=True,
beam_archive_path = '.')
res
Out[5]:
{'lat::orbit.x[FF.PIP02A]': array([0.]), 'beam::norm_emit.x[end]': array([9.99900678e-07]), 'beam_archive': '/Users/chrisonian/Code/GitHub/pytao/docs/examples/bmad_beam_714cb73f154e71df2eaaefe6138224b6.h5'}
InĀ [6]:
Copied!
from pmd_beamphysics import ParticleGroup, particle_paths
from h5py import File
afile = res['beam_archive']
h5 = File(afile, 'r')
ppaths = particle_paths(h5)
ppaths
from pmd_beamphysics import ParticleGroup, particle_paths
from h5py import File
afile = res['beam_archive']
h5 = File(afile, 'r')
ppaths = particle_paths(h5)
ppaths
Out[6]:
['/data/00001/particles/', '/data/00002/particles/', '/data/00003/particles/', '/data/00004/particles/']
Note that csr_wake is in here
InĀ [7]:
Copied!
list(h5)
list(h5)
Out[7]:
['csr_wake', 'data', 'expressions', 'input', 'settings']
InĀ [8]:
Copied!
P = ParticleGroup(h5[ppaths[-1]])
P.plot('delta_t', 'delta_pz', bins=200)
P = ParticleGroup(h5[ppaths[-1]])
P.plot('delta_t', 'delta_pz', bins=200)
InĀ [9]:
Copied!
os.remove(afile)
os.remove(afile)
evaluate examplesĀ¶
InĀ [10]:
Copied!
M.evaluate('lat::orbit.x[end]')
M.evaluate('lat::orbit.x[end]')
Out[10]:
array([0.])
csr_wake diagnostic fileĀ¶
InĀ [11]:
Copied!
from pytao.misc.csr import read_csr_wake_data_h5, process_csr_wake_data
import numpy as np
from pytao.misc.csr import read_csr_wake_data_h5, process_csr_wake_data
import numpy as np
csr_wake is stored in the HDF5 file
InĀ [12]:
Copied!
cdat = read_csr_wake_data_h5(h5)
cdat = read_csr_wake_data_h5(h5)
This is the actual data
InĀ [13]:
Copied!
dat = cdat['3:FF.BEN01']['data']
dat.shape
dat = cdat['3:FF.BEN01']['data']
dat.shape
Out[13]:
(134, 40, 5)
This will process into a more useful form for data analysis.
InĀ [14]:
Copied!
pdat = process_csr_wake_data(cdat)
pdat['s_position']
pdat = process_csr_wake_data(cdat)
pdat['s_position']
Out[14]:
array([0. , 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01 , 0.011, 0.012, 0.013, 0.014, 0.015, 0.016, 0.017, 0.018, 0.019, 0.02 , 0.021, 0.022, 0.023, 0.024, 0.025, 0.026, 0.027, 0.028, 0.029, 0.03 , 0.031, 0.032, 0.033, 0.034, 0.035, 0.036, 0.037, 0.038, 0.039, 0.04 , 0.041, 0.042, 0.043, 0.044, 0.045, 0.046, 0.047, 0.048, 0.049, 0.05 , 0.051, 0.052, 0.053, 0.054, 0.055, 0.056, 0.057, 0.058, 0.059, 0.06 , 0.06 , 0.061, 0.062, 0.063, 0.064, 0.065, 0.066, 0.067, 0.068, 0.069, 0.07 , 0.071, 0.072, 0.073, 0.074, 0.075, 0.076, 0.077, 0.078, 0.079, 0.08 , 0.081, 0.082, 0.083, 0.084, 0.085, 0.086, 0.087, 0.088, 0.089, 0.09 , 0.091, 0.092, 0.093, 0.094, 0.095, 0.096, 0.097, 0.098, 0.099, 0.1 , 0.101, 0.102, 0.103, 0.104, 0.105, 0.106, 0.107, 0.108, 0.109, 0.11 , 0.111, 0.112, 0.113, 0.114, 0.115, 0.116, 0.117, 0.118, 0.119, 0.12 , 0.121, 0.122, 0.123, 0.124, 0.125, 0.126, 0.127, 0.128, 0.129, 0.13 , 0.131, 0.132, 0.133, 0.134, 0.135, 0.136, 0.137, 0.138, 0.139, 0.14 , 0.141, 0.142, 0.143, 0.144, 0.145, 0.146, 0.147, 0.148, 0.149, 0.15 , 0.151, 0.152, 0.153, 0.154, 0.155, 0.156, 0.157, 0.158, 0.159, 0.16 , 0.161, 0.162, 0.163, 0.164, 0.165, 0.166, 0.167, 0.168, 0.169, 0.17 , 0.171, 0.172, 0.173, 0.174, 0.175, 0.176, 0.177, 0.178, 0.179, 0.18 , 0.181, 0.182, 0.183, 0.184, 0.185, 0.186, 0.187, 0.188, 0.189, 0.19 , 0.191, 0.192, 0.193, 0.193, 0.194, 0.195, 0.196, 0.197, 0.198, 0.199, 0.2 , 0.201, 0.202, 0.203, 0.204, 0.205, 0.206, 0.207, 0.208, 0.209, 0.21 , 0.211, 0.212, 0.213, 0.214, 0.215, 0.216, 0.217, 0.218, 0.219, 0.22 , 0.221, 0.222, 0.223, 0.224, 0.225, 0.226, 0.227, 0.228, 0.229, 0.23 , 0.231, 0.232, 0.233, 0.234, 0.235, 0.236, 0.237, 0.238, 0.239, 0.24 , 0.241, 0.242, 0.243, 0.244, 0.245, 0.246, 0.247, 0.248, 0.249, 0.25 , 0.251, 0.252, 0.253, 0.254, 0.255, 0.256, 0.257, 0.258, 0.259, 0.26 , 0.261, 0.262, 0.263, 0.263, 0.264, 0.265, 0.266, 0.267, 0.268, 0.269, 0.27 , 0.271, 0.272, 0.273, 0.274, 0.275, 0.276, 0.277, 0.278, 0.279, 0.28 , 0.281, 0.282, 0.283, 0.284, 0.285, 0.286, 0.287, 0.288, 0.289, 0.29 , 0.291, 0.292, 0.293, 0.294, 0.295, 0.296, 0.297, 0.298, 0.299, 0.3 , 0.301, 0.302, 0.303, 0.304, 0.305, 0.306, 0.307, 0.308, 0.309, 0.31 , 0.311, 0.312, 0.313, 0.314, 0.315, 0.316, 0.317, 0.318, 0.319, 0.32 , 0.321, 0.322, 0.323, 0.324, 0.325, 0.326, 0.327, 0.328, 0.329, 0.33 , 0.331, 0.332, 0.333, 0.334, 0.335, 0.336, 0.337, 0.338, 0.339, 0.34 , 0.341, 0.342, 0.343, 0.344, 0.345, 0.346, 0.347, 0.348, 0.349, 0.35 , 0.351, 0.352, 0.353, 0.354, 0.355, 0.356, 0.357, 0.358, 0.359, 0.36 , 0.361, 0.362, 0.363, 0.364, 0.365, 0.366, 0.367, 0.368, 0.369, 0.37 , 0.371, 0.372, 0.373, 0.374, 0.375, 0.376, 0.377, 0.378, 0.379, 0.38 , 0.381, 0.382, 0.383, 0.384, 0.385, 0.385, 0.386, 0.387, 0.388, 0.389, 0.39 , 0.391, 0.392, 0.393, 0.394, 0.395, 0.396, 0.397, 0.398, 0.399, 0.4 , 0.401, 0.402, 0.403, 0.404, 0.405, 0.406, 0.407, 0.408, 0.409, 0.41 , 0.411, 0.412, 0.413, 0.414, 0.415, 0.416, 0.417, 0.418, 0.419, 0.42 , 0.421, 0.422, 0.423, 0.424, 0.425, 0.426, 0.427, 0.428, 0.429, 0.43 , 0.431, 0.432, 0.433, 0.434, 0.435, 0.436, 0.437, 0.438, 0.439, 0.44 , 0.441, 0.442, 0.443, 0.444, 0.445])
InĀ [15]:
Copied!
from pytao.misc.csr_plot import plot_csr_wake, plot_csr_stats
from pytao.misc.csr import csr_wake_stats_at_step
from pytao.misc.csr_plot import plot_csr_wake, plot_csr_stats
from pytao.misc.csr import csr_wake_stats_at_step
InĀ [16]:
Copied!
from ipywidgets import interact
def plot1(step=0):
plot_csr_wake(pdat, step=step)
nstep = len(pdat['z'])
interact(plot1, step=(0, nstep-1, 1) )
from ipywidgets import interact
def plot1(step=0):
plot_csr_wake(pdat, step=step)
nstep = len(pdat['z'])
interact(plot1, step=(0, nstep-1, 1) )
interactive(children=(IntSlider(value=0, description='step', max=449), Output()), _dom_classes=('widget-interaā¦
Out[16]:
<function __main__.plot1(step=0)>
Check the s-position for each step
InĀ [17]:
Copied!
plt.plot(pdat['s_position'], marker='.')
plt.plot(pdat['s_position'], marker='.')
Out[17]:
[<matplotlib.lines.Line2D at 0x156dcf670>]
Another convenience plot
InĀ [18]:
Copied!
plot_csr_stats(pdat)
plot_csr_stats(pdat)
(450, 4)
Cleanup
InĀ [19]:
Copied!
!rm csr_wake.dat
!rm csr_wake.dat