Table Of Contents

modelicares.multi

Functions to load and plot data from multiple simulation and linearization files at once

  • multiload() - Load multiple Modelica simulation and/or linearization results
  • multiplot() - Plot data from multiple simulations in 2D Cartesian coordinates
  • multibode() - Plot multiple linearizations onto a single Bode diagram
  • multinyquist() - Plot multiple linearizations onto a single Nyquist diagram
modelicares.multi.multibode(lins, axes=None, pair=(0, 0), label='bode', title='Bode Plot', labels='', colors=['b', 'g', 'r', 'c', 'm', 'y', 'k'], styles=[(None, None), (3, 3), (1, 1), (3, 2, 1, 2)], leg_kwargs={}, **kwargs)

Plot multiple linearizations onto a single Bode diagram.

Arguments:

  • lins: Linearization result or list of results (instances of linres.LinRes)

  • axes: Tuple (pair) of axes for the magnitude and phase plots

    If axes is not provided, then axes will be created in a new figure.

  • pair: Tuple of (input index, output index) for the transfer function to be chosen from each system (applied to all)

    This is ignored if the system is SISO.

  • label: Label for the figure (ignored if axes is provided)

    This will be used as the base filename if the figure is saved.

  • title: Title for the figure

  • labels: Label or list of labels for the legends

    If labels is None, then no label will be used. If it is an empty string (‘’), then the base filenames will be used.

  • colors: Color or list of colors that will be used sequentially

    Each may be a character, grayscale, or rgb value.

  • styles: Line/dash style or list of line/dash styles that will be used sequentially

    Each style is a string representing a linestyle (e.g., “–”) or a tuple of on/off lengths representing dashes. Use “” for no line and “-” for a solid line.

  • leg_kwargs: Dictionary of keyword arguments for matplotlib.pyplot.legend()

    If leg_kwargs is None, then no legend will be shown.

  • **kwargs: Additional arguments for control.freqplot.bode()

Returns:

  1. axes: Tuple (pair) of axes for the magnitude and phase plots

Example:

>>> import os

>>> from glob import glob
>>> from modelicares import LinRes, multibode, save, read_params
>>> from numpy import pi, logspace

>>> lins = map(LinRes, glob('examples/PID/*/*.mat'))
>>> labels = ["Ti=%g" % read_params('Ti', os.path.join(lin.dir, 'dsin.txt'))
...           for lin in lins]
>>> multibode(lins,
...           title="Bode Plot of Modelica.Blocks.Continuous.PID",
...           label='examples/PIDs-bode', omega=2*pi*logspace(-2, 3),
...           labels=labels, leg_kwargs=dict(loc='lower right')) 
(<matplotlib.axes...AxesSubplot object at 0x...>, <matplotlib.axes...AxesSubplot object at 0x...>)

>>> save()
Saved examples/PIDs-bode.pdf
Saved examples/PIDs-bode.png
Bode plot of PID with varying parameters
modelicares.multi.multiload(locations='*')

Load multiple Modelica simulation and/or linearization results.

Arguments:

  • locations: Input filename, directory, or list of these

    Wildcards (‘*’) may be used in the path(s).

Returns:

  1. List of simulations (simres.SimRes instances)
  2. List of linearizations (linres.LinRes instances)

Either may be an empty list.

Example:

>>> from modelicares import *

# By file:
>>> multiload(['examples/ChuaCircuit.mat', 'examples/PID/*/*.mat']) 
Valid: SimRes('.../examples/ChuaCircuit.mat')
Valid: LinRes('.../examples/PID/1/dslin.mat')
Valid: LinRes('.../examples/PID/2/dslin.mat')
([SimRes('.../examples/ChuaCircuit.mat')], [LinRes('.../examples/PID/1/dslin.mat'), LinRes('.../examples/PID/2/dslin.mat')])


# By directory:
>>> multiload('examples') 
Valid: SimRes('...ChuaCircuit.mat')
Valid: LinRes('...PID.mat')...
Valid: SimRes('...ThreeTanks.mat')
([SimRes('...ChuaCircuit.mat'), SimRes('...ThreeTanks.mat')], [LinRes('...PID.mat')])
modelicares.multi.multinyquist(lins, ax=None, pair=(0, 0), label='nyquist', title='Nyquist Plot', xlabel='Real Axis', ylabel='Imaginary Axis', labels='', colors=['b', 'g', 'r', 'c', 'm', 'y', 'k'], leg_kwargs={}, **kwargs)

