mbtrack2.tracking.monitors.plotting module

Module for plotting the data recorded by the monitor module during the tracking.

plot_beamdata(filenames: str | list[str], dataset: str = 'mean', dimension: str = 'tau', stat_var: str = 'mean', x_var: str = 'time', turn: int | float | None = None, legend: list[str] | None = None, ax: Axes | None = None) Axes[source]

Plot 2D data recorded by BeamMonitor.

Parameters

filenamesstr or list of str

Names of the HDF5 files to be plotted.

dataset{“current”,”emit”,”mean”,”std”,”cs_invariant”}

HDF5 file’s dataset to be plotted. The default is “mean”.

dimensionstr
The dimension of the dataset to plot:

for “emit”, dimension = {“x”,”y”,”s”}, for “cs_invariant”, dimension = {“x”,”y”,”s”}, for “mean” and “std”, dimension = {“x”,”xp”,”y”,”yp”,”tau”,”delta”}. not used if “current”.

The default is “tau”.

stat_var{“mean”, “std”}

Statistical value of the dimension.

x_var{“time”, “index”}
Choice of the horizontal axis:

“time” corresponds to turn number. “index” corresponds to bunch index.

turnint or float, optional

Choice of the turn to plot when x_var = “index”. If None, the last turn is plotted.

legendlist of str, optional

Legend to add for each file.

Returns

axAxes

Axes object with the plot on it.

streak_beamdata(filename: str, dataset: str = 'mean', dimension: str = 'tau', cm_lim: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, ax: Axes | None = None) Axes[source]

Plot 3D data recorded by BeamMonitor.

Parameters

filenamestr

Name of the HDF5 file that contains the data.

dataset{“current”,”emit”,”mean”,”std”,”cs_invariant”}

HDF5 file’s dataset to be plotted. The default is “mean”.

dimensionstr
The dimension of the dataset to plot:

for “emit”, dimension = {“x”,”y”,”s”}, for “cs_invariant”, dimension = {“x”,”y”,”s”}, for “mean” and “std”, dimension = {“x”,”xp”,”y”,”yp”,”tau”,”delta”}. not used if “current”.

The default is “tau”.

cm_limlist [vmin, vmax], optional

Colormap scale for the “streak” plot.

Returns

axAxes

Axes object with the plot on it.

plot_bunchdata(filenames: str | list[str], bunch_number: int | list[int], dataset: str, dimension: str = 'x', legend: list[str] | None = None, ax: Axes | None = None) Axes[source]

Plot data recorded by BunchMonitor.

Parameters

filenamesstr or list of str

Names of the HDF5 files to be plotted.

bunch_numberint or list of int

Bunch to plot. This has to be identical to ‘bunch_number’ parameter in ‘BunchMonitor’ object.

dataset{“current”, “emit”, “mean”, “std”, “cs_invariant”}

HDF5 file’s dataset to be plotted.

dimensionstr, optional

The dimension of the dataset to plot. Use “None” for “current”, otherwise use the following :

for “emit”, dimension = {“x”,”y”,”s”}, for “cs_invariant”, dimension = {“x”,”y”,”s”}, for “mean” and “std”, dimension = {“x”,”xp”,”y”,”yp”,”tau”,”delta”}, for “action”, dimension = {“x”,”y”}.

legendlist of str, optional

Legend to add for each file.

Returns

axAxes

Axes object with the plot on it.

plot_phasespacedata(filename: str, bunch_number: int, x_var: str, y_var: str, turn: int, only_alive: bool = True, plot_size: float = 1, plot_kind: str = 'scatter') Figure[source]

Plot data recorded by PhaseSpaceMonitor.

Parameters

filenamestr

Name of the HDF5 file that contains the data.

bunch_numberint

Bunch to plot. This has to be identical to ‘bunch_number’ parameter in ‘PhaseSpaceMonitor’ object.

x_var, y_varstr {“x”, “xp”, “y”, “yp”, “tau”, “delta”}

If dataset is “particles”, the variables to be plotted on the horizontal and the vertical axes need to be specified.

turnint

Turn at which the data will be extracted.

only_alivebool, optional

When only_alive is True, only alive particles are plotted and dead particles will be discarded.

plot_size[0,1], optional

Number of macro-particles to plot relative to the total number of macro-particles recorded. This option helps reduce processing time when the data is big.

plot_kind{‘scatter’, ‘kde’, ‘hex’, ‘reg’, ‘resid’}, optional

The plot style. The default is ‘scatter’.

Return

figFigure

Figure object with the plot on it.

