Plotting

Plot Corrector Strengths

Plots the calculated corrector strengths.

ir_amplitude_detuning.plotting.correctors.get_corrector_strengths(folder: Path, beam: int, id_: str, corrector_pattern: str) pd.Series[source]

Get the corrector strengths for a given beam, id and corrector pattern.

Parameters:
  • folder (Path) -- The folder containing the data.

  • beam (int) -- The beam number (to select the right output files).

  • id (str) -- The id of the data (target name).

  • corrector_pattern (str) -- The corrector pattern to match.

Returns:

The corrector strengths KNL values.

Return type:

pd.Series

ir_amplitude_detuning.plotting.correctors.get_labels(field: FieldComponent, rescale: int = 0) tuple[str, str][source]

Generate the y-axis label for the plot.

Parameters:
  • field (FieldComponent) -- The field component.

  • rescale (int, optional) -- The rescaling factor for the y-axis.

ir_amplitude_detuning.plotting.correctors.get_settings_file(folder: Path, beam: int, id_: str) Path[source]

Return the settings file for a given beam and id.

Parameters:
  • folder (Path) -- The folder containing the data.

  • beam (int) -- The beam number (to select the right output files).

  • id (str) -- The id of the data (target name).

Returns:

The settings file.

Return type:

Path

ir_amplitude_detuning.plotting.correctors.pair_correctors(correctors: Sequence[str]) dict[str, dict[str, str]][source]

Returns a dictionary of ips with a dictionary left and right correctors. Assumes per IP and side there is only one corrector given and does not distinguish between corrector types.

Parameters:

correctors (Sequence[str]) -- The correctors to pair.

Returns:

The dictionary of ips with a dictionary left and right correctors.

Return type:

dict[str, dict[str, str]]

ir_amplitude_detuning.plotting.correctors.plot_correctors(folder: Path, beam: int, ids: dict[str, str] | Iterable[str], field: FieldComponent, corrector_pattern: str = '.*', **kwargs)[source]

Plot the corrector strengths for a given beam and corrector pattern.

Parameters:
  • folder (Path) -- The folder containing the data.

  • beam (int) -- The beam number (to select the right output files).

  • ids (dict[str, str] | Iterable[str]) -- The ids to plot (from the targets). Use a dictionary to specify labels.

  • field (str) -- The field of the used correctors, e.g. “a6” for K6SL.

  • corrector_pattern (str, optional) -- The corrector pattern to match, in case you don’t want all correctors to be plotted.

Keyword Arguments:
  • style (str) -- The plot style to use.

  • manual_style (dict) -- Dictionary of matplotlib style settings.

  • lim (float) -- The y-axis limit.

  • rescale (int) -- Exponent of the scaling factor. (e.g. 3 to give data in units of 10^3, which multiplies the data by 10^-3) Default: 3.

  • ncol (int) -- The number of columns in the figure.

  • plot_styles (Iterable[Path | str]) -- The plot styles to use.

Detuning Plots

Plotting utilities to compare detuning measurements and simulation results.

class ir_amplitude_detuning.plotting.detuning.PlotSetup(label: str, measurement: DetuningMeasurement | Detuning | None, simulation: Detuning | DetuningMeasurement | None = None, color: str = None)[source]

Container to define different detuning measurements to plot with the plot_measurements function.

Parameters:
  • label (str) -- Label for the measurement.

  • measurement (DetuningMeasurement | Detuning | None) -- Measurement to plot. Is expected, but can be None if you only want to plot simulation results.

  • simulation (Detuning | DetuningMeasurement | None) -- Simulation results to plot, corresponding to the given measurement. Is expected to be a Detuning object, so without errors, but can be given as DetuningMeasurement instead, yet the errors will be ignored.

  • color (str, optional) -- Color for the measurement.

ir_amplitude_detuning.plotting.detuning.get_average(measurement_setup: PlotSetup, terms: Sequence[str], method: str = 'auto') tuple[MeasureValue | float, str][source]

Calculate the average of the measurements.

Parameters:
  • measurement_setup (MeasurementSetup) -- The measurements to average.

  • terms (Sequence[str]) -- The terms to average.

  • method (str) -- The average method to use.

ir_amplitude_detuning.plotting.detuning.get_handles_labels(measurements: Sequence[PlotSetup]) tuple[list[Line2D], list[str]][source]

