- 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.
- 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.
- 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.
The 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
This 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.
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.
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 x der(x) t $ 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.
A new release 2.2.4 of ncDataReader2 is out. Some bugs were fixed and the API has slightly changed. This version should work both with Dymola and OpenModelica on Linux and Windows. When you have a DAP-enabled netcdf library it will even fetch data from the web in background. I already did some Dymola simulations with on-demand loading of data from a server, a post about this topic will follow.
- the meaning of offset and scale factor for a ncDatSet1D was changed
- chunk loading was implemented
- Akima interpolation was changed heavily, works much faster now
- better support for newer netcdf libraries
- new helper functions for setting attributes
- changed some char* to const char* to work with OpenModelica
- a lot of bugs were fixed