attractor Module

This is the main module which contains all methods necessary for generation of the attractor coordinates and also the visualization of those attractors.

Main module for attractors package

attractors.attractor.THEMES

Contains theme palettes. Loaded from data/themes.json file.

Type

dict

attractors.attractor.case_convert(snakecase_string: str) str[source]

Converts snake case string to pascal string

Parameters

snakecase_string (str) – snakecase string

Returns

Pascal string

Return type

str

class attractors.attractor.Attractor(attractor: str, **kwargs)[source]

Bases: DES

Attractor class inherits from DES. It sets default arguments and handles the plotting and animation for both multipoint and gradient types.

attr

Attractor name

Type

str

init_coord

Initial coordinate for the attractor

Type

List[float]

params

Parameters of the attractor

Type

Mapping[str, float]

bgcolor = None

Background color in hex

Type

str

palette = None

Color palette for plotting. Takes either list of hex values or matplotlib cmap

Type

Union[str,List[str]]

cmap = None

matplotlib.cmap) Matplotlib color map for figure (from palette)

fig = None

Matplotlib figure instance for Attractors class

Type

matplotlib.figure.Figure

ax = None

Matplotlib axes instance for Attractors class

Type

mpl_toolkits.mplot3d.Axes3D

__init__(attractor: str, **kwargs)[source]

Constructor for Attractors class

Parameters
  • attractor (str) – Attractor name

  • **kwargs – See below

Examples

A basic example for constructing an Attractors instance for “Lorenz”

>>> attr = Attractor("lorenz", sigma = 5, rho = 28.5, init_coord = [0.2,0.1,0.1])
Keyword Arguments
  • init_coord (List[float]) – Initial coordinate for the attractor. Defaults to values from :mod:attractors.utils.data

  • params (Mapping[str, float]) – Parameters of the attractor. Defaults to values from :mod:attractors.utils.data

static list_themes() dict[source]

Static method to get themes as a JSON structured dict

Returns

JSON structured dict of all themes

Return type

dict

static list_des() List[str][source]

Static method to get list of iterative ODE solvers that are available

Returns

List of iterative ODE solvers

Return type

List[str]

static list_attractors() List[str][source]

Static method to get list of attractors that are implemented in the package

Returns

List of attractors

Return type

List[str]

static list_params(attr: str) List[str][source]

Static method to get the parameters for a given attractor

Parameters

attr (str) – Attractor name

Returns

List of possible parameters

Return type

List[str]

classmethod set_theme(theme: Optional[dict], bgcolor: Optional[str], palette: Optional[Union[str, List[str]]])[source]

Class method that sets the background color and color palette for the matplotlib figure either via a theme or manually. If both theme and manual arguments are given, the manual arguments take precedence

Parameters
  • theme (dict, optional) – Theme palette in dict format containing colors and their respective hex values. Defaults to None.

  • bgcolor (str, optional) – Background color in hex. Defaults to None.

  • palette (Union[str,List[str]], optional) – Color palette in matplotlib cmap or list of hex values. Defaults to None.

classmethod set_figure(width: float, height: float, dpi: float)[source]

Class method to set figure size and dpi, and also set the background color and palette based on the current class attributes of the same name.

Note

set_theme() must be called before this function

Parameters
  • width (float) – Width of the figure in inches

  • height (float) – Height of the figure in inches

  • dpi (float) – The resolution of the figure in dots-per-inch

Raises

ValueError – When background color is NoneType or when palette is NoneType

classmethod set_limits(xlim: Tuple[float, float], ylim: Tuple[float, float], zlim: Tuple[float, float])[source]

Class method to set figure limits for all 3 dimensions.

Parameters
  • xlim (Tuple[float, float]) – X-axis limits for the figure

  • ylim (Tuple[float, float]) – Y-axis limits for the figure

  • zlim (Tuple[float, float]) – Z-axis limits for the figure

classmethod set_animate_multipoint(*objs: Iterator[DES], **kwargs)[source]

Class method to set the animation for multipoint

Parameters
  • *objs – Variable length list of generators which yield DES

  • **kwargs – See below

