Using the Zgoubidoo low-level interface¶
Test
Reading Zgoubi output files¶
TODO
-
zgoubidoo.outputs.
read_fai_file
(filename: str = 'zgoubi.fai', path: str = '.') → pandas.core.frame.DataFrame[source]¶ Function to read Zgoubi .fai files.
Reads the content of a Zgoubi .fai file (‘faisceau’, ‘beam’ file) and formats it as a valid Pandas DataFrame with headers.
Example
>>> read_fai_file()
- Parameters
filename – the name of the file
path – the path to the .fai file
- Returns
a Pandas DataFrame with the .fai file content.
- Raises
a FileNotFoundError in case the file is not found. –
-
zgoubidoo.outputs.
read_plt_file
(filename: str = 'zgoubi.plt', path: str = '.') → pandas.core.frame.DataFrame[source]¶ Function to read Zgoubi .plt files.
Reads the content of a Zgoubi .plt file (‘plot’ file) and formats it as a valid Pandas DataFrame with headers.
Notes
each coordinate is converted from the Zgoubi internal unit system onto the SI system. This means, in particular, that the positions are in meters and the angles in mrad.
- The special columns have the following meaning:
LET: one character string (for tagging (groups of) particles)
IREP is an index which indicates a symmetry with respect to the median plane. For instance,
if Z(I + 1) = −Z(I), then normally IREP(I + 1) = IREP(I ). Consequently the coordinates of particle I + 1 will not be obtained from ray-tracing but instead deduced from those of particle I by simple symmetry. This saves on computing time.
Example
>>> read_plt_file()
- Parameters
filename – the name of the file
path – the path to the .plt file
- Returns
a Pandas DataFrame with the .plt file content.
- Raises
a FileNotFoundError in case the file is not found. –
-
zgoubidoo.outputs.
read_srloss_file
(filename: str = 'zgoubi.SRLOSS.out', path: str = '.') → pandas.core.frame.DataFrame[source]¶ Read Zgoubi SRLOSS files to a DataFrame.
Reads the content of a Zgoubi SRLOSS (synchrotron radiation losses) file (produced with SRPrint) and formats it as a valid Pandas DataFrame with headers.
Example
>>> read_srloss_file()
- Parameters
filename – the name of the file
path – the path to the SRLOSS file
- Returns
a Pandas DataFrame with the SRLOSS file content.
- Raises
a FileNotFoundException in case the file is not found. –
-
zgoubidoo.outputs.
read_srloss_steps_file
(filename: str = 'zgoubi.SRLOSS.STEPS.out', path: str = '.') → pandas.core.frame.DataFrame[source]¶ Read Zgoubi SRLOSS STEPS files to a DataFrame.
Reads the content of a Zgoubi SRLOSS STEPS (synchrotron radiation losses for each integration steps) file (produced with SRPrint) and formats it as a valid Pandas DataFrame with headers.
Example
>>> read_srloss_steps_file()
- Parameters
filename – the name of the file
path – the path to the SRLOSS STEPS file
- Returns
a Pandas DataFrame with the SRLOSS STEPS file content.
- Raises
a FileNotFoundException in case the file is not found. –
-
zgoubidoo.outputs.
read_matrix_file
(filename: str = 'zgoubi.MATRIX.out', path: str = '.') → pandas.core.frame.DataFrame[source]¶ Read Zgoubi MATRIX files to a DataFrame.
Reads the content of a Zgoubi matrix file (parent from a Twiss command) and formats it as a valid Pandas DataFrame with headers.
Notes
the resulting DataFrame uses SI units.
Example
>>> read_matrix_file()
- Parameters
filename – the name of the file
path – the path to the zgoubi.MATRIX.out file
- Returns
a Pandas DataFrame with the zgoubi.MATRIX.out file content.
- Raises
a FileNotFoundError in case the file is not found. –
-
zgoubidoo.outputs.
read_optics_file
(filename: str = 'zgoubi.OPTICS.out', path: str = '.') → pandas.core.frame.DataFrame[source]¶ Read Zgoubi OPTICS files to a DataFrame.
Reads the content of a Zgoubi optics file (parent from a Optics) and formats it as a valid Pandas DataFrame with headers.
Notes
the resulting DataFrame uses SI units.
Example
>>> read_optcs_file()
- Parameters
filename – the name of the file
path – the path to the zgoubi.OPTICS.out file
- Returns
a Pandas DataFrame with the zgoubi.OPTICS.out file content.
- Raises
a FileNotFoundError in case the file is not found. –
Computing Twiss parameters¶
Step-by-step computation of the transfer matrix and Twiss parameters from Zgoubi tracks.
The functions in this module perform a first-order analysis of the dynamics, via the computation of the transfer matrix and its parametrizations.
The standard uncoupled Twiss parametrization (including off-momentum effects, aka. dispersion) is the default option.
Additional formalisms for the parametrization of fully coupled transfer matrices are also available (Teng, Ripken, etc.).
Example
import numpy as np import pandas as pd import zgoubidoo from zgoubidoo.commands import * _ = zgoubidoo.ureg
-
zgoubidoo.twiss.
compute_transfer_matrix
(beamline: zgoubidoo.input.Input, tracks: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame[source]¶ Constructs the step-by-step transfer matrix from tracking data (finite differences). The approximation uses the O(3) formula (not just the O(1) formula) and therefore makes use of all the 11 particles.
- Parameters
beamline – the Zgoubidoo Input beamline
tracks – tracking data
- Returns
a Panda DataFrame representing the transfer matrix
Example
Here is a typical example to call
compute_transfer_matrix
:>>> tracks = zgoubidoo.read_plt_file() >>> zi = zgoubidoo.Input() >>> matrix = zgoubidoo.twiss.compute_transfer_matrix(zi, tracks)