plot_profiledata(filename: str, bunch_number: int, dimension: str = 'tau', start: int = 0, stop: int | None = None, step: int | None = None, streak_plot: bool = False, ax: Axes | None = None) Axes[source]

Plot data recorded by ProfileMonitor.

Parameters

filenamestr

Name of the HDF5 file that contains the data.

bunch_numberint

Bunch to plot. This has to be identical to ‘bunch_number’ parameter in ‘ProfileMonitor’ object.

dimensionstr, optional

Dimension to plot. The default is “tau”.

startint, optional

First turn to plot. The default is 0.

stopint, optional

Last turn to plot. If None, the last turn of the record is selected.

stepint, optional

Plotting step. This has to be divisible by ‘save_every’ parameter in ‘ProfileMonitor’ object, i.e. step % save_every == 0. If None, step is equivalent to save_every.

streak_plotbool, optional

If True, a streak plot is shown. If False, a profile plot is shown. The default is False.

axAxes, optional

Axes to plot on. If None, a new figure is created.

Returns

axAxes

Axes object with the plot on it.

plot_wakedata(filename: str, bunch_number: int, wake_type: str = 'Wlong', start: int = 0, stop: int | None = None, step: int | None = None, streak_plot: bool = False, bunch_profile: bool = False, dipole: bool = False, ax: Axes | None = None) Axes[source]

Plot data recorded by WakePotentialMonitor.

Parameters

filenamestr

Name of the HDF5 file that contains the data.

bunch_numberint

Bunch to plot. This has to be identical to ‘bunch_number’ parameter in ‘WakePotentialMonitor’ object.

wake_typestr, optional

Wake type to plot: “Wlong”, “Wxdip”, …

startint, optional

First turn to plot. The default is 0.

stopint, optional

Last turn to plot. If None, the last turn of the record is selected.

stepint, optional

Plotting step. This has to be divisible by ‘save_every’ parameter in ‘WakePotentialMonitor’ object, i.e. step % save_every == 0. If None, step is equivalent to save_every.

streak_plotbool, optional

If True, a streak plot is shown. If False, a profile plot is shown. The default is False.

bunch_profilebool, optional

If True, the bunch profile is plotted.

dipolebool, optional

If True, the dipole moment is plotted.

axAxes, optional

Axes to plot on. If None, a new figure is created.

Returns

axAxes

Axes object with the plot on it.

plot_bunchspectrum(filenames: str | list[str], bunch_number: int | list[int], dataset: str = 'incoherent', dim: str = 'tau', turns: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None, fs: float | None = None, log_scale: bool = True, legend: list[str] | None = None, norm: bool = False, ax: Axes | None = None) Axes[source]

Plot coherent and incoherent spectrum data.

Parameters

filenamesstr or list of str

Names of the HDF5 files to be plotted.

bunch_numberint or list of int

Bunch to plot. This has to be identical to ‘bunch_number’ parameter in ‘BunchSpectrumMonitor’ object.

dataset{“mean_incoherent”, “coherent”, “incoherent”, “coherent_q”,

“coherent_s”, “coherent_o”}

HDF5 file’s dataset to be plotted. The default is “incoherent”.

dim{“x”,”y”,”tau”}, optional

The dimension of the dataset to plot. The default is “tau”.

turnsarray or None, optional

Numbers of the turns to plot. If None, all turns are shown. The default is None.

fsfloat or None, optional

If not None, the frequency axis is normalised by fs. The default is None.

log_scalebool, optional

If True, the spectrum plots are shown in y-log scale. The default is True.

legendlist of str, optional

Legend to add for each file. The default is None.

normbool, optional

If True, normalise the data of each spectrum by its geometric mean. The default is False.

Returns

ax : Axes

streak_bunchspectrum(filename: str, bunch_number: int, dataset: str = 'incoherent', dim: str = 'tau', fs: float | None = None, log_scale: bool = True, fmin: float | None = None, fmax: float | None = None, turns: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None, norm: bool = False, ylim: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, ax: Axes | None = None) Axes[source]

Plot 3D data recorded by the BunchSpectrumMonitor.

Parameters

filenamestr

Name of the HDF5 file to be plotted.

bunch_numberint

Bunch to plot. This has to be identical to ‘bunch_number’ parameter in ‘BunchSpectrumMonitor’ object.

dataset{“coherent”, “incoherent”, “coherent_q”, “coherent_s”, “coherent_o”}

HDF5 file’s dataset to be plotted. The default is “incoherent”.

dim{“x”,”y”,”tau”}, optional

