plot module

Define a library to produce all these nice 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, Any], save_fig: bool = True, clean_fig: bool = True, fault_scenarios: Sequence[list[Fault]] | None = None, **kwargs) list[Figure]

Create all the desired plots.

Parameters:
  • accelerators (Sequence[Accelerator]) – The accelerators holding relatable data. Due to bad implementation, the following accelerators are expected: - Reference linac, first solver - Reference linac, second solver - Fixed linac, first solver - Fixed linac, second solver If you provide only the two first linacs, the function will still work but they will be plotted twice.

  • plots (dict[str, Any]) – The plot TOML table.

  • save_fig (bool, optional) – If Figures should be saved; the default is True.

  • clean_fig (bool) – If Figures should be cleaned between two calls of this function; the default is True.

  • fault_scenarios (Sequence[FaultScenario] | None, optional) – If provided, the position of the Objective will also appear on plots.

  • kwargs – Other tables from the TOML configuration file.

Returns:

The created figures.

Return type:

list[matplotlib.figure.Figure]

_separate_plot_presets_from_plot_modificators(plots: dict[str, Any]) tuple[dict[str, Any], dict[str, Any]]

Separate the config entries corresponding to the name of a plot.

_plot_preset(preset: str, *args: Accelerator, all_y_axis: list[str], x_axis: Literal['z_abs', 'elt_idx'] = 'z_abs', save_fig: bool = True, clean_fig: bool = True, add_objectives: bool = False, fault_scenarios: Sequence[list[Fault]] | None = None, **kwargs) Figure

Plot a preset.

Parameters:
  • str_preset (str) – Key of PLOT_PRESETS.

  • *args (Accelerator) – Accelerators to plot. In typical usage, args = (Working, Fixed)

  • x_axis (str, optional) – Name of the x axis. The default is ‘z_abs’.

  • all_y_axis (list[str]) – Name of all the y axis.

  • save_fig (bool, optional) – To save Figures or not. The default is True.

  • add_objectives (bool, optional) – To add the position of objectives to the plots; if True, the fault_scenarios must be provided.

  • fault_scenarios (Sequence[FaultScenario] | None, optional) – To plot the objectives, if add_objectives == True.

  • **kwargs – Holds all complementary data on the plots.

_proper_kwargs(preset: str, kwargs: dict[str, Any]) dict[str, Any]

Merge dicts, priority kwargs > PLOT_PRESETS > FALLBACK_PRESETS.

_keep_colors(axe: Axes) dict[object, tuple[float, float, float] | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float]]

Keep track of the color associated with each SimulationOutput.

_y_label(y_axis: str) str

Set the proper y axis label.

_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: Literal['z_abs', 'elt_idx'], y_axis: str, simulation_output: SimulationOutput) tuple[ndarray, ndarray, dict[str, Any]]

Get x data, y data, kwargs from a SimulationOutput.

_single_accelerator_all_simulations_data(x_axis: Literal['z_abs', 'elt_idx'], 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: Literal['z_abs', 'elt_idx'], 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, Any], 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: Literal['z_abs', 'elt_idx'], y_axis: str, colors: dict[str, str] | None, *accelerators: Accelerator, plot_section: bool = True, symetric_plot: bool = False, **kwargs) None

Get proper data and plot it on an Axe.

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.