Skip to content

VerbruggenBart/Simulation-Management

 
 

Repository files navigation

Simulation Management

Repository to share the python code for working with Modelica simulation files in .mat format. The module (simman.py) allows accessing, indexing, filtering, plotting, ...

This module contains tools to: 1) access simulation parameters and results generated by dymola in .mat files, or having exactly the same structure 2) keep track of a (unlimited) amount of these simulation output files

Two classes are defined: 1) Simulation 2) Simdex 3) Process

The main properties of those classes are discussed below. One function is also defined: load_simdex(filename). This function loads the desired simdex that was previously saved with Simdex.save(filename)

class Simulation:

Class for doing operations one 1 single simulation file
The simualation files are supposed to be generated by Dymola, or at 
least have the same structure.  
A Simulation object contains all the (useful) info that is in the .mat file.
Therefore, objects of the Simulation class are relatively memory intensive,
depending on the size of the .mat file.

Most important attributes are:
    - self.filename (path to the .mat file)
    - self.names (list of all variable and parameter names)
    - self.dataInfo (mapping of vars and pars to data1 and data2)
    - self.data1 (contains the values of the parameters)
    - self.data2 (contains the values of the variables (timeseries))

Most important methods are:
    - get_value(name) : retreives the value(s) for name, name can be 
      a parameter or a variable
    - exist(regex) : returns all vars and pars that satisfy the regex

class Simdex:

A Simdex object is an index of all the parameters and variables in several 
.mat files.  It can be used to select a set of .mat files from a large set
in order to analyse the results of this set of simulations.

Most important attributes are:
    - self.simulations (a list of filenames of the indexed simulations)
    - self.parameters (a list of all parameters in the set of simulations)
    - self.parametermap (numpy array mapping which simulation has 
      which parameters)        
    - self.parametervalues (numpy array containing the values of the 
      mapped parameters)
    - self.variables (a list of all variables in the set of simulations)
    - self.variablemap (numpy array mapping which simulation has 
      which variables)
    - self.filterset (dictionary tracking all executed filter options on 
      the current set) 
      
    There is no attribute containing the variable values themselves because 
    that would blow up the size of simdex.  These values are kept in the 
    original .mat files and only extracted when needed

Most important methods (* = implemented):

* __init__(folder): create simdex based from all .mat simulation files in 
  the current folder
- update(folderlist): update simdex with all .mat files found in a list of 
  folders. Checks if the found files are already in simulations, else they 
  are added and their parameters and ALL attributes are updated with the 
  info found in the new files
- remove(sim_id): remove a simulation from the simdex
* print(): gives a nice overview of the indexed simulations 
* filter(dictionary): this method takes as input a dictionary with parameter
  name/value pairs.   It returns a new Simdex object with those simulations
  that have exactly the same values for those parameters.  
  If a parameter is asked with '*' as value, all simulations that HAVE 
  the parameter are selected.
* getidentical(sim_id):  this method takes as input a simulation number and 
  returns a new simdex object all simulations with identical parameter set 
  (so all variants of the model with only changed parameter values).  
* exist(re): similar to Simulation.exist method. Give a search string as re 
  (regular expression) and you get a list of all parameters and variables 
  that satisfy the re. 
* plot(var): directly create a plot showing the given var for each of the 
  simulations in self.
- get_values(var or par): get an array with the values of the variable or
  parameter for each of the simulations in the simdex
* get_parameter(par): to be merged in get_values!!
- save(filename): saves the simdex by pickling (cPickle) to filename.  The 
  simdex can be loaded later on with the function load_simdex(filename)

This info AND more details can be found in the docstrings of each of these classes, functions and methods

About

Python module for management of Modelica simulation files in .mat format

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published