Utils

A collection of various miscelaneous functionality that helps visualize the profiles and results of convolutions and their numerical values.

lfd.analysis.plotting.utils.plot_profiles(ax, profiles, normed=True, **kwargs)[source]

Normalizes all given profiles and then plots them on a given axis. Set normed to False if normalization is not desired. Lables are determined from the name attribute of the profile. *args and **kwargs are forwarded to the matplotlib plot function.

lfd.analysis.plotting.utils.paperstyle(after_reset=True)[source]

Returns matplotlib style context that uses the same style as was in the paper.

lfd.analysis.plotting.utils.set_ax_props(axes, xlims=(), xticks=(), xlabels=(), ylims=((-0.01, 1.1), ), ylabels=())[source]

Sets the labels, ticks and limits on all pairs of axes, ticks and labels provided.

Parameters:
  • axes (matplotlib.pyplot.Axes) – Axes on which ticks, limits and labels will be set
  • xlims (list or tuple) – Nested list or tuple of x-axis limits of the plots per axis. Default: (,).
  • xticks (list or tuple) – Nested list or tuple of locations at which ticks and tick marks will be placed. Default: (,)
  • xlabels (list, tuple, string or generator expression) – List, tuple or an iterable that provide a label for each of the axes
  • ylims (list or tuple) – Nested list or tuple of y-axis limits of the plots per axis. Default: (-0.01, 1.1).
  • ylabels (list, tuple, string or generator expression) – List, tuple or an iterable that provide a label for each of the axes

Note

Ticks and lims that are shorter than the number of axes will begin repeating themselves untill they match the length of axes. Given ticks and lims NEED to be nested list or tuples (i.e. list of lists, list of tuples, tuple of lists…) in order to work properly. Otherwise only a singular limit can be extracted from them and the limits can not be set properly.

Ticks and lims can be any iterable that supports Python’s multiplication trick (i.e. [1, 2]*2 = [1, 2, 1, 2]). Given ticks and lims that have length zero will not be set.

The labels are expected to always be given for each axis. When only a string is given an attempt will be made to inspect and ascertain which axes are shared and which ones are on the edge of the figure and only those axes will be labeled. This procedure, however, is susceptible to errors - often in situations where additional axes holding colorbars are given. In that situation best course of action is to provide the labels as expected, one for each axis, even when they are all the same.

lfd.analysis.plotting.utils.get_ls()[source]

Function returns the next linestyle from linestyles to help out with graphing in for loops

lfd.analysis.plotting.utils.get_style_path()[source]

Returns the path to the file defining the Matplotlib figure style in the paper.

lfd.analysis.plotting.utils.get_data_dir()[source]

Returns the path to data directory of utils module.

lfd.analysis.plotting.utils.get_data_file(name)[source]

Returns a path to an existing file in the data directory of utils module. If the file doesn’t exist an OSError is raised.

Parameters:name (str) – Name of the desired data file.
Returns:fname – Returns a full data dir path of an existing file.
Return type:str
Raises:error : OSError – File of given name doesn’t exist.
lfd.analysis.plotting.utils.create_data_file_name(name)[source]

Creates a filepath to a file in the data directory of utils module. The file might already exist. To retrieve a filepath to an already existing file use get_data_file.

Parameters:name (str) – Name of the desired data file.
Returns:fpath – Path to a file in the data directory.
Return type:str
lfd.analysis.plotting.utils.get_or_create_data(filenames, samplerKwargs=None, samplers=None, cache=True, **kwargs)[source]

Retrieves data stored in filename(s) or creates the data and stores it at given location(s). If the datafiles are just filenames the files are read and written to lfd’s cache.

Parameters:
  • filenames (list, tuple or str) – Singular or a list of filepath(s) to existing files, or filename(s) of of already cached files.
  • samplerKwargs (list, tuple or dict, optional) – Single or multiple dictionaries to pass to the sampler.
  • samplers (list, function, optional) – Sampler(s) to invoke. By default generic_sampler is used.`
  • cache (bool) – If True, data will be cached if it doesn’t exist already.
  • **kwargs (dict) – Optional. Any keywords are forwarded to the sampler.
Returns:

data – A list of numpy arrays containing the read, or created, data.

Return type:

list

Notes

There is no functional difference between providing a single samplerArgs dictionary or givin the arguments as “plain old” kwargs. When samplerArgs are a list, however, it is iterated over, and each element is passed as a kwarg to the sampler, while kwargs are passed to the sampler as-is on every iteration.