ess.TraceWin¶
Main description of this module is not written yet
-
class
ess.TraceWin.
density
(filename, envelope=None)[source]¶ Simple class to read a TraceWin density file into a pythonized object
Class afterwards hold the same items as found in the TraceWin documentation: z, nelp, ib, Np, Xouv, Youv, dXouv, ..
-
class
ess.TraceWin.
dst
(filename=None, freq=352.21, mass=938.272, Ib=0.0)[source]¶ Simple class to read in a TraceWin distribution file
Class afterwards hold the following dictionary items: - x [m] - xp [rad] - y [m] - yp [rad] - phi [rad] - E [MeV] (kinetic energy)
-
append
(x=0.0, xp=0.0, y=0.0, yp=0.0, E=0.0, phi=0.0)[source]¶ Append one particle to the distribution
Kinetic Energy in MeV
x,y in m
xp,yp in rad
phi in rad
-
append_many
(array)[source]¶ Append a matrix of particle vectors.
Matrix on form 6xN, where N is number of particles. Each row should hold [x,xp,y,yp,phi,E] Units m,rad, MeV
-
save
(filename, toutatis=False)[source]¶ Save the distribution file so it can be read by TraceWin again
- Parameters
filename – Name of file
toutatis – Include 7th column of zeros
Stolen from Ryoichi’s func.py (with permission)
-
subplot
(index, x, y=None, nb=100, mask=None, xlim=None, ylim=None, norm=None, **kwargs)[source]¶ Create a subplot histogram similar to TraceWin.
- Parameters
index – The plot index (e.g. 221, 222 etc)
x – The first coordinate
y – [optional] second coordinate if 2D histogram
nb – Number of bins
mask – Optional mask (see example)
xlim – Limit x range in histogram
ylim – Limit y range in 2D histogram
norm – Normalization factor
kwargs – Arguments passed to plt.hist2d, or plt.hist if 1D plot
Example:
import numpy as np from ess import TraceWin from matplotlib import pyplot as plt data = TraceWin.dst('part_dtl1.dst') m = np.where(data['E']>3.5) data.subplot(221, 'x', 'xp', mask=m) data.subplot(222, 'y', 'yp', mask=m) data.subplot(223, 'phi', 'E', mask=m) data.subplot(224, 'x', 'y', mask=m) plt.show()
-
-
class
ess.TraceWin.
envDiag
(filename)[source]¶ Read ENV_diag1.dat file
This contains e.g. the absolute phase at each diag
For now we do not read in all info from the file, so feel free to request or add anything else you would like.
-
class
ess.TraceWin.
envelope
(filename)[source]¶ Read an envelope file Create one by saving envelope data plot to ascii
Example:
from ess import TraceWin from matplotlib import pyplot as plt data = TraceWin.envelope('envelope.txt') print(data.keys()) for key in data: print(key, data.unit(key)) if 'rms_' in key: plt.plot(data['position'], data[key]/max(data[key]), label=f"{key} [{data.unit(key)}]") plt.legend() plt.xlabel(f"Position [{data.unit('position')}]") plt.show()
-
class
ess.TraceWin.
field_map
(filename)[source]¶ Class to read in the field map structures
WARNING: Work in progress!!
-
interpolate
(npoints: tuple, method='cubic')[source]¶ Interpolate the map into a new mesh Each value should be an integer with the number of mesh points in each dimension intervals should be tuple-like with same number of elements as the map dimension, e.g. [0.8,0.8] for 2D Can also be a float if you want same interpolation factor in all planes
method can be ‘linear’, ‘nearest’ or ‘cubic’
-
-
class
ess.TraceWin.
partran
(filename)[source]¶ Read partran1.out files..
This class can also read tracewin.out (same format)
-
class
ess.TraceWin.
plt
(filename, flag_remove_loss=True)[source]¶ Simple class to read in a TraceWin plot file
Class afterwards hold the following dictionary items: - Ne (number of locations) - Np (number of particles) - Ib [A] (beam current) - freq [MHz] - mc2 [MeV] - Nelp [m] (locations)
- each plt[i], where i is element number, holds:
Zgen [cm] (location)
phase0 [deg] (ref phase)
wgen [MeV] (ref energy)
x [array, m]
xp [array, rad]
y [array, m]
yp [array, rad]
phi [array, rad]
E [array, MeV]
l [array] (is lost)
Example:
plt=ess.TraceWin.plt('calc/dtl1.plt') for i in [97,98]: data=plt[i] if data: print(data['x'])
-
calc_avg
()[source]¶ Calculates averages of 6D coordinates at each element, such that e.g. self.avg[“x”] gives average X at each location.
Units: m, rad, MeV
-
calc_minmax
(pmin=5, pmax=95)[source]¶ Calculates min/max values of beam coordinates in percentile, pmin is lower and pmax upper.
Units: cm
-
calc_rel
()[source]¶ Calculates relativistic gamma/beta at each position, based on AVERAGE beam energy (NOT necessarily reference)
-
class
ess.TraceWin.
project
(project_fname=None, settings_fname=None)[source]¶ Read and modify TraceWin project files
Example:
p = project('SPK.ini') for diff in p.compare_to('MEBT.ini'): print(diff) p.set('main:beam1_energy', 89e6) p.save()
-
check_rule
(rule=None, fail_on_err=False, fix_if_possible=False)[source]¶ Validate that we still obey the rule if rule is not given, check all rules
-
compare_to
(other)[source]¶ Compare the settings of this file to a different project file
- Parameters
other – project object, or file path to other project file
-
get_options
(parameter)[source]¶ Get the possible options for parameter as specified in the reference file
-
get_type
(parameter)[source]¶ Get the type of parameter as specified in the reference file
d : double value i : integer value, int:list : integer representing a list selection bool:list : booleans representing a list selection
For int:list and bool:list, recommend to use get_options() to figure out how to set as a user.
-