4

I want to automatically evaluate my simulation results with a python script, but struggle to open the .mat-Files in a meaningful way.

Opening the files with scipy.loadmat doesn't seem to be a viable option:

from scipy.io import loadmat
x = loadmat(path)

Result: enter image description here

Should I implicitly return the values I want to analyse with my python simulation script or is there another way of loading .mat-Results with Python?

What do you use for such tasks? Matlab is not an option sadly.

Phil
  • 624
  • 7
  • 19
  • 2
    You could try using DyMat: https://pypi.org/project/DyMat/ – matth Dec 06 '19 at 13:28
  • @matth this is pretty much the answer to my question! Can you post this as the answer? Thank you so much! – Phil Dec 06 '19 at 15:33
  • So, is the mat file from Dymola/Openmodelica not a "standard"-conform .mat file? – Christoph Dec 06 '19 at 15:35
  • Another way could be, since you'll be using Python anyway, to use [OMPython](https://github.com/OpenModelica/OMPython). – Christoph Dec 06 '19 at 15:36
  • related: https://stackoverflow.com/questions/48662401/how-can-i-analyse-the-results-of-a-dymolasimulation-simulated-via-python-interf – matth Dec 06 '19 at 15:51
  • 1
    Phil, if you [self-answer](https://stackoverflow.com/help/self-answer) your question, by giving a small example script, I would definetly upvote it! – matth Dec 06 '19 at 19:54

1 Answers1

2

By suggestion from @matth DyMat can be used to write code to automatic process dymola results:

import DyMat

d = DyMat.DyMatFile(path) 
varX = d.data("dymola.path.to.variable")

To get all the paths to all variables one can use d.names() or d.nameTree()

Phil
  • 624
  • 7
  • 19