The dimension of the dataset to plot. The default is “tau”.

fsfloat or None, optional

If not None, the frequency axis is normalised by fs.

log_scalebool, optional

If True, the spectrum plots are shown in y-log scale. The default is True.

fminfloat, optional

If not None, the plot is limited to values bigger than fmin.

fmaxfloat, optional

If not None, the plot is limited to values smaller than fmax.

turnsarray, optional

If not None, only the turn numbers in the turns array are plotted.

normbool, optional

If True, normalise the data of each spectrum by its geometric mean. The default is False.

ylimarray, optional

If not None, should be array like in the form [ymin, ymax] where ymin and ymax are the minimum and maximum values used in the y axis.

Returns

ax : Axes

plot_beamspectrum(filenames: str | list[str], dim: str = 'tau', turns: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None, f0: float | None = None, log_scale: bool = True, legend: list[str] | None = None, norm: bool = False, ax: Axes | None = None) Axes[source]

Plot coherent beam spectrum data.

Parameters

filenamesstr or list of str

Names of the HDF5 files to be plotted.

dim{“x”,”y”,”tau”}, optional

The dimension of the dataset to plot. The default is “tau”.

turnsarray or None, optional

Numbers of the turns to plot. If None, all turns are shown. The default is None.

f0float or None, optional

If not None, the frequency axis is noramlised by f0. The default is None.

log_scalebool, optional

If True, the spectrum plots are shown in y-log scale. The default is True.

legendlist of str, optional

Legend to add for each file. The default is None.

normbool, optional

If True, normalise the data of each spectrum by its geometric mean. The default is False.

Returns

ax : Axes

streak_beamspectrum(filename: str, dim: str = 'tau', f0: float | None = None, log_scale: bool = True, fmin: float | None = None, fmax: float | None = None, turns: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None, norm: bool = False, ylim: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, ax: Axes | None = None) Axes[source]

Plot 3D data recorded by the BeamSpectrumMonitor.

Parameters

filenamestr

Name of the HDF5 file to be plotted.

dim{“x”,”y”,”tau”}, optional

The dimension of the dataset to plot. The default is “tau”.

f0float or None, optional

If not None, the frequency axis is normalised by f0.

log_scalebool, optional

If True, the spectrum plots are shown in y-log scale. The default is True.

fminfloat, optional

If not None, the plot is limited to values bigger than fmin.

fmaxfloat, optional

If not None, the plot is limited to values smaller than fmax.

turnsarray, optional

If not None, only the turn numbers in the turns array are plotted.

normbool, optional

If True, normalise the data of each spectrum by its geometric mean. The default is False.

ylimarray, optional

If not None, should be array like in the form [ymin, ymax] where ymin and ymax are the minimum and maximum values used in the y axis.

Returns

ax : Axes

plot_cavitydata(filename: str, cavity_name: str, phasor: str = 'cavity', plot_type: str = 'bunch', bunch_number: int = 0, turn: int | None = None, cm_lim: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, show_objective: bool = False, ax: Axes | None = None) Axes[source]

Plot data recorded by CavityMonitor.

Parameters

filenamestr

Name of the HDF5 file that contains the data.

cavity_namestr

Name of the CavityResonator object.

phasorstr, optional

Type of the phasor to plot. Can be “beam”, “cavity”, “generator” or “ig”.

plot_typestr, optional
Type of plot:
  • “bunch” plots the phasor voltage and angle versus time for a

given bunch. - “turn” plots the phasor voltage and angle versus bunch index for a given turn. - “streak_amplitude” plots the phasor amplitude versus bunch index and time. - “streak_angle” plots the phasor angle versus bunch index and time. - “detune” or “psi” plots the detuning or tuning angle versus time. - “power” plots the generator, cavity, beam and reflected power versus time. Needs BeamMonitor data with same save_every as CavityMonitor. - “mean” plots the mean phasor voltage and angle versus time for non-empty bunches. Needs BeamMonitor data with same save_every as CavityMonitor. - “tuner_diff” plots the tuner difference from optimal tuning condition (for a given bunch) and the tuning angle versus time.

bunch_numberint, optional

Bunch number to select. The default is 0.

turnint, optional

Turn to plot. The default is None.

cm_limlist [vmin, vmax], optional

Colormap scale for the “streak” plots.

show_objectivebool, optional

If True, shows the cavity voltage and phase objective value (Vc and theta) in plot type “mean” and “bunch” for “cavity” phasor. The default is False.

axAxes, optional

Axes to plot on. If None, a new figure is created.

Returns

axAxes

Axes object with the plot on it.