pyaccelerator.utils

Module Contents

Functions

plot_twiss(self) → Tuple[plt.Figure, plt.Axes]

Plot the evolution of twiss parameters through the lattice.

plot_phasespace(self, plane: str = 'both', style: str = 'auto', add_legend: bool = True) → Tuple[plt.Figure, plt.Axes]

Plot the evolution of phase space coordinates through the lattice.

plot_phasespace_distribution(self, plane: str = 'both') → Tuple[plt.Figure, plt.Axes]

Plot the phase space coordinates distribution.

to_v_vec(vec: Sequence[float]) → np.ndarray

Helper function to create 1D vertical arrays.

to_twiss(twiss: Sequence[Union[float, None]]) → np.ndarray

Helper function to create twiss vectors.

to_phase_coord(phase_coord: Sequence[float]) → np.ndarray

Helper function to create phase space coordinate vectors.

complete_twiss(beta: Optional[float] = None, alpha: Optional[float] = None, gamma: Optional[float] = None) → Tuple[float, float, float]

Given 2 twiss parameters, compute the third.

compute_one_turn(list_of_m: Sequence[np.array]) → np.array

Iteratively compute the matrix multiplictions of the arrays in the

compute_twiss_clojure(twiss: Sequence[float]) → float

Compute twiss clojure condition:

compute_m_twiss(m: np.array) → np.array

Compute the twiss transfer matrix from a 2x2 phase space transfer

compute_twiss_solution(transfer_m: np.ndarray, tol: float = 1e-10) → np.ndarray

Compute the periodic twiss solution for the provided transfer matrix.

pyaccelerator.utils.PLANE_INDICES[source]
pyaccelerator.utils.PLANE_SLICES[source]
pyaccelerator.utils.PhasespaceDistribution[source]
pyaccelerator.utils.TransportedTwiss[source]
pyaccelerator.utils.TransportedPhasespace[source]
pyaccelerator.utils.plot_twiss(self) → Tuple[plt.Figure, plt.Axes][source]

Plot the evolution of twiss parameters through the lattice.

Returns

The plotted plt.Figure and plt.Axes.

pyaccelerator.utils.plot_phasespace(self, plane: str = 'both', style: str = 'auto', add_legend: bool = True) → Tuple[plt.Figure, plt.Axes][source]

Plot the evolution of phase space coordinates through the lattice.

Parameters
  • plane – plane of interest, either ‘h’ or ‘v’.

  • style – either ‘s’, ‘phasespace’ or ‘auto’.

  • add_legend – if True will add the s coordinate as the legend when plotting in phasespace.

Returns

The plotted plt.Figure and plt.Axes.

pyaccelerator.utils.plot_phasespace_distribution(self, plane: str = 'both') → Tuple[plt.Figure, plt.Axes][source]

Plot the phase space coordinates distribution.

Parameters

plane – plane of interest, either ‘h’ or ‘v’.

Returns

The plotted plt.Figure and plt.Axes.

pyaccelerator.utils.plot[source]
pyaccelerator.utils.plot[source]
pyaccelerator.utils.plot[source]
pyaccelerator.utils.to_v_vec(vec: Sequence[float]) → np.ndarray[source]

Helper function to create 1D vertical arrays.

Parameters

vec – Vector to convert to vertical array.

Returns

Vertical 1D np.ndarray.

pyaccelerator.utils.to_twiss(twiss: Sequence[Union[float, None]]) → np.ndarray[source]

Helper function to create twiss vectors.

Parameters

twiss – List of length 3, a single twiss parameter can be None.

Returns

Completed vertical 1D twiss parameter np.ndarray.

pyaccelerator.utils.to_phase_coord(phase_coord: Sequence[float]) → np.ndarray[source]

Helper function to create phase space coordinate vectors.

Parameters

phase_coord – List of length 3.

Returns

Vertical 1D np.ndarray.

pyaccelerator.utils.complete_twiss(beta: Optional[float] = None, alpha: Optional[float] = None, gamma: Optional[float] = None) → Tuple[float, float, float][source]

Given 2 twiss parameters, compute the third.

Parameters
  • beta (optional) – Beta function in meters.

  • alpha (optional) – Twiss alpha in radians.

  • gamma (optional) – Twiss gamma in meter^-1.

Returns

Tuple of completes twiss parameters, (beta, alpha, gamma).

pyaccelerator.utils.compute_one_turn(list_of_m: Sequence[np.array]) → np.array[source]

Iteratively compute the matrix multiplictions of the arrays in the provided sequence.

Parameters

list_of_m – Sequence of transfer matrices.

Returns

Result of the iterative matrix multiplication of the matrices.

pyaccelerator.utils.compute_twiss_clojure(twiss: Sequence[float]) → float[source]

Compute twiss clojure condition:

beta * gamma - alpha^2 = 1

Parameters

twiss – List of twiss parameters, [beta[m], alpha[rad], gamma[m]]

Returns

beta * gamma - alpha^2

pyaccelerator.utils.compute_m_twiss(m: np.array) → np.array[source]

Compute the twiss transfer matrix from a 2x2 phase space transfer matrix.

Parameters

m – Phase space transfer matrix.

Returns

Twiss parameter transfer matrix, (3, 3), beta, alpha, gamma.

pyaccelerator.utils.compute_twiss_solution(transfer_m: np.ndarray, tol: float = 1e-10) → np.ndarray[source]

Compute the periodic twiss solution for the provided transfer matrix.

Parameters
  • transfer_m – 3x3 transfer matrix.

  • tol – Numerical tolerance.

Returns

Twiss vector, beta, alpha, gamma.