utils module

Collection of utility functions for sapphireppplot.

sapphireppplot.utils.get_results_folder(path_prefix='', results_folder='', message='Input path to results folder')

Prompts the user to specify the path to a results folder.

If the script from command line with arguments it uses the first argument as the results folder path. Otherwise, it prompts the user to input the path manually.

Parameters:
  • path_prefix (str) – Prefix for relative path. Note that relative path and environment variables are evaluated on the executing machine. Avoid relative path if you are connected to a data server with client-side execution.

  • results_folder (str) – The path to the results folder.

  • message (str) – Message to be prompted for input.

Return type:

str

Returns:

results_folder (str) – The path to the results folder.

sapphireppplot.utils.prm_to_dict(prm_lines)

Convert parameter file to a dict.

Parameters:

prm_lines (list[str]) – List of line in the parameter file.

Return type:

Dict[str, Any]

Returns:

prm_dict (ParamDict) – Dictionary representing the parameter file structure. Values are always given as strings. Subsections are given as dicts.

sapphireppplot.utils.match_index(list_in, target)

Find index i where list_in[i] = target.

Parameters:
  • list_in (Sequence[Any]) – List/array of values to search.

  • target (Any) – Target value to find.

Return type:

int

Returns:

index (int) – Index i.

Raises:

ValueError – Raises an error if the target can not be found in list_in or multiple matches exist.

sapphireppplot.utils.find_closest_index(array, target, print_index=False)

Find closest index i to array[i] = target in a sorted array.

Parameters:
  • array (Sequence[Any] | ndarray) – Sorted array of values to search.

  • target (Any) – Target value to find.

  • print_index (bool) – Print the found index and match to the console?

Return type:

int

Returns:

index (int) – Index i.

sapphireppplot.utils.sapphirepp_colors()

Get a list of six colors in the Sapphire++ design for line plots.

Thanks to Thibault Vieu for selecting the colors!

Return type:

list[tuple[float, float, float] | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float]]

Returns:

sapphirepp_colors – A list of six colors in the Sapphire++ design.

sapphireppplot.utils.colorblind_colors()

Get a list of colorblind friendly colors for line plots.

Uses the seaborn colorblind color palette, see seaborn documentation.

Return type:

list[tuple[float, float, float] | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float]]

Returns:

sapphirepp_colors – A list of ten colorblind friendly colors.

sapphireppplot.utils.set_matplotlib_style(style='notebook', font_scale=1.0, color_palette='colorblind', disable_tex=False, custom_rc=None)

Set matplotlib.rcParams according to a style.

This can be used to set the style for a specific journal.

Parameters:
  • style (Literal['notebook', 'MNRAS', 'beamerposter_A0']) –

    Style of to use.

    • notebook: Style optimised for Jupyter notebooks

    • MNRAS: Style for MNRAS article

    • beamerposter_A0: Style for A0 sized beamerposter

  • font_scale (float) – Scaling factor for the font in titles, labels and legends.

  • color_palette (Union[Literal['colorblind', 'sapphirepp'], list[tuple[float, float, float] | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float]]]) –

    Color pallet to use for line colors.

  • disable_tex (bool) – Some styles use LaTeX to render text. This can lead to rendering errors if no working LaTeX installation is provided or required packages are missing. To avoid this isse, you can disable LaTeX rendering. Note however, that this can drastically alter the style.

  • custom_rc (Optional[dict[str, Any]]) – Custom overwrite of rcParams, applied after scaling.

Return type:

None

See also

sapphireppplot.plot_properties.PlotProperties.set_style

Set style for ParaView plots.