Buildings.Utilities.IO.Python_3_8.Examples
Collection of models that illustrate model use and test models
Information
This package contains examples for the use of models that can be found in Buildings.Utilities.IO.Python_3_8.
Extends from Modelica.Icons.ExamplesPackage (Icon for packages containing runnable examples).
Package Content
Name | Description |
---|---|
KalmanFilter | Kalman filter implemented in Python and called from Modelica |
SimpleRoom | Simple room model implemented in Python that outputs the temperature and the energy |
Buildings.Utilities.IO.Python_3_8.Examples.KalmanFilter
Kalman filter implemented in Python and called from Modelica
Information
This example demonstrates the implementation of a Kalman filter
in Python.
The model generates a uniform random number, which is computed
in the Python file KalmanFilter.py
by the function
random(seed)
.
This random number is added to a sine wave and then sent to
the function filter(u)
in the above Python file.
The function filter(u)
implements a Kalman filter that estimates and returns
the state.
The function saves its temporary variables to a file called
tmp-kalman.json
.
When simulating this model, the figure below will be generated which shows the sine wave, the sine wave plus noise, which is input to the Kalman filter, and the estimated state which is the output of the Kalman filter.
Implementation
The code is based on http://www.scipy.org/Cookbook/KalmanFiltering.
Extends from Modelica.Icons.Example (Icon for runnable examples).
Parameters
Type | Name | Default | Description |
---|---|---|---|
Time | samplePeriod | 0.001 | Sample period of component [s] |
Modelica definition
Buildings.Utilities.IO.Python_3_8.Examples.SimpleRoom
Simple room model implemented in Python that outputs the temperature and the energy
Information
This example demonstrates the implementation of a simple room model
that is implemented in the Python module Resources/Python-Sources/SimpleRoom.py
.
The Python model computes a first-order response to the room model.
It returns the current room air temperature and the energy consumed during the simulation.
The Python module also passes an object from one call to the next. This object
contains the past room temperature, energy and time when the function was called,
stored as a Python dictionary.
This illustrates how Python data structures can be passed between function calls,
thereby enabling for example to call some (memory-intensive) machine learning program,
implemented in Python, from a Modelica block that may then pass the output of this program
to a controller.
Note that this example is for demonstration only. An implementation in Modelica would be much simpler and computationally more efficient.
Extends from Modelica.Icons.Example (Icon for runnable examples).