pyretis.inout.plotting package

This package contains functions for setting up plotters.

Specifically, it defines colors, color schemes and a function for selecting a plotter.

Here we also hard-code some color schemes which may be useful for the plotting:

  • the colorblind 10 scheme [cb10],
  • the deep color scheme from the seaborn project [deep] and
  • the husl color scheme [husl].

Package structure

Modules

__init__.py
This file. Handles imports for PyRETIS and defines some colors and the method for creating a plotter.
mpl_plotting.py (pyretis.inout.plotting.mpl_plotting)
Methods for generating plots using matplotlib.
plotting.py (pyretis.inout.plotting.plotting)
Definition of a generic base class for the plotter(s).
txt_plotting.py (pyretis.inout.plotting.txt_plotting)
Methods for generating text output.

Important methods defined here

create_plotter (create_plotter())
Method to create a plotter.

Folders

styles
This folder contains style files for matplotlib which are used by PyRETIS.

References

[cb10]The colorblind_10 color scheme, https://jiffyclub.github.io/palettable/tableau/
[deep]The deep color scheme, from the seaborn project http://stanford.edu/~mwaskom/software/seaborn/index.html
[husl]The husl color scheme, http://www.husl-colors.org/
pyretis.inout.plotting.create_plotter(plot_settings, out_dir=None)[source]

Create a plotter from given settings.

The input plot settings is assumed to be a dictionary which we use for creating the plotter. In case the plot settings are not given, we just return None. We are here assuming that they are not given simply because we do not want to create a plotter.

Parameters:
  • plot_settings (dict) – These are the settings to create the plotter from. Here, we look for the keys plotter, output and style which defines the plotter to use, the output format and the style to use.
  • out_dir (string, optional) – This string selects if and where the output should be written to. It’s mainly used for internal purposes to save the report files to a specific directory.
Returns:

out (object like MplPlotter) – This is an object which can be used for plotting.

pyretis.inout.plotting.mpl_plotting module

Functions for generating plots using matplotlib.

This module defines a plotter class for matplotlib and it also defines some standard plots that are used in the analysis.

Important classes defined here

MplPlotter (MplPlotter)
A class for plotting with matplotlib.

Important methods defined here

mpl_set_style (mpl_set_style())
Method for setting the style for the plots, typically used here to load the PyRETIS style.
class pyretis.inout.plotting.mpl_plotting.MplPlotter(out_fmt, backup=False, style=None, out_dir=None)[source]

Bases: pyretis.inout.plotting.plotting.Plotter

A plotter using matplotlib.

This class defines a plotter which makes use of matplotlib and it can be used as a starting point to create other plotters for PyRETIS bases on other tools (e.g. gnuplot etc.).

style

Defines what style to use for the plotting.

Type:string
out_fmt

Selects format for output plots.

Type:string
__init__(out_fmt, backup=False, style=None, out_dir=None)[source]

Initiate, set style and check output format.

Parameters:
  • out_fmt (string) – This is the format to use for the images.
  • backup (boolean, optional) – Determines if we should overwrite or backup old files.
  • style (string, optional) – This selects the style to use, it can be a file path or the string with the style name.
  • out_dir (string, optional) – Determines if we should write the files to a particular directory.
_print_figures_to_file(canvas)[source]

Save figure(s) to file(s).

This function will save figures to files. It will add a file format extension to the files when writing.

Parameters:canvas (dict of matplotlib.backend_bases.FigureCanvasBase) – canvas[key] is assumed to define a figure which we will save to a file with a file name defined by key and the extension defined by self.out_fmt.
Returns:out (dict) – The files written.
output_energy(results, energies)[source]

Plot energy results using mpl_plot_energy().

The parameters for this method is described in mpl_plot_energy().

Returns:out (dict) – This dict contains the files created by the plotting.
output_flux(results)[source]

Plot flux results using py:func:.mpl_plot_flux.

The parameters for this method is described in mpl_plot_flux().

Returns:outputfile (list of dicts) – A list containing the files created for the flux and for the error in the flux.

Note

The returned list is used to plot the figures in pairs.

output_matched_probability(path_ensembles, detect, matched)[source]

Plot matched probabilities using mpl_plot_matched().

The parameters for this method is described in mpl_plot_matched().

Returns:out (dict) – This dict contains the files created by the plotting.
output_orderp(results, orderdata)[source]

Plot order parameter data using mpl_plot_orderp().

The parameters for this method is described in mpl_plot_orderp().

Returns:out (dict) – This dict contains the files created by the plotting.
output_path(results, path_ensemble)[source]

Plot path results using mpl_plot_path().

The parameters for this method is described in mpl_plot_path().

