SimulationFramework.Modules.Beams package

Subpackages

Submodules

SimulationFramework.Modules.Beams.astra module

cdist(a, b)[source]
convert_csrtrackfile_to_astrafile(self, csrtrackfile, astrafile)[source]
create_ref_particle(self, array, index=0, subtractmean=False)[source]
find_nearest_vector(self, nodes, node)[source]
interpret_astra_data(self, data, normaliseZ=False, keepLost=False)[source]
read_astra_beam_file(self, filename, normaliseZ=False, keepLost=False)[source]
read_csrtrack_beam_file(self, filename)[source]
read_csv_file(self, filename, delimiter=' ')[source]
read_pacey_beam_file(self, filename, charge=2.5e-10)[source]
rms(self, x, axis=None)[source]
write_astra_beam_file(self, filename=None, index=None, status=5, charge=None, normaliseZ=False)[source]
Parameters:
  • filename (Optional[str])

  • index (Optional[int])

  • status (int)

  • charge (Optional[float])

  • normaliseZ (bool)

write_csv_file(self, filename, data)[source]

SimulationFramework.Modules.Beams.gdf module

read_gdf_beam_file(self, filename=None, position=None, time=None, charge=None, longitudinal_reference='t', gdfbeam=None)[source]
read_gdf_beam_file_info(self, file)[source]
read_gdf_beam_file_object(self, file)[source]
write_gdf_beam_file(self, filename=None, normaliseX=False, normaliseZ=False, cathode=False, charge=None, mass=None)[source]
Parameters:
  • filename (Optional[str])

  • normaliseX (bool)

  • normaliseZ (bool)

  • cathode (bool)

SimulationFramework.Modules.Beams.hdf5 module

read_HDF5_beam_file(self, filename, local=False)[source]
rotate_beamXZ(self, theta, preOffset=[0, 0, 0], postOffset=[0, 0, 0])[source]
unrotate_beamXZ(self)[source]
write_HDF5_beam_file(self, filename, centered=False, mass=9.1093837015e-31, sourcefilename=None, pos=None, rotation=None, longitudinal_reference='t', xoffset=0, yoffset=0, zoffset=0, toffset=0, cathode=False)[source]
write_HDF5_summary_file(filename, beams=[], clean=False)[source]

SimulationFramework.Modules.Beams.mad8 module

read_tfs(tfs_file_path, index=None)[source]

Parses the TFS table present in tfs_file_path and returns a dictionary. :type tfs_file_path: str :param tfs_file_path: Path object to the output TFS file. :type tfs_file_path: str :type index: Optional[str] :param index: Name of the column to set as index. If not given, looks in tfs_file_path

for a column starting with INDEX&&&.

Returns:

Dictionary object.

read_tfs_beam_file(self, fileName, charge=None)[source]
set_beam_charge(self, charge)[source]
write_mad8_beam_file(self, filename)[source]

Save a mad8 beam file using multiple START commands.

SimulationFramework.Modules.Beams.ocelot module

read_ocelot_beam_file(self, filename)[source]
write_ocelot_beam_file(self, filename=None, write=True)[source]

Save an npz file for ocelot.

Parameters:
  • filename (Optional[str])

  • write (bool)

SimulationFramework.Modules.Beams.plot module

density_plot(particle_group, key='x', bins=None, filename=None, **kwargs)[source]

1D density plot. Also see: marginal_plot

Example

density_plot(P, ‘x’, bins=100)

marginal_plot(particle_group, key1='t', key2='p', bins=None, units=['', ''], scale=[1, 1], subtract_mean=[False, False], cmap=None, limits=None, filename=None, **kwargs)[source]

Density plot and projections

Example

marginal_plot(P, ‘t’, ‘energy’, bins=200)

plot(self, keys=None, bins=None, type='density', **kwargs)[source]
plotScreenImage(beam, keys=['x', 'y'], scale=[1, 1], iscale=1, colormap=<matplotlib.colors.LinearSegmentedColormap object>, size=None, grid=False, marginals=False, limits=None, screen=False, use_scipy=False, subtract_mean=[False, False], title='', filename=None, **kwargs)[source]
slice_plot(particle_group, xkey='t', ykey='slice_current', xlim=None, nice=True, include_legend=True, subtract_mean=True, bins=None, filename=None, **kwargs)[source]

slice plot. Also see: marginal_plot

Example

slice plot(P, ‘slice_current’, bins=100)

SimulationFramework.Modules.Beams.sdds module

