simulation_output module

Define a class to store outputs from different BeamCalculator.

Todo

Do I really need the r_zz_elt key??

Todo

Do I really need z_abs? Envelope1D does not uses it while TraceWin does.

Todo

Transfer matrices are stored in TransferMatrix, but also in BeamParameters.zdelta.

Todo

Maybe the synchronous phase model should appear somewhere in here?

class SimulationOutput(out_folder: Path, is_multiparticle: bool, is_3d: bool, synch_trajectory: ParticleFullTrajectory, cav_params: dict[str, float | None] | None, beam_parameters: BeamParameters, element_to_index: Callable[[str | Element, str | None], int | slice] | None, set_of_cavity_settings: SetOfCavitySettings, transfer_matrix: TransferMatrix | None = None, z_abs: ndarray | None = None, in_tw_fashion: DataFrame | None = None, r_zz_elt: list[ndarray] | None = None)

Bases: object

Store the information produced by a BeamCalculator.

Used for fitting, post-processing, plotting.

Parameters:
  • out_folder (pathlib.Path) – Results folder used by the BeamCalculator that created this.

  • is_multiparticle (bool) – Tells if the simulation is a multiparticle simulation.

  • is_3d (bool) – Tells if the simulation is in 3D.

  • synch_trajectory (ParticleFullTrajectory | None) – Holds energy, phase of the synchronous particle.

  • cav_params (dict[str, float | None] | None) – Holds amplitude, synchronous phase, absolute phase, relative phase of cavities.

  • beam_parameters (BeamParameters | None) – Holds emittance, Twiss parameters, envelopes in the various phase spaces.

  • element_to_index (Callable[[str | Element, str | None], int | slice] | None) – Takes an Element, its name, ‘first’ or ‘last’ as argument, and returns corresponding index. Index should be the same in all the arrays attributes of this class: z_abs, beam_parameters attributes, etc. Used to easily get the desired properties at the proper position.

  • set_of_cavity_settings (SetOfCavitySettings) – The cavity parameters used for the simulation.

  • transfer_matrix (TransferMatrix) – Holds absolute and relative transfer matrices in all planes.

  • z_abs (numpy.ndarray | None, optional) – Absolute position in the linac in m. The default is None.

  • in_tw_fashion (pandas.DataFrame | None, optional) – A way to output the SimulationOutput in the same way as the Data tab of TraceWin. The default is None.

  • r_zz_elt (list[numpy.ndarray] | None, optional) – Cumulated transfer matrices in the [z-delta] plane. The default is None.

out_folder: Path
is_multiparticle: bool
is_3d: bool
synch_trajectory: ParticleFullTrajectory
cav_params: dict[str, float | None] | None
beam_parameters: BeamParameters
element_to_index: Callable[[str | Element, str | None], int | slice] | None
set_of_cavity_settings: SetOfCavitySettings
transfer_matrix: TransferMatrix | None = None
z_abs: ndarray | None = None
in_tw_fashion: DataFrame | None = None
r_zz_elt: list[ndarray] | None = None
__post_init__() None

Save complementary data, such as Element indexes.

__str__() str

Give a resume of the data that is stored.

property beam_calculator_information: Path

Use out_path to retrieve info on BeamCalculator.

has(key: str) bool

Tell if the required attribute is in this class.

We also call the InitialBeamParameters.has(), as it is designed to handle the alias (such as twiss_zdelta <=> zdelta.twiss).

get(*keys: str, to_numpy: bool = True, to_deg: bool = False, elt: Element | str | Collection[Element] | Collection[str] | None = None, pos: Literal['in', 'out'] | None = None, none_to_nan: bool = False, **kwargs: str | bool | None) Any

Shorthand to get attributes from this class or its attributes.

Parameters:
  • *keys (str) – Name of the desired attributes.

  • to_numpy (bool, optional) – If you want the list output to be converted to a np.ndarray. The default is True.

  • to_deg (bool, optional) – To apply np.rad2deg function over every key containing the string.

  • elt (Element | str | Collection[Element] | Collection[str] | None, optional) – If provided, return the attributes only at the considered element(s).

  • pos (Literal["in", "out"] | None, optional) – If you want the attribute at the entry, exit, or in the whole element.

  • none_to_nan (bool, optional) – To convert None to np.nan. The default is False.

  • **kwargs (str | bool | None) – Other arguments passed to recursive getter.

Returns:

out – Attribute(s) value(s).

Return type:

Any

compute_complementary_data(elts: ListOfElements, ref_simulation_output: Self | None = None) None

Compute some other indirect quantities.

Todo

Fix output_data_in_tw_fashion

Parameters:
  • elts (ListOfElements) – Must be a full ListOfElements, containing all the elements of the linac.

  • ref_simulation_output (SimulationOutput | None, optional) – For calculation of mismatch factors. The default is None, in which case the calculation is simply skipped.

pickle(pickler: MyPickler, path: Path | str | None = None) Path

Pickle (save) the object.

This is useful for debug and temporary saves; do not use it for long time saving.

classmethod from_pickle(pickler: MyPickler, path: Path | str) Self

Instantiate object from previously pickled file.

plot(key: str, to_deg: bool = True, grid: bool = True, **kwargs) Axes | ndarray

Plot the key.

__init__(out_folder: Path, is_multiparticle: bool, is_3d: bool, synch_trajectory: ParticleFullTrajectory, cav_params: dict[str, float | None] | None, beam_parameters: BeamParameters, element_to_index: Callable[[str | Element, str | None], int | slice] | None, set_of_cavity_settings: SetOfCavitySettings, transfer_matrix: TransferMatrix | None = None, z_abs: ndarray | None = None, in_tw_fashion: DataFrame | None = None, r_zz_elt: list[ndarray] | None = None) None
_to_deg(val: ndarray | list | float | None) ndarray | list | float | None

Convert the val[key] into deg if it is not None.