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)
- ALLOWED_PLOT_PRESETS = [ 'acceptance', 'cav', 'emittance', 'energy', 'envelopes', 'mismatch_factor', 'phase', 'transfer_matrices', 'twiss']
List of implemented presets for the plots
- factory(accelerators, plots, save_fig=True, clean_fig=True, fault_scenarios=None, **kwargs)[source]
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.
save_fig (
bool, default:True) – If Figures should be saved.clean_fig (
bool, default:True) – If Figures should be cleaned between two calls of this function.fault_scenarios (
Sequence[list[Fault]] |None, default:None) – If provided, the position of theObjectivewill also appear on plots.kwargs – Other tables from the
TOMLconfiguration file.
- Return type:
- Returns:
The created figures.
- _separate_plot_presets_from_plot_modificators(plots)[source]
Separate the config entries corresponding to the name of a plot.
- Parameters:
plots (
dict[str,Any]) – Dictionary holding the plot configuration.- Return type:
- Returns:
plot_presets (dict[str, bool]) – Subset of
plots, with only the keys that can be found inALLOWED_PLOT_PRESETS. Indicates which plots presets will be plotted:"cav","emittance"…plot_kwargs (dict[str, Any]) – Subset of
plots, with only the keys corresponding to a plot modificator, eg"add_objectives".
- _plot_preset(preset, *args, all_y_axis, x_axis='z_abs', save_fig=True, clean_fig=True, add_objectives=False, fault_scenarios=None, usr_kwargs=None, get_kwargs=None, symmetric_plot=False, **kwargs)[source]
Plot a preset.
- Parameters:
str_preset – Key of
ALLOWED_PLOT_PRESETS.*args (
Accelerator) – Accelerators to plot. In typical usage,args = (Working, Fixed)x_axis (
Literal['z_abs','elt_idx'], default:'z_abs') – Name of the x axis.all_y_axis (
list[Literal['beam_parameters','element_to_index','elt_idx','phi_s','set_of_cavity_settings','synch_trajectory','v_cav_mv','z_abs'] |Literal['alpha_phiw','beta_phiw','envelope_energy_phiw','envelope_pos_phiw','eps_phiw','eps_no_normalization_phiw','eps_normalized_phiw','gamma_phiw','sigma_phiw','twiss_phiw','alpha_phiw99','beta_phiw99','envelope_energy_phiw99','envelope_pos_phiw99','eps_phiw99','eps_no_normalization_phiw99','eps_normalized_phiw99','gamma_phiw99','sigma_phiw99','twiss_phiw99','alpha_t','beta_t','envelope_energy_t','envelope_pos_t','eps_t','eps_no_normalization_t','eps_normalized_t','gamma_t','sigma_t','twiss_t','alpha_x','beta_x','envelope_energy_x','envelope_pos_x','eps_x','eps_no_normalization_x','eps_normalized_x','gamma_x','sigma_x','twiss_x','alpha_x99','beta_x99','envelope_energy_x99','envelope_pos_x99','eps_x99','eps_no_normalization_x99','eps_normalized_x99','gamma_x99','sigma_x99','twiss_x99','alpha_y','beta_y','envelope_energy_y','envelope_pos_y','eps_y','eps_no_normalization_y','eps_normalized_y','gamma_y','sigma_y','twiss_y','alpha_y99','beta_y99','envelope_energy_y99','envelope_pos_y99','eps_y99','eps_no_normalization_y99','eps_normalized_y99','gamma_y99','sigma_y99','twiss_y99','alpha_z','beta_z','envelope_energy_z','envelope_pos_z','eps_z','eps_no_normalization_z','eps_normalized_z','gamma_z','sigma_z','twiss_z','alpha_zdelta','beta_zdelta','envelope_energy_zdelta','envelope_pos_zdelta','eps_zdelta','eps_no_normalization_zdelta','eps_normalized_zdelta','gamma_zdelta','sigma_zdelta','twiss_zdelta'] |Literal['alpha','beta','beta_kin','envelope_energy','envelope_pos','eps','eps_no_normalization','eps_normalized','gamma','gamma_kin','sigma','twiss','z_abs'] |Literal['phiw','phiw99','t','x','x99','y','y99','z','zdelta'] |Literal['beta','gamma','phi_abs','synchronous','w_kin','z_in'] |Literal['e_mev','e_rest_mev','f_bunch_mhz','i_milli_a','q_adim','sigma','inv_e_rest_mev','gamma_init','omega_0_bunch','lambda_bunch','q_over_m','m_over_q'] |Literal['cumulated','individual','n_points','r_xx','r_yy','r_zdelta','r_zz','r_zdelta_11','r_zdelta_12','r_zdelta_21','r_zdelta_22'] |Literal['struct']]) – Name of all the y axis.save_fig (
bool, default:True) – To save Figures or not.add_objectives (
bool, default:False) – To add the position of objectives to the plots; if True, thefault_scenariosmust be provided.fault_scenarios (
Sequence[list[Fault]] |None, default:None) – To plot the objectives, ifadd_objectives == True.usr_kwargs (
dict[str,Any] |None, default:None) – User-definedkwargs, passed to thematplotlib.axes.Axes.plot()method.get_kwargs (
dict[str,bool] |None, default:None) – Keyword arguments for theSimulationOutput.get()methods.symmetric_plot (
bool, default:False) – If plot should be symmetric.**kwargs – Holds all complementary data on the plots.
preset (
str)clean_fig (
bool, default:True)
- Return type:
- _proper_kwargs(preset, kwargs)[source]
Merge dicts, priority kwargs > PLOT_PRESETS > FALLBACK_PRESETS.
We also add a
"usr_kwargs"key holding additional keywords, that will be passed tomatplotlib.axes.Axes.plot().
- _make_a_subplot(axe, x_axis, y_axis, colors, *accelerators, plot_section=True, symmetric_plot=False, get_kwargs=None, **usr_kwargs)[source]
Get proper data and plot it on an Axe.
- Parameters:
axe (
Axes) – Object on which to add plot data.x_axis (
Literal['z_abs','elt_idx']) – Nature of x axis.y_axis (
Literal['beam_parameters','element_to_index','elt_idx','phi_s','set_of_cavity_settings','synch_trajectory','v_cav_mv','z_abs'] |Literal['alpha_phiw','beta_phiw','envelope_energy_phiw','envelope_pos_phiw','eps_phiw','eps_no_normalization_phiw','eps_normalized_phiw','gamma_phiw','sigma_phiw','twiss_phiw','alpha_phiw99','beta_phiw99','envelope_energy_phiw99','envelope_pos_phiw99','eps_phiw99','eps_no_normalization_phiw99','eps_normalized_phiw99','gamma_phiw99','sigma_phiw99','twiss_phiw99','alpha_t','beta_t','envelope_energy_t','envelope_pos_t','eps_t','eps_no_normalization_t','eps_normalized_t','gamma_t','sigma_t','twiss_t','alpha_x','beta_x','envelope_energy_x','envelope_pos_x','eps_x','eps_no_normalization_x','eps_normalized_x','gamma_x','sigma_x','twiss_x','alpha_x99','beta_x99','envelope_energy_x99','envelope_pos_x99','eps_x99','eps_no_normalization_x99','eps_normalized_x99','gamma_x99','sigma_x99','twiss_x99','alpha_y','beta_y','envelope_energy_y','envelope_pos_y','eps_y','eps_no_normalization_y','eps_normalized_y','gamma_y','sigma_y','twiss_y','alpha_y99','beta_y99','envelope_energy_y99','envelope_pos_y99','eps_y99','eps_no_normalization_y99','eps_normalized_y99','gamma_y99','sigma_y99','twiss_y99','alpha_z','beta_z','envelope_energy_z','envelope_pos_z','eps_z','eps_no_normalization_z','eps_normalized_z','gamma_z','sigma_z','twiss_z','alpha_zdelta','beta_zdelta','envelope_energy_zdelta','envelope_pos_zdelta','eps_zdelta','eps_no_normalization_zdelta','eps_normalized_zdelta','gamma_zdelta','sigma_zdelta','twiss_zdelta'] |Literal['alpha','beta','beta_kin','envelope_energy','envelope_pos','eps','eps_no_normalization','eps_normalized','gamma','gamma_kin','sigma','twiss','z_abs'] |Literal['phiw','phiw99','t','x','x99','y','y99','z','zdelta'] |Literal['beta','gamma','phi_abs','synchronous','w_kin','z_in'] |Literal['e_mev','e_rest_mev','f_bunch_mhz','i_milli_a','q_adim','sigma','inv_e_rest_mev','gamma_init','omega_0_bunch','lambda_bunch','q_over_m','m_over_q'] |Literal['cumulated','individual','n_points','r_xx','r_yy','r_zdelta','r_zz','r_zdelta_11','r_zdelta_12','r_zdelta_21','r_zdelta_22'] |Literal['struct']) – What to plot.colors (
dict[str,tuple[float,float,float] |str|tuple[float,float,float,float] |tuple[tuple[float,float,float] |str,float] |tuple[tuple[float,float,float,float],float]] |None) – Holds the line labels from previous plots and associate it to their colors.accelerators (
Accelerator) – Objects from which we takey_axis.plot_section (
bool, default:True) – To outline the different sections in the background of the plots.symmetric_plot (
bool, default:False) – If a symmetric plot (wrt x axis) should be added.get_kwargs (
dict[str,bool] |None, default:None) – Keyword arguments for theSimulationOutput.get()method.usr_kwargs – User-defined
kwargs, passed to thematplotlib.axes.Axes.plot()method.
- Return type: