Tag: dymat

DyMat | HDF5 export and other Modelica/Python projects

DyMat_logoAfter the request of a user I added a very simple HDF5 export to my DyMat package. The code is already in the github repository and will be part of the next release.

If you are interested in the handling of Modelica simulations with Python you should also have a look at these packages:

Happy new year!

DyMat | version 0.5 reads more file formats

DyMat_logoVersion 0.5 of my package DyMat has been released. Read access to different file structures has been implemented. The new version will be able to read most mat files written by dymola.

DyMat should still be handled as beta software, it may have some bugs!

Dymolas different mat file formats – the Aclass quest

DyMat_logoWhen playing a bit with the result files of Dymola 2012 I discovered an strange behaviour in the structure of the saved mat-files. Until now I’ve seen three variants of these files:

  1. The format of the regular result files saved automatically by the simulation process. This format is also used by OpenModelica and can be read with DyMat.
  2. When using “Save Result As” in the result browser and choosing “Result files (*.mat)” for the file format the saved file is almost identical to 1. but some matrices are transposed.
  3. When using “Save Result As” in the result browser and choosing “Result files – Only Plotted (*.mat)” the saved file uses a much simpler structure.

For me this makes no sense! Maybe there’s some deeper concept behind it, but I don’t see it yet. Nevertheless I plan to implement all three variants in my DyMat package in the future.

The information on the variant seems to be coded in the “Aclass” variable. This structure differs in a number which looks like a version (1.0 and 1.1) and the strings “binNormal” and “binTrans“. This can be used to handle files in an different way, but I will do more testing.

DyMat | Reading Modelica results with python

DyMat_logoThe simple module has turned into a complete python package including a script, documentation and more output options. This package is released under the BSD License.  The development is hosted on github.com, feel free to contribute!

Project homepage: http://www.j-raedler.de/projects/DyMat

Development hosting: https://github.com/jraedler/DyMat


  • documentation (well,  some …)
  • command-line script DyMatExport
  • export to CSV, Gnuplot, MATLAB and netCDF
  • more list options, including tree view
  • a lot of additional functions


| View all articles regarding DyMat |

DyMat_logoThis package contains some modules to read and process the result files from Dymola and OpenModelica with python. A script is included that will help you to browse and export the contents of these files to other formats.

Both simulation systems save their results in regular mat-files, but use a special variable structure to store the data efficiently. An easy way to access the data is MATLAB, but some people (like me) don’t have it or don’t want to use it. DyMat needs scipy to load the contents of the files.

DyMat started  as a simple python script, but now it’s a package of modules and a powerful script to use the functions from the command line.


The development of this package is hosted on bitbucket.org, you may browse and download the source code and documentation there.

DyMat.py used in LBLs Modelica Buildings Library

My python module DyMat.py will now be part of free Modelica Library for Building Energy and Control Systems developed at the Lawrence Berkeley National Laboratory. The module may be used under the terms of the Modelica License 2. I will add the copyright notice and license information to the file soon.

Reading dymolas mat-files with python

INFO: This post is outdated! Please have a look here.

Dymola stores its simulation results in regular mat-files, but the program uses a special variable structure to store the data efficiently. An easy way to access the data is MATLAB, but I was looking for a more pythonic solution.

If you want to access the data from python you can use the function scipy.io.loadmat() from the scipy package. Some conversion is necessary get access to the data as simple time rows. The format of the result file dsres.mat is explained dymola users guide. Short version: the file contains matrices of different shape, every matrix has its own abscissa. The names of all dymola variables are stored in a special matrix. Every dymola variable name points to a column of one of the data matrices. Usually a lot of names point to the same column, possibly using a different sign (+/-).

The following python script can be imported as a module or run as a standalone script.


The first argument is the name of the mat-file. If no second argument is given, it prints  the names of all variables in the file. When you provide a variable name as the second argument, the values are printed with the corresponding time values in a format that can be directly printed with gnuplot. You may need to quote the variable name for the shell in some cases.

$ python DyMat.py dsres.mat
$ python DyMat.py dsres.mat "der(x)" # Time | der(x)
0.000000 0
200.000000 0.0597325
400.000000 0.117873
600.000000 0.172892
800.000000 0.223386
1000.000000 0.268128
$ python DyMat.py dsres.mat "der(x)" > tmp
$ gnuplot
gnuplot> plot "tmp"


The module needs more testing. I played a bit with the conversion to netCDF, XLS and CSV, but it’s not easy to transfer the space-efficient data structure to these formats. The conversion to netCDF with the same structure is trivial, but has no advantage over the original format. If you expand all variables the size of the file will explode. This needs to be checked in detail.

When I find the time I will implement a handler for pydap. A plotting tool based on PyQwt would be nice too.