Generate the handles and labels for the legend based on the given measurements.

Parameters:

measurements (Sequence[MeasurementSetup]) -- The measurements to plot.

ir_amplitude_detuning.plotting.detuning.get_measured_detuning_terms(measurements: Sequence[PlotSetup], terms: Sequence[str]) list[str][source]

Get all terms for which at least one measurement has a value.

Parameters:

measurements (Sequence[MeasurementSetup]) -- The setups to check.

ir_amplitude_detuning.plotting.detuning.get_ylabel(rescale: int = 0, delta: bool = False) str[source]

Generate a y-axis label for the plot.

Parameters:
  • rescale (int, optional) -- The rescaling factor for the y-axis.

  • delta (bool, optional) -- Indicate if the data is a “detuning shift” e.g. difference between two setups; adds a “Delta” prefix.

ir_amplitude_detuning.plotting.detuning.plot_measurements(setups: Sequence[PlotSetup], **kwargs)[source]

Plot multiple measurements on the same plot.

Parameters:

measurements (Sequence[MeasurementSetup]) -- List of MeasurementSetup objects to plot.

Keyword Arguments:
  • style (str) -- The plot style to use.

  • manual_style (dict) -- Dictionary of matplotlib style settings.

  • is_shift (bool) -- Indicate if the given data is a “detuning shift” e.g. difference between two setups. This simply adds a “Delta” prefix to the y-axis label, if no label is given.

  • ylim (Sequence[float, float]) -- y-axis limits.

  • rescale (int) -- Exponent of the scaling factor. (e.g. 3 to give data in units of 10^3, which multiplies the data by 10^-3) Default: 3.

  • ncol (int) -- Number of columns in the plot.

  • transpose_legend (bool) -- Transpose the legend order.

  • terms (Sequence[str]) -- Terms to plot.

  • measured_only (bool) -- Only plot terms for which at least one measurement has a value.

  • average (bool | str) -- Add an average values to the plot, Can be “rms”, “weighted_rms”, “mean”, “weighted_mean”. The default for True is “weighted_rms”. Default: False.

ir_amplitude_detuning.plotting.detuning.plot_value_or_measurement(ax: Axes, measurement: MeasureValue | float, x: float, label: str = None, color: str = None) Line2D | ErrorbarContainer[source]

Plots an errorbar if the given measurement has an error, otherwise a simple point.

Parameters:
  • ax (Axes) -- The axes to plot on.

  • measurement (MeasureValue | float) -- The measurement to plot.

  • x (float) -- The x-position of the measurement.

  • label (str, optional) -- Label for the measurement.

  • color (str, optional) -- Color for the measurement.

General Plotting Utilities

This module contains general utilities to help with the plotting.

class ir_amplitude_detuning.plotting.utils.OtherColors[source]

Other predefined colors.

ir_amplitude_detuning.plotting.utils.get_color_for_field(field: FieldComponent)[source]

Get predefined colors for the fields.

ir_amplitude_detuning.plotting.utils.get_color_for_ip(ip: str)[source]

Get predefined colors for the IPs.

ir_amplitude_detuning.plotting.utils.get_default_scaling(term: FirstOrderTerm | SecondOrderTerm) tuple[int, float][source]

Get the default scaling factor for a detuning term.

Parameters:

term (str) -- Detuning term, e.g. “X02”

Returns:

(exponent, scaling)

Return type:

tuple[int, float]

ir_amplitude_detuning.plotting.utils.get_full_target_labels(targets: Sequence[Target], suffixes: Sequence[str] | None = None, rescale: float = 3) dict[str, str][source]

Get a latex label that includes values of all detuning terms, so that they can be easily compared. This is useful to plot the results of multiple targets on the same figure, without having to invent confusing labels. Instead you can just use the target detuning values that went into the correction. It ignores constraints and only the first target_data is used - otherwise the labels would be too long. Extra information can be added via the suffixes.

Parameters:
  • targets (Sequence[Target]) -- List of Target objects to get labels for.

  • suffixes (Sequence[str] | None) -- List of suffixes to add to the labels.

  • rescale (float) -- Exponent of the scaling factor. (e.g. 3 to give data in units of 10^3, which multiplies the data by 10^-3) Default: 3.

Returns:

Dictionary of labels for each target identified by its name.

Return type:

dict[str, str]