Plotting

class aido.plotting.Plotting[source]

Bases: object

Container for all plotting functions

class FWHM(x: ~numpy.ndarray, y: ~numpy.ndarray, height: ~typing.Annotated[float, <function percentage_type at 0x731c407bf880>] = 0.5)[source]

Bases: object

Class for computing Full Width at Half Maximum (or other height) for a given (x, y) curve.

__init__(x: ~numpy.ndarray, y: ~numpy.ndarray, height: ~typing.Annotated[float, <function percentage_type at 0x731c407bf880>] = 0.5) None[source]

Compute the Full Width Half Maximum for a given mapping of (x, y) values.

Parameters:
  • x (np.ndarray) – X-axis values of the curve

  • y (np.ndarray) – Y-axis values of the curve (must be non-negative)

  • height (Percentage, optional) – Height at which to compute the width, as a fraction of the maximum height. Defaults to 0.5.

add_to_axis(ax: Axes, color: str = 'k', linestyles: str = '--', **kwargs) Axes[source]

Add two vertical lines at the x-intersection to represent the FWHM.

Parameters:
  • ax (matplotlib.pyplot.Axes) – Axes on which to add the vertical lines

  • color (str)

  • linestyles (str)

Returns:

ax (matplotlib.pyplot.Axes)

property values

returns: tuple

  • widthfloat

    Width of the distribution (FWHM) at the specified height (x_right - x_left)

  • x_leftfloat

    x-intersection at the left edge

  • x_rightfloat

    x-intersection at the right edge

  • heightfloat

    Absolute height used for computing the peak

optimizer_loss(results_dir: str = './results/', optimizer_loss_dir: str | PathLike = '/loss/optimizer') DataFrame[source]

Plot the optimizer loss over epochs and save the figure if fig_savepath is provided.

Parameters:
  • fig_savepath (str | os.PathLike | None) (Path to save the figure. If None, the figure will not be saved.)

  • results_dir (str | os.PathLike, optional) (Results directory. Defaults to “./results/”)

  • optimizer_loss_dir (str | os.PathLike) (Directory containing the optimizer loss files.)

Returns:

df_loss (pd.DataFrame) (DataFrame with the optimizer loss at each iteration)

parameter_evolution(results_dir: str = './results/', parameter_dir: str | PathLike = '/parameters/') Tuple[DataFrame, ndarray][source]

Plots the evolution of all simulation parameters along with their respective “sigma”.

Parameters:
  • fig_savepath (str | os.PathLike, optional) (The file path to save the figure.) – Defaults to “<results_dir>/plots/parameter_evolution”. If None, the figure will not be saved.

  • results_dir (str | os.PathLike, optional) (Results directory. Defaults to “./results/”)

  • parameter_dir (str | os.PathLike, optional) (The directory path where the SimulationParameterDictionaries) – are stored (.json files). Defaults to “<results_dir>/parameters”.

Returns:

Tuple(pd.DataFrame, np.ndarray) (A Tuple containing the DataFrame with all parameters provided by the) – optimizer after each iteration, and the simulation sampling standard deviation (2D array).

classmethod plot(plot_types: str | List[str] = 'all', results_dir: str | PathLike = './results/')[source]

Plot the evolution of variables of interest over the Optimization process.

Parameters:

plot_types (str | List[str], optional) (The types of plots to be generated.) – It can be a string or a list of strings. If “all” is specified, it will generate all available plots. Available methods:

[“parameter_evolution”, “optimizer_loss”, “simulation_samples”]

Returns:

None

TODO Clean up this class and do not repeat the reading of files all the time

simulation_samples(results_dir: str = './results/', parameter_dir: str = '/parameters/', sampled_param_dict_filepath: str | PathLike = '/task_outputs/iteration=*/validation=False') Tuple[DataFrame, ndarray][source]

Generate a DataFrame of simulation parameters and their values.

This method collects simulation parameters and their values for each iteration and task, organizing them into a DataFrame.

Parameters:
  • fig_savepath (str or os.PathLike or None, optional) – Path to save the generated plot. Defaults to “./results/plots/simulation_samples”.

  • sampled_param_dict_filepath (str or os.PathLike, optional) – Path to the sampled parameter dictionary files. Defaults to “./results/task_outputs/simulation_task*”.

  • parameter_dir (str, optional) – Where the parameters are stored in the results folder. Defaults to ‘parameters’.

Returns:

  • pd.DataFrame – DataFrame containing the simulation parameters.

  • np.ndarray – Array of sigma values.

Notes

TODO: Check for files dynamically in case b2luigi changes directory names due to changes in the b2luigi.Parameters of the SimulationTasks.

aido.plotting.percentage_type(value: float) float[source]

Checks if a float lies between [0, 1]