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: 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, reptis=False)[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.
output_pp_global_cross(pp)[source]

Plot repptis global cross prob 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.
output_pppath(results, path_ensemble)[source]

Plot repptis path results using mpl_plot_pppath().

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

Returns:out (dict) – This dict contains the files created by the plotting.
output_tau(tau, tauerror, bins, tau_ref, tau_ref_bins)[source]

Plot Tau, Tau error, and tau reference histogram.

The parameters for this method is described in mpl_plot_tau() and mpl_plot_tau_ref().

Returns:out (dict) – This dict contains the files created by the plotting.
output_xi(xi, xierror)[source]

Plot Xi and Xi error using mpl_plot_xi().

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

Returns:out (dict) – This dict contains the files created by the plotting.
pyretis.inout.plotting.mpl_plotting._mpl_plot_xy_chunk(axs, series, low=0, high=None, color=None)[source]

Do the actual plotting in chunks for x vs y data.

Parameters:
  • axs (Axes object from matplotlib) – Where to do the plotting.
  • series (dict) – Represents the data to be plotted.
  • low (int, optional) – Lower index to start plotting. low can be negative.
  • high (int, optional) – Index where to end the plotting, this index is not plotted. high is assumed to always be > 0 or None.
  • color (string, optional) – A string representing the color to use.
Returns:

handle (object like matplotlib.lines.Line2D) – A handle for the plotted line.

pyretis.inout.plotting.mpl_plotting._mpl_read_style_file(filename)[source]

Read style files for old versions of matplotlib.

This function is just intended for old versions of matplotlib where we have to read parameters and set them ourselves.

Parameters:filename (string) – This is the matplotlib rc file to open.
Returns:out (None) – Returns None, but modifies matplotlib.rcParams.
pyretis.inout.plotting.mpl_plotting._mpl_shoots_histogram(histograms, ensemble)[source]

Plot the histograms from the shoots analysis.

Parameters:
  • histograms (dict) – These are the histograms obtained in the shoots analysis.
  • ensemble (string) – This is the ensemble identifier, e.g. 001, 002, etc.
Returns:

out (object like matplotlib.backend_bases.FigureCanvasBase) – This is the unscaled histogram.

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.

abstract output_energy(results, energies)[source]

Plot energy results.

abstract output_flux(results)[source]

Plot flux results.

abstract output_matched_probability(path_ensembles, detect, matched)[source]

Plot the overall probability for path ensembles.

abstract output_orderp(results, orderdata)[source]

Plot order parameter results.

abstract 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: 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, reptis=False)[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.

output_pppath(results, path_ensemble)[source]

Output all the results obtained by the repptis 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.

pyretis.inout.plotting.txt_plotting._txt_block_error(outputfile, title, error, backup=False)[source]

Write the output from the error analysis to a text file.

Parameters:
  • outputfile (string) – This is the name of the output file to create.
  • title (string) – This is an identifier/title to add to the header, e.g. ‘Ensemble: 001’, ‘Kinetic energy’, etc.
  • error (list) – This is the result of the error analysis.
  • backup (boolean, optional) – Determines if we will do a backup of old files or not.
pyretis.inout.plotting.txt_plotting._txt_histogram(outputfile, title, histograms, backup=False)[source]

Write histograms to a text file.

Parameters:
  • outputfile (string) – This is the name of the output file to create.
  • title (string) – A descriptive title to add to the header.
  • histograms (tuple or list) – The histograms to store.
  • backup (boolean, optional) – Determines if we will do a backup of old files or not.
pyretis.inout.plotting.txt_plotting._txt_shoots_histogram(outputfile, histograms, scale, ensemble, backup=False)[source]

Write the histograms from the shoots analysis to a text file.

Parameters:
  • histograms (dict) – These are the histograms obtained in the shoots analysis.
  • scale (dict) – These are the scale factors for normalising the histograms obtained in the shoots analysis.
  • ensemble (string) – This is the ensemble identifier, e.g. 001, 002, etc.
  • outputfile (string) – This is the name of the output file to create.
  • backup (boolean, optional) – Determines if we will do a backup of old files or not.