Keyword Arguments
  • linekwargs (dict) – Kwargs for matplotlib line plot for lines plotted in the figure. Defaults to {}

  • pointkwargs (dict) – Kwargs for matplotlib line plot for markers plotted in the figure. Defaults to {}

  • elevationrate (float) – Rate of change of elevation angle in animation per frame. Defaults to 0.005

  • azimuthrate (float) – Rate of change of azimuth angle in animation per frame. Defaults to 0.05

Returns

instance of the class

Return type

Attractor

classmethod set_animate_gradient(obj: Iterator[DES], **kwargs)[source]

Class method to set the animation for gradient

Parameters
  • obj – Generator which yields DES

  • **kwargs – See below

Keyword Arguments
  • linekwargs (dict) – Kwargs for matplotlib line plot for lines plotted in the figure. Defaults to {}

  • pointkwargs (dict) – Kwargs for matplotlib line plot for markers plotted in the figure. Defaults to {}

  • elevationrate (float) – Rate of change of elevation angle in animation per frame. Defaults to 0.005

  • azimuthrate (float) – Rate of change of azimuth angle in animation per frame. Defaults to 0.05

  • gradientaxis (str) – Axis along which color gradient is applied. Defaults to “Z”

Returns

instance of the class

Return type

Attractor

classmethod animate(**kwargs) Optional[FuncAnimation][source]

Classmethod that animates the figure after setting the animation parameters

Example

Following example returns an FuncAnimation instance

>>> inst = Attractor("dequan_li").rk3(0, 10, 10000)
>>> x = Attractor.set_animate_gradient(inst).animate(live = True, show = False)

Following example saves the animation to output MPEG4 encoded video file

>>> inst = Attractor("dequan_li").rk3(0, 10, 10000)
>>> x = Attractor.set_animate_gradient(inst).animate(outf="dequan_li.mp4")

Note

set_animate_multipoint() or set_animate_gradient(), must be run before running this method.

Keyword Arguments
  • fps (int) – Frames per second for live plot/generated video. Defaults to 60

  • live (bool) – Flag to redirect plotting to FuncAnimation instead of piping to ffmpeg. Defaults to False

  • show (bool) – Flag to call plt.show() instead of returning FuncAnimation if live = True. Defaults to True

  • outf (str) – Filename of output video if generated. Defaults to “output.mp4”

Returns

FuncAnimation instance if kwargs live = True, show = False

Return type

Optional[matplotlib.animation.FuncAnimation]

classmethod plot_gradient(obj: Iterator[DES], **kwargs) Axes3D[source]

Class method to plot the attractor as gradient type

Example

Following example generates a gradient plot at a particular index

>>> inst = Attractor("dequan_li").rk3(0, 10, 10000)
>>> ax = Attractor.plot_gradient(inst, index=8000)
Parameters
  • obj – Generator which yields DES

  • **kwargs – See below

Keyword Arguments
  • index (int) – Index to be plotted. Defaults to the final index plottable

  • linekwargs (dict) – Kwargs for matplotlib line plot for lines plotted in the figure. Defaults to {}

  • pointkwargs (dict) – Kwargs for matplotlib line plot for markers plotted in the figure. Defaults to {}

  • gradientaxis (str) – Axis along which color gradient is applied. Defaults to “Z”

Returns

Axes attribute of Attractor class

Return type

mpl_toolkits.mplot3d.Axes3D

classmethod plot_multipoint(*objs: Iterator[DES], **kwargs) Axes3D[source]

Class method to plot the attractor as multipoint type

Example

Following example generates a gradient plot at a particular index

>>> inst = Attractor("dequan_li").rk3(0, 10, 10000)
>>> ax = Attractor.plot_multipoint(inst, index=8000)
Parameters
  • *objs – Variable length list of generators which yield DES

  • **kwargs – See below

Keyword Arguments
  • index (int) – Index to be plotted. Defaults to the final index plottable

  • linekwargs (dict) – Kwargs for matplotlib line plot for lines plotted in the figure. Defaults to {}

  • pointkwargs (dict) – Kwargs for matplotlib line plot for markers plotted in the figure. Defaults to {}

Returns

Axes attribute of Attractor class

Return type

mpl_toolkits.mplot3d.Axes3D

parser Module

This is the module which wraps the attractors.attractor module, and provides an easy to use CLI. As of v1.3.0, the parser module only supports animations.

attractors.parser.case_convert(snakecase_string)[source]
attractors.parser.cli()[source]

Subpackages