read_SDDS_beam_file(self, fileName, charge=None, ascii=False, page=-1)[source]
set_beam_charge(self, charge)[source]
write_SDDS_file(self, filename=None, ascii=False, xyzoffset=[0, 0, 0])[source]

Save an SDDS file using the SDDS class.

Parameters:

filename (Optional[str])

SimulationFramework.Modules.Beams.vsim module

read_vsim_h5_beam_file(self, filename, charge=7e-11, interval=1)[source]
write_vsim_beam_file(self, file, normaliseT=False)[source]

Module contents

Simframe Beams Module

This module defines the base class and utilities for representing particle beams and groups of beams.

Each beam consists of particles (see Particles), represented in 6-dimensional phase space (x, cpx, y, cpy, z, cpz).

Functions are provided to read/write the particle distribution from a range of simulation codes.

The beamGroup class is used for loading and analysing a group of beam distributions, for example from a directory.

Classes:
  • beam: Generic container for a particle beam.

  • beamGroup: Container for a group of particle beams.

  • particlesGroup: Container for a group of particle distributions.

class beam(*args: Any, **kwargs: Any)[source]

Bases: BaseModel

Class describing a particle distribution. The distribution is contained in the beam or Particles property of this class (see Particles).

Additional results from analysis of the beam are contained in the following properties:

  • sigmas – average beam properties,

see sigmas.

see centroids.

  • centroids – various emittance calculations,

see emittance.

  • kde – kernel density estimator,

see kde.

  • mve – minimum volume ellipse,

see MVE.

  • slices – calculations of slice properties,

see slice.

  • twiss – Twiss parameters,

see twiss.

Functions are also provided for translating the particle distribution from and to HDF5 format (in-house developed or OpenPMD), ASTRA, GPT, OCELOT, or SDDS.

property E0_eV: float

Particle rest mass energy in eV

Returns:

Particle rest mass energy in eV; if already defined, just return the attribute; if not, calculate from the Particles object; if not possible, assume electrons and calculate its rest mass energy

Return type:

float

property Particles: Particles

Property defining the particle distribution

Returns:

The particle distribution

Return type:

Particles

property beam: Particles

Property defining the particle distribution

Returns:

The particle distribution

Return type:

Particles

property centroids: centroids

Property defining the beam centroids

Returns:

Beam centroids

Return type:

centroids

code: str | None = None

Code from which the beam distribution was generated

property data: <property object at 0x7d9bef7454e0>

Property defining the particle distribution

Returns:

The particle distribution

Return type:

Particles

property emittance: emittance

Property defining the beam emittances

Returns:

Beam emittance

Return type:

emittance

filename: str | None = None

Name of beam distribution file; if provided on instantiation, load the file into this object

property kde: kde

Property defining the beam kernel density estimator

Returns:

KDE

Return type:

kde

longitudinal_reference: ndarray | str | None = None

Longitudinal reference position for ASTRA-type distributions

property mve: Any

Property defining the beam minimum volume ellipse

Returns:

Beam sigmas

Return type:

normalise_to_ref_particle(array, index=0, subtractmean=False)[source]

Normalise a distribution to the first element in the array (i.e. the ASTRA reference particle)

Parameters:
  • array (np.ndarray) – The array to normalise

  • index (int) – Not in use

  • subtractmean (bool) – If true, subtract the reference particle from the array

Returns:

The normalised array

Return type:

np.ndarray

offset: list | ndarray = [0, 0, 0]

Beam offset from nominal axis [x,y,z]

particle_mass: ndarray | None = None

Particle mass in kg

plot(**kwargs)[source]
plotScreenImage(**kwargs)[source]
q_over_c: UnitValue = 5.344285992678308e-28 C/c

Elementary charge divided by speed of light

read_HDF5_beam_file(*args, **kwargs)[source]

Load in an HDF5-type beam distribution file and update the Particles object.

read_SDDS_beam_file(*args, **kwargs)[source]

Load in an SDDS-type beam distribution file and update the Particles object.

read_astra_beam_file(*args, **kwargs)[source]

Load in an ASTRA-type beam distribution file and update the Particles object.

read_beam_file(filename, run_extension='001')[source]

Load in a beam distribution file and update the Particles object.

Based on the extension in filename, the appropriate function will be called.

Parameters:
  • filename (str) – The name of the file to be loaded

  • run_extension (str) – Run extension for ASTRA-type beam distribution files.

