modelicares.linres — ModelicaRes v0.8.0 Documentation
Description: Python module to set up, plot, and analyze Modelica simulations
Keywords: Modelica, Python, plot, results, simulation, experiment

### Navigation

- index
- modules |
- next |
- previous |
- ModelicaRes v0.8.0 Documentation »

# `modelicares.linres`

Load, analyze, and plot the result of linearizing a Modelica model.

This module relies on python-control, which is included in the distribution.

class `modelicares.linres.` `LinRes`(fname='dslin.mat')

  Bases: `object`

  Class for Modelica-based linearization results and methods to analyze those results

  On initialization, load and preprocess a linearized Modelica model (MATLAB® format). The model is in state space:

      der(x) = A*x + B*u;
           y = C*x + D*u;

  The linear system is stored as sys within this class. It is an instance of `control.StateSpace`, which emulates the structure of a continuous-time model in MATLAB® (e.g., the output of `ss()` in MATLAB®). It contains:

  > - A, B, C, D: Matrices of the linear system
  > - stateName: List of name(s) of the states (x)
  > - inputName: List of name(s) of the inputs (u)
  > - outputName: List of name(s) of the outputs (y)

  Arguments:

  - fname: Name of the file (may include the path)

    > The file extension (‘.mat’) is optional. The file must contain four matrices: Aclass (specifies the class name, which must be “AlinearSystem”), nx, xuyName, and ABCD.

  Example:

      >>> from modelicares import LinRes
      >>> lin = LinRes('examples/PID')

  `__repr__`()

    Return a formal description of the `LinRes` instance.

    Example:

        >>> from modelicares import LinRes
        >>> lin = LinRes('examples/PID.mat')
        >>> lin
        LinRes('...PID.mat')

  `__str__`()

    Return an informal description of the `LinRes` instance.

    Example:

        >>> from modelicares import LinRes
        >>> lin = LinRes('examples/PID.mat')
        >>> print(lin)
        Modelica linearization results from "...PID.mat"

  `bode`(axes=None, pairs=None, label='bode', title=None, colors=['b', 'g', 'r', 'c', 'm', 'y', 'k'], styles=[(None, None), (3, 3), (1, 1), (3, 2, 1, 2)], **kwargs)

    Create a Bode plot of the system’s response.

    The Bode plots of a MIMO system are overlayed. This is different than MATLAB®, which creates an array of subplots.

    Arguments:

    - 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.

    - pairs: List of (input index, output index) tuples of each transfer function to be evaluated

      > If not provided, all of the transfer functions will be plotted.

    - 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

      > If title is None (default), then the title will be “Bode Plot of fbase”, where fbase is the base filename of the data. Use ‘’ for no title.

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

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

      > See also

      > http://matplotlib.sourceforge.net/api/colors_api.html

    - 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.

      > See also

      > http://matplotlib.sourceforge.net/api/collections_api.html

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

    Returns:

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

    Example:

        >>> from modelicares import LinRes, saveall
        >>> from numpy import pi, logspace

        >>> lin = LinRes('examples/PID.mat')
        >>> lin.bode(label='examples/PID-bode', omega=2*pi*logspace(-2, 3),
        ...          title="Bode Plot of Modelica.Blocks.Continuous.PID")
        (<matplotlib.axes._subplots.AxesSubplot object at 0x...>, <matplotlib.axes._subplots.AxesSubplot object at 0x...>)
        >>> saveall()
        Saved examples/PID-bode.pdf
        Saved examples/PID-bode.png

  `nyquist`(ax=None, pairs=None, label='nyquist', title=None, xlabel='Real Axis', ylabel='Imaginary Axis', colors=['b', 'g', 'r', 'c', 'm', 'y', 'k'], **kwargs)

    Create a Nyquist plot of the system’s response.

    The Nyquist plots of a MIMO system are overlayed. This is different than MATLAB®, which creates an array of subplots.

    Arguments:

    - ax: Axes onto which the Nyquist diagram should be plotted

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

    - pairs: List of (input index, output index) tuples of each transfer function to be evaluated

      > If not provided, all of the transfer functions will be plotted.

    - label: Label for the figure (ignored if ax is provided)

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

    - title: Title for the figure

      > If title is None (default), then the title will be “Nyquist Plot of fbase”, where fbase is the base filename of the data. Use ‘’ for no title.

    - xlabel: x-axis label

    - ylabel: y-axis label

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

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

      > See also

      > http://matplotlib.sourceforge.net/api/colors_api.html

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

    Returns:

    1. ax: Axes of the Nyquist plot

    Example:

        >>> from modelicares import LinRes, saveall
        >>> from numpy import pi, logspace

        >>> lin = LinRes('examples/PID.mat')
        >>> lin.nyquist(label='examples/PID-nyquist',
        ...             omega=2*pi*logspace(0, 3, 61), labelFreq=20,
        ...             title="Nyquist Plot of Modelica.Blocks.Continuous.PID")
        <matplotlib.axes._subplots.AxesSubplot object at 0x...>
        >>> saveall()
        Saved examples/PID-nyquist.pdf
        Saved examples/PID-nyquist.png

### Navigation

- index
- modules |
- next |
- previous |
- ModelicaRes v0.8.0 Documentation »