ocelot.utils package¶
Submodules¶
ocelot.utils.acc_utils module¶
-
ocelot.utils.acc_utils.
RTU_56
(LB, LD, r, m)¶
-
ocelot.utils.acc_utils.
beam2rf
(E1, chirp, curvature, skewness, n, freq, E0=0.00675, zeta1=0.0, zeta2=0.0, zeta3=0.0)¶ Function calculates RF parameters: cavities (first and high harmonic) voltage [GV] and phase [deg] from the final beam energy, chirp, curvature, skewness.
- Parameters
E1 – the beam energy [GeV] after RF system
chirp – the beam chirp
curvature – the beam curvature
skewness – the beam skewness
n – 3, number of harmonic of the high harmonic cavity. If n = 0 the high harmonic cavity does not exist.
freq – frequency [Hz] of the first harmonic cavity
E0 – initial beam energy [GeV] (from the gun)
zeta1 – initial beam chirp (from the gun)
zeta2 – initial beam curvature (from the gun)
zeta3 – initial beam skewness (from the gun)
- Returns
v1, phi1, vh, phih
-
ocelot.utils.acc_utils.
beam2rf_xfel_linac
(sum_voltage, chirp, init_energy=0.13)¶ wrapped up function for EuXFEL linacs
- Parameters
sum_voltage – in control system [GeV]
chirp – in control system [GeV]
init_energy – for L1 it is 0.13 GeV, L2 = 0.7 GeV
- Returns
v1, phi1
-
ocelot.utils.acc_utils.
bunching
(p_array, lambda_mod, smooth_sigma=None)¶ Function calculates bunching factor for wavelength lambda_mod
$b(lambda) =
rac{1}{N_0}left| langle e^{- i rac{ 2 pi}{lambda} s} N(s) angle ight|$
- param p_array
ParticleArray
- param lambda_mod
wavelength
- param smooth_sigma
smoothing parameter
- return
bunching factor
-
ocelot.utils.acc_utils.
calculate_mismatch
(tws_des, tws_err)¶ Function calculates mismatch and mismatch phase using two twiss lists. Result is saved in tws_err list as M_x, M_y, psi_x, psi_y
- Parameters
tws_des – list, design twiss parameters
tws_err – list, error twiss parameters
- Returns
(Mx, My, phi_x, phi_y) mismatch at the end of lattice
-
ocelot.utils.acc_utils.
chicane_RTU
(yoke_len, dip_dist, r, type)¶ Method calculate R56, T566, U5666 and path length of the reference particle for chicanes ‘s’ and ‘c’ type
- Parameters
yoke_len – dipole yoke length
dip_dist – distance between 1st and 2nd dipoles on Z-axis (not a particle path but projection on Z-axis)
r – radii of the dipoles
type – type of the chicane “s” or “c”
- Returns
R56, T566, U5666, Sref (distance between magnet 2 and 3 is 0)
-
ocelot.utils.acc_utils.
rf2beam
(v1, phi1, vh, phih, n=3, freq=1300000000.0, E0=0.00675, zeta1=0.0, zeta2=0.0, zeta3=0.0)¶ Function calculates beam parameters: the final beam energy, chirp, curvature, skewness, from the RF parameters: voltages and phases. Note: in EuXFEL case, L1: E0 = 130 MeV, to get correct Sum Voltage for L1/L2, E1’ = E1 - E0
- Parameters
v1 – voltage [GeV] of the first harmonic cavity
phi1 – phase [deg] of the first harmonic cavity
vh – voltage [GeV] of the high harmonic cavity
phih – phase [deg] of the high harmonic cavity
n – 3, number of harmonic of the high harmonic cavity. If n = 0 the high harmonic cavity does not exist
freq – frequency [Hz] of the first harmonic cavity
E0 – initial beam energy [GeV] (from the gun)
zeta1 – initial beam chirp (from the gun)
zeta2 – initial beam curvature (from the gun)
zeta3 – initial beam skewness (from the gun)
- Returns
E1, chirp, curvature, skewness
-
ocelot.utils.acc_utils.
rf2beam_xfel_linac
(v, phi, init_energy=0.13)¶ wrapped up function for EuXFEL linacs
- Parameters
v –
phi –
init_energy – for L1 it is 0.13 GeV, L2 = 0.7 GeV
- Returns
-
ocelot.utils.acc_utils.
slice_bunching
(tau, charge, lambda_mod, smooth_sigma=None)¶ Function calculates bunching factor for wavelength lambda_mod
$b(lambda) =
rac{1}{N_0}left| langle e^{- i rac{ 2 pi}{lambda} s} N(s) angle ight|$
- param p_array
ParticleArray
- param lambda_mod
wavelength
- param smooth_sigma
smoothing parameter
- return
bunching factor
ocelot.utils.add_wake module¶
ocelot.utils.create_db module¶
ocelot.utils.db module¶
-
class
ocelot.utils.db.
ActionParameters
(pars)¶ Bases:
object
-
class
ocelot.utils.db.
ActionResult
(pars)¶ Bases:
object
-
class
ocelot.utils.db.
PerfDB
(dbname='flash.db')¶ Bases:
object
-
add_action_parameters
(tuning_id, action_id, param_names, start_vals, end_vals)¶
-
add_machine_parameters
(tuning_id, params)¶
-
close
()¶
-
current_action_id
()¶
-
current_tuning_id
()¶
-
get_action_parameters
(tuning_id, action_id)¶
-
get_actions
(tuning_id=None)¶
-
get_machine_parameters
(tuning_id)¶
-
get_tunings
()¶
-
new_action
(tuning_id, start_sase, end_sase)¶
-
new_tuning
(params)¶
-
-
class
ocelot.utils.db.
Tuning
(pars)¶ Bases:
object
-
ocelot.utils.db.
create_db
(dbname='flash.db')¶
-
ocelot.utils.db.
test_add_action_parameters
(dbname)¶
-
ocelot.utils.db.
test_new_action
(dbname)¶
-
ocelot.utils.db.
test_new_tunings
(dbname)¶
ocelot.utils.launcher module¶
Launches simulations on various remote configurations
-
class
ocelot.utils.launcher.
Launcher
¶ Bases:
object
-
backup
(dir='./')¶
-
cleanAllBut
(dir='./', keepFiles=[])¶
-
-
class
ocelot.utils.launcher.
LocalLauncher
¶ Bases:
ocelot.utils.launcher.Launcher
-
collect
(inputDir, outputDir, pattern='*')¶
-
launch
()¶
-
outputfile
(filename)¶
-
prepare
()¶
-
-
class
ocelot.utils.launcher.
MpiLauncher
¶ Bases:
ocelot.utils.launcher.Launcher
-
collect
(inputDir, outputDir, pattern='*')¶
-
launch
()¶
-
prepare
()¶
-
-
class
ocelot.utils.launcher.
NewLauncher
¶ Bases:
ocelot.utils.launcher.Launcher
for MOGA, tmp?
-
collect
(inputDir, outputDir, pattern='*')¶
-
launch
()¶
-
prepare
()¶
-
-
class
ocelot.utils.launcher.
PollableMpiLauncher
¶ Bases:
ocelot.utils.launcher.Launcher
-
collect
(inputDir, outputDir, pattern='*')¶
-
launch
()¶
-
prepare
()¶
-
-
class
ocelot.utils.launcher.
SshMpiLauncher
¶ Bases:
ocelot.utils.launcher.Launcher
-
collect
(inputDir, outputDir, pattern='*')¶
-
launch
()¶
-
prepare
()¶
-
-
ocelot.utils.launcher.
createId
(prefix)¶
ocelot.utils.mpi_utils module¶
-
ocelot.utils.mpi_utils.
chunks
(lst, nthreads)¶ Divide list into chuncks
- Parameters
lst – list of something
nthreads – number of threads
- Returns
list of list
-
ocelot.utils.mpi_utils.
slicing_p_array
(p_array, SIZE)¶ Divide ParticleArray into chuncks
- Parameters
p_array – ParticleArray
SIZE – number of threads
- Returns
list of ParticleArray
ocelot.utils.section_track module¶
Section class for s2e tracking. S.Tomin. XFEL/DESY. 2017
-
class
ocelot.utils.section_track.
SectionLattice
(sequence, tws0=None, data_dir='.', *args, **kwargs)¶ Bases:
object
High level class to work with SectionTrack()
-
calculate_twiss
(tws0=None)¶ Method calculates twiss parameters for whole lattice [sequence of lattices] and assigns for each section initial Twiss() - section.tws0
- Parameters
tws0 – Twiss() - initial twiss parameters
- Returns
return list of Twiss()
-
init_sections
(*args, **kwargs)¶ Method initiates section and return dictionary with initialized sections
- Returns
self.dict_sections - dictionary
-
initialize
(tws0=None, *args, **kwargs)¶
-
load_twiss_track
(sections)¶
-
track_sections
(sections, p_array, config=None, force_ext_p_array=False, coupler_kick=False, verbose=True)¶
-
update_sections
(sections, config=None, coupler_kick=False)¶
-
-
class
ocelot.utils.section_track.
SectionTrack
(data_dir, *args, **kwargs)¶ Bases:
object
-
add_physics_process
(physics_process, start, stop)¶
-
apply_matching
(bounds=None)¶
-
bc_analysis
()¶
-
change_bc_shoulders
(drift)¶
-
folder_check_create
(filename)¶
-
get_bc_shoulders
()¶
-
get_tws_list
()¶
-
load_twiss_file
()¶
-
read_beam_file
()¶
-
remove_coupler_kicks
()¶
-
save_beam_file
(particles)¶
-
save_twiss_file
(twiss_list)¶
-
tracking
(particles=None)¶
-
update_bunch_compressor
(rho)¶
-
update_cavity
(phi, v)¶
-
-
ocelot.utils.section_track.
normal
(loc=0.0, scale=1.0, size=None)¶ Draw random samples from a normal (Gaussian) distribution.
The probability density function of the normal distribution, first derived by De Moivre and 200 years later by both Gauss and Laplace independently 2, is often called the bell curve because of its characteristic shape (see the example below).
The normal distributions occurs often in nature. For example, it describes the commonly occurring distribution of samples influenced by a large number of tiny, random disturbances, each with its own unique distribution 2.
Note
New code should use the
normal
method of adefault_rng()
instance instead; please see the random-quick-start.- locfloat or array_like of floats
Mean (“centre”) of the distribution.
- scalefloat or array_like of floats
Standard deviation (spread or “width”) of the distribution. Must be non-negative.
- sizeint or tuple of ints, optional
Output shape. If the given shape is, e.g.,
(m, n, k)
, thenm * n * k
samples are drawn. If size isNone
(default), a single value is returned ifloc
andscale
are both scalars. Otherwise,np.broadcast(loc, scale).size
samples are drawn.
- outndarray or scalar
Drawn samples from the parameterized normal distribution.
- scipy.stats.normprobability density function, distribution or
cumulative density function, etc.
Generator.normal: which should be used for new code.
The probability density for the Gaussian distribution is
\[p(x) = \frac{1}{\sqrt{ 2 \pi \sigma^2 }} e^{ - \frac{ (x - \mu)^2 } {2 \sigma^2} },\]where \(\mu\) is the mean and \(\sigma\) the standard deviation. The square of the standard deviation, \(\sigma^2\), is called the variance.
The function has its peak at the mean, and its “spread” increases with the standard deviation (the function reaches 0.607 times its maximum at \(x + \sigma\) and \(x - \sigma\) 2). This implies that normal is more likely to return samples lying close to the mean, rather than those far away.
- 1
Wikipedia, “Normal distribution”, https://en.wikipedia.org/wiki/Normal_distribution
- 2(1,2,3)
P. R. Peebles Jr., “Central Limit Theorem” in “Probability, Random Variables and Random Signal Principles”, 4th ed., 2001, pp. 51, 51, 125.
Draw samples from the distribution:
>>> mu, sigma = 0, 0.1 # mean and standard deviation >>> s = np.random.normal(mu, sigma, 1000)
Verify the mean and the variance:
>>> abs(mu - np.mean(s)) 0.0 # may vary
>>> abs(sigma - np.std(s, ddof=1)) 0.1 # may vary
Display the histogram of the samples, along with the probability density function:
>>> import matplotlib.pyplot as plt >>> count, bins, ignored = plt.hist(s, 30, density=True) >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * ... np.exp( - (bins - mu)**2 / (2 * sigma**2) ), ... linewidth=2, color='r') >>> plt.show()
Two-by-four array of samples from N(3, 6.25):
>>> np.random.normal(3, 2.5, size=(2, 4)) array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
ocelot.utils.sim_gui module¶
ocelot.utils.sim_info module¶
-
class
ocelot.utils.sim_info.
RunInfo
(id)¶ Bases:
object
-
class
ocelot.utils.sim_info.
SimInfo
(n=10)¶ Bases:
object
ocelot.utils.sim_plot module¶
ocelot.utils.wake_pws module¶
Planar wakefield structure S.Tomin, 11.2018
added function which generates wake tables S.Tomin and I.Zagorodnov, 11.2019
-
ocelot.utils.wake_pws.
wake_kick
(p_array, b=0.0005, t=0.00025, p=0.0005)¶ Function to calculate transverse kick by corrugated structure [SLAC-PUB-16881]
- Parameters
p_array – ParticleArray
b – distance to the dechirper wall
t – longitudinal gap
p – period
- Returns
(wake, current) - wake[:, 0] - s in [m], wake[:, 1] - kick in [V] - current[:, 0] - s in [m], current[:, 1] - current in [A]
-
ocelot.utils.wake_pws.
wake_tables
(b=0.0005, a=0.01, width=0.02, t=0.00025, p=0.0005, length=1, sigma=3e-05, filename=None)¶ Function creates two wake tables for horizontal and vertical corrugated plates
- Parameters
b – distance from the plate in [m]
a – half gap between plates in [m]
width – width of the corrugated structure in [m]
t – longitudinal gap in [m]
p – period of corrugation in [m]
length – length of the corrugated structure in [m]
sigma – characteristic longitudinal beam size in [m]]
filename – save to files if filename is not None
- Returns
hor_wake_table, vert_wake_table
ocelot.utils.xfel_utils module¶
functions common to fel decks
-
class
ocelot.utils.xfel_utils.
FelSimulator
¶ Bases:
object
configurable to e.g. semi-empirical models
-
run
()¶
-
-
ocelot.utils.xfel_utils.
checkout_run
(run_dir, run_id, prefix1, prefix2, save=False, debug=1)¶
-
ocelot.utils.xfel_utils.
create_exfel_lattice
(*agrs, **kwargs)¶
-
ocelot.utils.xfel_utils.
create_fel_beamline
(beamline='sase1', inters_phi=0, inters_K='K_und')¶
-
ocelot.utils.xfel_utils.
create_fel_lattice
(und_N=35, und_L=5, und_l=0.04, und_Kx=0, und_Ky=0, inters_L=1.08, inters_K='K_und', inters_phi=0, quad_L=0.4, quad_K=0, phs_L=0.0, quad_start='d', **kwargs)¶
-
ocelot.utils.xfel_utils.
create_fel_lattice_tmp
(und_N=34, und_L=5, und_l=0.04, und_Kx=0, und_Ky=0, inters_L=1.08, inters_K='K_und', inters_phi=0, quad_L=0.1, quad_K=0, phs_L=0.0, quad_start='d', **kwargs)¶
-
ocelot.utils.xfel_utils.
detune_E
(inp, beam, sig)¶
-
ocelot.utils.xfel_utils.
detune_k
(lat, sig)¶
-
ocelot.utils.xfel_utils.
dfl_hxrss_filt
(dfl, trf, s_delay, st_cpl=1, enforce_padn=None, res_per_fwhm=6, fft_method='mp', dump_proj=0, debug=1)¶
-
ocelot.utils.xfel_utils.
dfl_st_cpl
(dfl, theta_b, inp_axis='y', s_start=None)¶
-
ocelot.utils.xfel_utils.
get_data_dir
()¶
-
ocelot.utils.xfel_utils.
prepare_el_optics
(beam, lat_pkg, E_photon=None, beta_av=None, s=None)¶
-
ocelot.utils.xfel_utils.
rematch
(beta_mean, l_fodo, qdh, lat, extra_fodo, beam, qf, qd)¶ requires l_fodo to be defined in the lattice
-
ocelot.utils.xfel_utils.
rematch_beam_lat
(beam, lat_pkg, beta_mean, raise_min_beta=False)¶
-
ocelot.utils.xfel_utils.
save_xhrss_dump_proj
(dump_proj, filePath)¶
-
ocelot.utils.xfel_utils.
tap_exp
(n, n0, a0, a1, a2)¶ exponential tapering
-
ocelot.utils.xfel_utils.
tap_pol
(n, n0, a0, a1, a2)¶ piecewise-quadratic tapering function
-
ocelot.utils.xfel_utils.
tap_pol_old
(n, n0, a0, a1, a2)¶ piecewise-quadratic tapering function
-
ocelot.utils.xfel_utils.
taper
(lat, k)¶
-
ocelot.utils.xfel_utils.
update_beam
(beam_new, g, n_interp)¶ check and rewrite!
Module contents¶
-
ocelot.utils.
chicane_RTU
(yoke_len, dip_dist, r, type)¶ Method calculate R56, T566, U5666 and path length of the reference particle for chicanes ‘s’ and ‘c’ type
- Parameters
yoke_len – dipole yoke length
dip_dist – distance between 1st and 2nd dipoles on Z-axis (not a particle path but projection on Z-axis)
r – radii of the dipoles
type – type of the chicane “s” or “c”
- Returns
R56, T566, U5666, Sref (distance between magnet 2 and 3 is 0)