read_gdf_beam_file(*args, **kwargs)[source]

Load in a GDF-type beam distribution file and update the Particles object.

read_ocelot_beam_file(*args, **kwargs)[source]

Load in an OCELOT-type beam distribution file and update the Particles object.

reference_particle: ndarray | None = None

Reference particle for ASTRA-type distributions

resample(npart, **kwargs)[source]

Resample the beam using a kernel density estimator, updating the number of particles. See kde.

Parameters:

npart (int) – Number of particles for the new distribution

Returns:

The resampled beam.

Return type:

beam

reset_dicts()[source]

Clear out the Particles object, removing the distribution from this object.

Return type:

None

rms(x, axis=None)[source]

Calculate the RMS of a distribution

Parameters:
  • x (np.ndarray) – Array from which to calculate the RMS

  • axis (int, optional) – Axis along which to calculate the RMS

Returns:

RMS of the distribution

Return type:

float or np.ndarray

rotate_beamXZ(theta, preOffset=[0, 0, 0], postOffset=[0, 0, 0])[source]
sddsindex: int = 0

Index for SDDS files

set_particle_mass(mass=9.1093837015e-31)[source]

Set the mass of all particles in the distribution by updating particle_mass.

Parameters:

mass (float) – Particle mass in kg

Return type:

None

property sigmas: sigmas

Property defining the beam sigmas

Returns:

Beam sigmas

Return type:

sigmas

property slice: slice

Property defining the beam slice properties

Returns:

Beam slice properties

Return type:

slice

slice_plot(*args, **kwargs)[source]
speed_of_light: UnitValue = 299.792458 Mm/s

Speed of light

starting_position: list | ndarray = [0, 0, 0]

Beam starting position [x,y,z]

theta: float = 0

Horizontal angle of beam distribution

property twiss: twiss

Property defining the beam twiss properties

Returns:

Beam Twiss parameters

Return type:

twiss

unrotate_beamXZ()[source]
write_HDF5_beam_file(*args, **kwargs)[source]

Write out an HDF5-type beam distribution file.

write_SDDS_beam_file(*args, **kwargs)[source]

Write out an SDDS-type beam distribution file.

write_astra_beam_file(*args, **kwargs)[source]

Write out an ASTRA-type beam distribution file.

write_gdf_beam_file(*args, **kwargs)[source]

Write out a GDF-type beam distribution file.

write_mad8_beam_file(*args, **kwargs)[source]

Write out a MAD8-type beam distribution file.

write_ocelot_beam_file(*args, **kwargs)[source]

Write out an OCELOT-type beam distribution file.

class beamGroup(*args: Any, **kwargs: Any)[source]

Bases: BaseModel

Class for grouping together multiple particle distributions. These distributions can be loaded in from a directory, for example, using the function load_directory().

Properties such as the emittance objects for these distributions are stored as properties of the beamGroup.

(see particlesGroup).

add(filename)[source]
beams: Dict = {}

Dictionary containing the beam objects, keyed by (file)name

property centroids
property data
property emittance
getScreen(screen)[source]
getScreens()[source]
property kde
property mve
param(param)[source]
sddsindex: int = 0

Index for SDDS files

property sigmas
property slice
sort(key='z', function='mean', *args, **kwargs)[source]
property twiss
get_properties(obj)[source]
load_HDF5_summary_file(filename)[source]
load_directory(directory='.', types={'SimFrame': '.hdf5'}, verbose=False)[source]

Load in all beam distribution files from a directory and create a beamGroup object.

Parameters:
  • directory (str) – Directory from which to load the files

  • types (Dict) – Beam distribution file types to load

  • verbose (bool) – If true, print progress

Returns:

A new beamGroup.

Return type:

beamGroup

load_file(filename, *args, **kwargs)[source]

Load in a beam distribution files and create a beam object.

Parameters:

filename (str) – Name of file to load

Returns:

A new beam.

Return type:

beam

class particlesGroup(*args, **kwargs)[source]

Bases: BaseModel

Class for grouping together properties of multiple particle distributions, such as the emittance objects.

Parameters:
  • args (Any)

  • kwargs (Any)

particles: List = None

List of Particles or its sub-classes

save_HDF5_summary_file(directory='.', filename='./Beam_Summary.hdf5', files=None)[source]
Return type:

None

class stats(beam, function)[source]

Bases: object

class statsGroup(beam, function)[source]

Bases: object

Class for grouping together statistical properties of multiple particle distributions.