This submodule contains classes to help load, analyze, and plot results from Modelica linearizations:
Bases: modelicares._res.Res
Class for Modelica-based linearization results and methods to analyze those results
Initialization arguments:
fname: Name of the file (including the directory if necessary)
The file must contain four matrices: Aclass (specifies the class name, which must be “AlinearSystem”), nx, xuyName, and ABCD.
tool: String indicating the linearization tool that created the file and thus the function to be used to load it
By default, the available functions are tried in order until one works (or none do).
Methods:
Properties:
dirname - Directory from which the variables were loaded
fbase - Base filename from which the variables were loaded, without the directory or extension
fname - Filename from which the variables were loaded, with absolute path
sys - State-space system as an instance of control.StateSpace
It contains:
A, B, C, D: Matrices of the linear system
der(x) = A*x + B*u; y = C*x + D*u;state_names: List of names of the states (x)
input_names: List of names of the inputs (u)
output_names: List of names of the outputs (y)
tool - String indicating the function used to load the results (named after the corresponding Modelica tool)
Example:
>>> lin = LinRes('examples/PID.mat')
>>> print(lin)
Modelica linearization results from .../examples/PID.mat
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 name or index, output name or index) tuples of each transfer function to be evaluated
By default, all of the transfer functions will be plotted.
label: Label for the figure (ignored if axes is provided)
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.
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 or ‘-‘ for a solid line.
**kwargs: Additional plotting arguments:
freqs: List or frequencies or tuple of (min, max) frequencies over which to plot the system response.
If freqs is None, then an appropriate range will be determined automatically.
in_Hz: If True (default), the frequencies (freqs) are in Hz and should be plotted in Hz (otherwise, rad/s)
in_dB: If True (default), plot the magnitude in dB
in_deg: If True (default), plot the phase in degrees (otherwise, radians)
Other keyword arguments are passed to matplotlib.pyplot.plot().
Returns:
Example:
(Source code, png, hires.png, pdf)
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 name or index, output name or index) tuples of each transfer function to be evaluated
By default, all of the transfer functions will be plotted.
label: Label for the figure (ignored if ax is provided)
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.
**kwargs: Additional plotting arguments:
freqs: List or frequencies or tuple of (min, max) frequencies over which to plot the system response.
If freqs is None, then an appropriate range will be determined automatically.
in_Hz: If True (default), the frequencies (freqs) are in Hz and should be plotted in Hz (otherwise, rad/s)
mark: True, if the -1 point should be marked on the plot
show_axes: True, if the axes should be shown
skip: Mark every nth frequency on the plot with a dot
If skip is 0 or None, then the frequencies are not marked.
label_freq: If True, if the marked frequencies should be labeled
Other keyword arguments are passed to matplotlib.pyplot.plot().
Returns:
Example:
(Source code, png, hires.png, pdf)
Return a SISO system given input and output indices.
Arguments:
iu: Index or name of the input
This must be specified unless the system has only one input.
iy: Index or name of the output
This must be specified unless the system has only one output.
Example:
>>> lin = LinRes('examples/PID.mat')
>>> lin.to_siso()
A = [[ 0. 0.]
[ 0. -100.]]
B = [[ 2.]
[ 100.]]
C = [[ 1. -10.]]
D = [[ 11.]]
Return a transfer function given input and output names.
Arguments:
iu: Index or name of the input
This must be specified unless the system has only one input.
iy: Index or name of the output
This must be specified unless the system has only one output.
Example:
>>> lin = LinRes('examples/PID.mat')
>>> lin.to_tf()
(array([[ 11., 102., 200.]]), array([ 1., 100., 0.]))
Bases: modelicares._res.ResList
Specialized list of linearization results
Initialization signatures:
LinResList(): Returns an empty linearization list
LinResList(lins), where lins is a list of LinRes instances: Casts the list into a LinResList
LinResList(filespec), where filespec is a filename or directory, possibly with wildcards a la glob: Returns a LinResList of LinRes instances loaded from the matching or contained files
The filename or directory must include the absolute path or be resolved to the current directory.
An error is only raised if no files can be loaded.
LinResList(filespec1, filespec2, ...): Loads all files matching or contained by filespec1, filespec2, etc. as above.
Each file will be opened once at most; duplicate filename matches are ignored.
Built-in methods:
The entries are LinRes instances, but linearizations can be specified via filename when initializing or appending the list. The list has all of the methods of a standard Python list (e.g., + or __add__/__radd__, clear(), in or __contains__, del or __delitem__, __getitem__, += or __iadd__, *= or __imul__, iter() or __iter__, copy(), extend(), index(), insert(), len() or __len__, * or __mul__/__rmul__, pop(), remove(), reverse(), reversed() or __reversed__, = or __setitem__, __sizeof__(), and sort()). By default, the sort() method orders the list of linearizations by the full path of the result files.
Overloaded methods:
Additional methods:
Properties:
Example:
>>> lins = LinResList('examples/PID/*/')
>>> lins.dirname
['.../examples/PID/1', '.../examples/PID/2']
Add linearization(s) to the end of the list of linearizations.
Arguments:
item: LinRes instance or a file specification
Example:
>>> lins = LinResList('examples/PID/*/')
>>> lins.append('examples/PID.mat')
>>> print(lins)
List of linearization results (LinRes instances) from the following files
in the .../examples directory:
PID/1/dslin.mat
PID/2/dslin.mat
PID.mat
Plot the linearizations onto a single Bode diagram.
This method calls LinRes.bode() from the included instances of LinRes.
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.
pair: Tuple of (input name or index, output name or 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)
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 plotting arguments:
freqs: List or frequencies or tuple of (min, max) frequencies over which to plot the system response.
If freqs is None, then an appropriate range will be determined automatically.
in_Hz: If True (default), the frequencies (freqs) are in Hz and should be plotted in Hz (otherwise, rad/s)
in_dB: If True (default), plot the magnitude in dB
in_deg: If True (default), plot the phase in degrees (otherwise, radians)
Other keyword arguments are passed to matplotlib.pyplot.plot().
Returns:
Example:
(Source code, png, hires.png, pdf)
Plot the linearizations onto a single Nyquist diagram.
This method calls nyquist() from the included instances of LinRes.
Arguments:
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 name or index, output name or 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)
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 plotting arguments:
freqs: List or frequencies or tuple of (min, max) frequencies over which to plot the system response.
If freqs is None, then an appropriate range will be determined automatically.
in_Hz: If True (default), the frequencies (freqs) are in Hz and should be plotted in Hz (otherwise, rad/s)
mark: True, if the -1 point should be marked on the plot
show_axes: True, if the axes should be shown
skip: Mark every nth frequency on the plot with a dot
If skip is 0 or None, then the frequencies are not marked.
label_freq: If True, if the marked frequencies should be labeled
Other keyword arguments are passed to matplotlib.pyplot.plot().
Returns:
- ax: Axes of the Nyquist plot
Example:
(Source code, png, hires.png, pdf)