plot module
Define a library to produce all these nice plots.
When adding you own presets, do not forget to add them to the list of
implemented plots IMPLEMENTED_PLOTS.
Todo
better detection of what is a multiparticle simulation and what is not. Currently looking for “‘partran’: 0” in the name of the solver, making the assumption that multipart is the default. But it depends on the .ini… update: just use .is_a_multiparticle_simulation
Todo
Fix when there is only one accelerator to plot.
Todo
Different plot according to dimension of FieldMap, or according to if it accelerates or not (ex when quadrupole defined by a field map)
- factory(accelerators: Sequence[Accelerator], plots: dict[str, bool], **kwargs: bool) list[Figure]
Create all the desired plots.
- _plot_preset(str_preset: str, *args: Accelerator, x_axis: str = 'z_abs', all_y_axis: list[str] | None = None, save_fig: bool = True, **kwargs: bool | str | int) Figure
Plot a preset.
- Parameters:
str_preset (str) – Key of PLOT_PRESETS.
*args (Accelerator) – Accelerators to plot. In typical usage, args = (Working, Fixed) (previously: (Working, Broken, Fixed). Useful to reimplement?)
x_axis (str, optional) – Name of the x axis. The default is ‘z_abs’.
all_y_axis (list[str] | None, optional) – Name of all the y axis. The default is None.
save_fig (bool, optional) – To save Figures or not. The default is True.
**kwargs (bool | str | int) – Holds all complementary data on the plots.
- _proper_kwargs(preset: str, kwargs: dict[str, bool]) dict[str, bool | int | str]
Merge dicts, priority kwargs > PLOT_PRESETS > FALLBACK_PRESETS.
- _keep_colors(axe: Axes) dict[str, str]
Keep track of the color associated with each SimulationOutput.
- _single_simulation_data(axis: str, simulation_output: SimulationOutput) list[float] | None
lightwin.Get single data array from single SimulationOutput.
- _single_simulation_all_data(x_axis: str, y_axis: str, simulation_output: SimulationOutput) tuple[ndarray, ndarray, dict | None]
Get x data, y data, kwargs from a SimulationOutput.
- _single_accelerator_all_simulations_data(x_axis: str, y_axis: str, accelerator: Accelerator) tuple[list[ndarray], list[ndarray], list[dict[str, Any]]]
Get x_data, y_data, kwargs from all SimulationOutputs of Accelerator.
- _all_accelerators_data(x_axis: str, y_axis: str, *accelerators: Accelerator) tuple[list[ndarray], list[ndarray], list[dict[str, Any]]]
Get x_data, y_data, kwargs from all Accelerators (<=> for 1 subplot).
- _avoid_similar_labels(plt_kwargs: list[dict]) list[dict]
Append a number at the end of labels in doublons.
- _error_calculation_function(y_axis: str) tuple[Callable[[ndarray, ndarray], ndarray], str]
Set the function called to compute error.
- _compute_error(x_data: list[ndarray], y_data: list[ndarray], plt_kwargs: dict[str, int | bool | str], fun_error: Callable[[ndarray, ndarray], ndarray]) tuple[list[ndarray], list[ndarray]]
Compute error with proper reference and proper function.
- _make_a_subplot(axe: Axes, x_axis: str, y_axis: str, colors: dict[str, str] | None, *accelerators: Accelerator, plot_section: bool = True, symetric_plot: bool = False, **kwargs: bool | int | str) None
Get proper data and plot it on an Axe.
- create_fig_if_not_exists(axnum: int | list[int], sharex: bool = False, num: int = 1, clean_fig: bool = False, **kwargs: bool | str | int) tuple[Figure, list[Axes]]
Check if figures were already created, create it if not.
- Parameters:
axnum (int | list[int]) – Axes indexes as understood by fig.add_subplot or number of desired axes.
sharex (bool, optional) – If x axis should be shared. The default is False.
num (int, optional) – Fig number. The default is 1.
clean_fig (bool, optional) – If the previous plot should be erased from Figure. The default is False.
- _autoscale_based_on(axx: Axes, to_ignore: str) None
Rescale axis, ignoring Lines with to_ignore in their label.
- plot_pty_with_data_tags(ax, x, y, idx_list, tags=True)
Plot y vs x.
Data at idx_list are magnified with bigger points and data tags.
- _plot_structure(elts: ListOfElements, ax: Axes, x_axis: str = 'z_abs') None
Plot structure of the linac under study.
- _plot_aperture(aperture: Aperture, x_0: float, width: float) Rectangle
Add a thin line to show an aperture.
- _plot_drift(drift: Drift, x_0: float, width: float) Rectangle
Add a little rectangle to show a drift.
- _plot_field_map(field_map: FieldMap, x_0: float, width: float) Ellipse
Add an ellipse to show a field_map.
- _plot_quad(quad: Quad, x_0: float, width: float) Polygon
Add a crossed large rectangle to show a quad.
- _plot_section(linac, ax, x_axis='z_abs')
Add light grey rectangles behind the plot to show the sections.
- _compute_ellipse_parameters(d_eq)
Compute the ellipse parameters so as to plot the ellipse.
- plot_ellipse(axx, d_eq, **plot_kwargs)
Perform the proper ellipse plotting.
- plot_ellipse_emittance(axx, accelerator, idx, phase_space='w')
Plot the emittance ellipse and highlight interesting data.
- plot_fit_progress(hist_f, l_label, nature='Relative')
Plot the evolution of the objective functions w/ each iteration.