Returns:out (dict) – This dict contains the files created by the plotting.

pyretis.inout.plotting.plotting module

Definition of the base class for the plotter.

This module just defines a base class for plotters. This is just to ensure that all plotters at least implement some functions and that we can make use of them.

Important classes defined here

Plotter (Plotter)
A generic class for creating plots.
class pyretis.inout.plotting.plotting.Plotter(backup=True, plotter_type=None, out_dir=None)[source]

Bases: object

Base class for PyRETIS plotters.

This class defines a plotter. A plotter is just an object that supports certain functions which can be called by analysis output functions. It should define certain plots and the Plotter class is an abstract class just to make sure that all plotters define the needed plots.

backup

Determines if we overwrite old files or try to back them up.

Type:boolean
plotter_type

Defines a name for the plotter, in case we want to identify it.

Type:string
out_dir

Defines an output directory for the plotter.

Type:string, optional
__init__(backup=True, plotter_type=None, out_dir=None)[source]

Initialise the plotting object.

Parameters:
  • backup (boolean, optional) – Determines if we overwrite old files or not.
  • plotter_type (string, optional) – A name for the plotter.
  • out_dir (string, optional) – A string which can be used to set an output directory for the plotter.
__str__()[source]

Print out the basic info.

output_energy(results, energies)[source]

Plot energy results.

output_flux(results)[source]

Plot flux results.

output_matched_probability(path_ensembles, detect, matched)[source]

Plot the overall probability for path ensembles.

output_orderp(results, orderdata)[source]

Plot order parameter results.

output_path(results, path_ensemble)[source]

Plot results for each path ensemble.

pyretis.inout.plotting.txt_plotting module

A class for writing text data for the analysis.

This module defines a text plotter which supports the same method as the generic plotter, however, the output is human-readable text.

Important classes defined here

TxtPlotter (TxtPlotter)
A class for writing text output.
class pyretis.inout.plotting.txt_plotting.TxtPlotter(out_fmt, backup=False, out_dir=None)[source]

Bases: pyretis.inout.plotting.plotting.Plotter

A plotter writing text-based output.

This class will just write text-based output. It is similar to (MplPlotter) in the sense that the same functions are supported. Here, however, we do not plot any figures, we just write a column based text file with the results.

out_fmt

Selects format for output plots.

Type:string
__init__(out_fmt, backup=False, out_dir=None)[source]

Initialise the text writer.

Parameters:
  • out_fmt (string) – This is the format to use for the images.
  • backup (boolean, optional) – Determines if we should overwrite or backup old files.
  • out_dir (string, optional) – Determines if we should write the files to a particular directory.
output_energy(results, energies)[source]

Save the output from the energy analysis to text files.

Parameters:
  • results (dict) – Each item in results contains the results for the corresponding energy. It is assumed to contains the keys ‘vpot’, ‘ekin’, ‘etot’, ‘ham’, ‘temp’, ‘elec’.
  • energies (numpy.array) – This is the raw data for the energy analysis.
Returns:

outfiles (list) – The output files created by this function.

output_flux(results)[source]

Store the output from the flux analysis in text files.

Parameters:results (dict) – This is the dict with the results from the flux analysis.
Returns:outputfile (list of dicts) – A list containing the files created for the flux and for the error in the flux.
output_matched_probability(path_ensembles, detect, matched)[source]

Output the matched probabilities to a text file.

This function will output the matched probabilities for the different ensembles and also output the over-all matched probability.

Parameters:
  • path_ensembles (list of strings) – This is the names for the path ensembles we have calculated the probability for.
  • detect (list of floats) – These are the detect interfaces used in the analysis.
  • matched (dict) – This dict contains the results from the matching of the probabilities. We make use of matched[‘overall-prob’] and matched[‘matched-prob’] here.
Returns:

outfiles (list) – The files created by this function.

output_orderp(results, orderdata)[source]

Save the output from the order parameter analysis to text files.

Parameters:
  • results (dict) – Each item in results contains the results for the corresponding order parameter.
  • orderdata (numpy.array) – This is the raw data for the order parameter analysis
Returns:

outfiles (list) – The output files created by this function.

Note

We are here only outputting results for the first order parameter. I.e. other order parameters or velocities are not written here. This will be changed when the structure of the output order parameter file has been fixed. Also note that, if present, the first order parameter will be plotted against the second one - i.e. the second one will be assumed to represent the velocity here.

output_path(results, path_ensemble)[source]

Output all the results obtained by the path analysis.

Parameters:
  • results (dict) – This dict contains the result from the analysis.
  • path_ensemble (object like PathEnsemble) – This is the path ensemble we have analysed.
Returns:

outfiles (list) – The output files created by this function.