Plot multiple linearizations onto a single Nyquist diagram.

Arguments:

  • lins: Linearization result or list of results (instances of linres.LinRes)

  • ax: Axes onto which the Nyquist diagrams should be plotted

    If ax is not provided, then axes will be created in a new figure.

  • pair: Tuple of (input index, output index) for the transfer function to be chosen from each system (applied to all)

    This is ignored if the system is SISO.

  • label: Label for the figure (ignored if axes is provided)

    This will be used as the base filename if the figure is saved.

  • title: Title for the figure

    • xlabel: x-axis label
    • ylabel: y-axis label
  • labels: Label or list of labels for the legends

    If labels is None, then no label will be used. If it is an empty string (‘’), then the base filenames will be used.

  • colors: Color or list of colors that will be used sequentially

    Each may be a character, grayscale, or rgb value.

  • leg_kwargs: Dictionary of keyword arguments for matplotlib.pyplot.legend()

    If leg_kwargs is None, then no legend will be shown.

  • **kwargs: Additional arguments for control.freqplot.nyquist()

    If textFreq is not specified, then only the frequency points of the first system will have text labels.

Returns:

  1. ax: Axes of the Nyquist plot

Example:

>>> import os

>>> from glob import glob
>>> from modelicares import LinRes, multinyquist, save, read_params
>>> from numpy import pi, logspace

>>> lins = map(LinRes, glob('examples/PID/*/*.mat'))
>>> labels = ["Td=%g" % read_params('Td', os.path.join(lin.dir, 'dsin.txt'))
...           for lin in lins]
>>> multinyquist(lins,
...              title="Nyquist Plot of Modelica.Blocks.Continuous.PID",
...              label='examples/PIDs-nyquist', textFreq=True,
...              omega=2*pi*logspace(-1, 3, 81), labelFreq=20,
...              labels=labels) 
<matplotlib.axes...AxesSubplot object at 0x...>

>>> save()
Saved examples/PIDs-nyquist.pdf
Saved examples/PIDs-nyquist.png
Nyquist plot of PID with varying parameters
modelicares.multi.multiplot(sims, suffixes='', color=['b', 'g', 'r', 'c', 'm', 'y', 'k'], dashes=[(None, None), (3, 3), (1, 1), (3, 2, 1, 2)], **kwargs)

Plot data from multiple simulations in 2D Cartesian coordinates.

This method simply calls simres.SimRes.plot() from multiple instances of simres.SimRes.

A new figure is created if necessary.

Arguments:

  • sims: Simulation result or list of results (instances of simres.SimRes)

  • suffixes: Suffix or list of suffixes for the legends (see simres.SimRes.plot())

    If suffixes is None, then no suffix will be used. If it is an empty string (‘’), then the base filenames will be used.

  • color: Single entry, list, or itertools.cycle of colors that will be used sequentially

    Each entry may be a character, grayscale, or rgb value.

  • dashes: Single entry, list, or itertools.cycle of dash styles that will be used sequentially

    Each style is a tuple of on/off lengths representing dashes. Use (0, 1) for no line and (None ,None) for a solid line.

  • **kwargs: Propagated to simres.SimRes.plot() (and thus to base.plot() and finally matplotlib.pyplot.plot())

Returns:

  1. ax1: Primary y axes
  2. ax2: Secondary y axes

Example:

>>> from glob import glob
>>> from modelicares import SimRes, multiplot, save

>>> sims = map(SimRes, glob('examples/ChuaCircuit/*/*.mat'))
>>> multiplot(sims, title="Chua Circuit", label='examples/ChuaCircuits',
...           suffixes=['L.L = %.0f H' % sim.get_IV('L.L')
...                     for sim in sims], # Read legend parameters.
...           ynames1='L.i', ylabel1="Current") 
(<matplotlib.axes...AxesSubplot object at 0x...>, None)

>>> save()
Saved examples/ChuaCircuits.pdf
Saved examples/ChuaCircuits.png
plot of Chua circuit with varying inductance