Git Product home page Git Product logo

modelicares's Introduction

ModelicaRes

Set up and analyze Modelica simulations in Python

ModelicaRes is a free, open-source tool that can be used to

Plot of Chua circuit with varying parameters  Sankey diagram of three tanks example  Bode diagram of PID with varying parameters

The goal of ModelicaRes is to leverage Python to make these tasks easy and complex tasks feasible. Publication-quality figures can be created with matplotlib using built-in methods that automatically add titles, labels, and legends. ModelicaRes can be scripted or used in an interactive Python session with math and matrix functions from NumPy.

Please see the tutorial, which is available as an IPython notebook or online as a static page. For the full documentation and many more examples, see the main website.

Currently, ModelicaRes only loads Dymola/OpenModelica-formatted binary and text results (*.mat and *.txt), but the interface is modular so that other formats can be added easily.

Installation

First, install the dependencies. Most are installed automatically, but SciPy >= 0.10.0 must be installed according to the instructions at http://www.scipy.org/install.html. The GUIs require Qt, which can be installed via PyQt4, guidata, or PySide.

Then install ModelicaRes. The easiest way is to use pip:

> pip install modelicares

On Linux, it may be necessary to have root privileges:

$ sudo pip install modelicares

The matplotlibrc file has some recommended revisions to matplotlib's defaults. To use it, copy it to the working directory or matplotlib's configuration directory. See http://matplotlib.org/users/customizing.html for details.

License terms and development

ModelicaRes is published under a BSD-compatible license. Please share any improvements you make, preferably as a pull request to the master branch of the GitHub repository. There are useful development scripts in the hooks folder. If you find a bug, have a suggestion, or just want to leave a comment, please open an issue.

Build Status  Code Health

See also

  • awesim: helps run simulation experiments and organize results
  • BuildingsPy: supports unit testing
  • DyMat: exports Modelica simulation data to Gnuplot, MATLAB®, and Network Common Data Form (netCDF)
  • PyFMI: tools to work with models through the Functional Mock-Up Interface (FMI) standard
  • PySimulator: elaborate GUI; supports FMI

modelicares's People

Contributors

arnoutaertgeerts avatar kdavies4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

modelicares's Issues

Installation under Jython 2.7

Hi Kevin, (or whoever who read it)

I am trying to use modelicares in Jython (using easy_install, pip, ...) and I am getting this error:
ImportError: No module named py3k
(Installation in Python works fine!)
Do you know what is this py3k? Any experience about this issue?

Cheers!

ImportError: No module named _display

@kdavies4 When I try the new merged version for simulations I get the following importerror:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-5715e1a567d2> in <module>()
----> 1 from modelicares.exps.simulators import dymosim

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\modelicares\__init__.py in <module>()
     48 # These will be available directly from modelicares; others must be loaded from
     49 # their submodules.
---> 50 from .simres import SimRes, SimResList, SimResSequence
     51 from .linres import LinRes, LinResList
     52 from .util import (add_arrows, add_hlines, add_vlines, ArrowLine, closeall,

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\modelicares\simres.py in <module>()
    581 
    582 # List of file-loading functions for SimRes
--> 583 from ._io.dymola import readsim as dymola
    584 READERS = [('dymola', dymola)]  # SimRes tries these in order.
    585 # All of the keys should be in lowercase.

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\modelicares\_io\dymola.py in <module>()
     69 from six import PY2
     70 
---> 71 from .._display import default_display_units
     72 from ..simres import Variable
     73 from ..util import next_nonblank

ImportError: No module named _display

Did you remove this module?

Problems with natu library

Hello again!

I am having this error when importing SimRes

Traceback (most recent call last):
  File "C:\Users\fragom\PhD_CIM\PYTHON\SimuGUI\src\gui\msv_framework_gui.py", line 11, in <module>
    from gui import UI_LoadSources, UI_ConfigSolver, UI_Simulation, UI_Plot
  File "C:\Users\fragom\PhD_CIM\PYTHON\SimuGUI\src\gui\__init__.py", line 3, in <module>
    from mee_simulation_gui import UI_Simulation
  File "C:\Users\fragom\PhD_CIM\PYTHON\SimuGUI\src\gui\mee_simulation_gui.py", line 13, in <module>
    from modelicares import SimRes
  File "C:\IDE\Python27\lib\site-packages\modelicares-0.12.2_126_gdab068a-py2.7.egg\modelicares\__init__.py", line 50, in <module>
    from .simres import SimRes, SimResList, SimResSequence
  File "C:\IDE\Python27\lib\site-packages\modelicares-0.12.2_126_gdab068a-py2.7.egg\modelicares\simres.py", line 52, in <module>
    from natu import core as nc
  File "C:\IDE\Python27\lib\site-packages\natu-0.12.2_126_gdab068a-py2.7.egg\natu\core.py", line 171, in <module>
    from .exponents import Exponents, split_code, u, i
  File "C:\IDE\Python27\lib\site-packages\natu-0.12.2_126_gdab068a-py2.7.egg\natu\exponents.py", line 177, in <module>
    parser = re.compile('%s%s?%s?' % (base, exponent, remainder))
  File "C:\IDE\Python27\lib\re.py", line 190, in compile
    return _compile(pattern, flags)
  File "C:\IDE\Python27\lib\re.py", line 245, in _compile
    raise error, v # invalid expression
sre_constants.error: nothing to repeat

I am reading in "the web" that this issue might come from the re.compile() function. I guess you did not face this issue with the natu library. Any idea?

Edited: I am running the code in Eclipse Mars PyDev, under Windows 7

Cheers!

to_pandas error

Kevin, are you still using ModelicaRes often? I keep getting error messages with respect to natu :) If I want to translate the SimRes object to a dataFrame I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-85a33601c9f3> in <module>()
----> 1 data.to_pandas(names=keys)

/home/arnout/anaconda/lib/python2.7/site-packages/ModelicaRes-0.12.2_117_g9339ef6_dirty-py2.7.egg/modelicares/simres.pyc in to_pandas(self, names, aliases)
   1649 
   1650             if unit:
-> 1651                 data.update({name + ' / ' + unit: values})
   1652             else:
   1653                 data.update({name: values})

/home/arnout/anaconda/lib/python2.7/site-packages/natu/exponents.pyc in __add__(x, y)
    461         """x.__add__(y) <==> x+y"""
    462         copy = x.copy()
--> 463         for base, exp in y.items():
    464             copy[base] += exp
    465         return copy

AttributeError: 'str' object has no attribute 'items'

'SimRes' object has no attribute 'find'

I was just starting to use Modelica res however it seems that something does not quite work as it should:

In [11]:
from modelicares import SimRes
sim = SimRes('test.mat')
sim.find('ramp.y')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-3c4dae3c8df3> in <module>()
----> 1 sim.find('ramp.y')

AttributeError: 'SimRes' object has no attribute 'find'

SyntaxError when importing SimRes

When trying to import SimRes I receive the following error.

In [1]: from modelicares import SimRes
Traceback (most recent call last):

  File "C:\ProgramData\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-3-7373672c4d21>", line 1, in <module>
    from modelicares import SimRes

  File "C:\ProgramData\Miniconda3\lib\site-packages\modelicares\__init__.py", line 50, in <module>
    from .simres import SimRes, SimResList, SimResSequence

  File "C:\ProgramData\Miniconda3\lib\site-packages\modelicares\simres.py", line 1723
    if attr == 'value' and len(self) <> self.n_constants:
                                      ^
SyntaxError: invalid syntax

Is there any way to fix this?

Sankey diagrams accumulate labels

When multiple Sankey diagrams are generated at successive times in a simulation, the labels are appended. I need to submit a fix to the Sankey class of matplotlib. After it is accepted, remove the temporary change to 00-make-gh-pages.sh in the gh-pages branch.

Compatiblity issue with matplotlib version >=3.1.0

There are multiple imports of matplolib.cbook.iterable (1, 2), however, this object is deprecated with maplotlib from version v3.1.0 (source).
This has already causing import errors.

An eassiest fix would be specifying matplotlib's version <3.1.0 in setup.py. In my case v3.0.0 worked.

to_pandas() error when progressing modified simulation data

When trying to export simulation data to a dataFrame pandas raises a KeyError.
The problem is that Dymola does not store the units into the *.mat-file when using Dymola functions like "writeTrajectory" or "Export Results".
It would be great if the function's return line could be updated to a more dynamic one, like:
return DataFrame(data).set_index('Time / '+self['Time'].unit)
This way one could use to_pandas() for modified simulation data.
Of course it would also be possible to change the data entry 'Time / ' to 'Time / s'.

simulators not implemented?

Hi Kevin,

we're trying to set up MPC (model predictive control) with Modelica, and we need a continue-run framework. We can implement it with dymosim.exe or pyfmi, and we're happy to see that you have implemented this functionality. However, when we install mdoelica res with pip, the following doesn't work::

from modelicares.exps.simulators import dymosim

Any idea why not? And is it possible to do continue-simulations with pyfmi too?
Thanks,
Roel

Doc: Unresolved links

The following doc files link to _images which is not available.

base.html
index.html
linres.html
multi.html
simres.html

Symlinks in commit

Dear Kevin,

Thank you for this nice project. Unfortunately I cannot use your software directly. The files 00-reindent.py and 00-tabnanny.py from the folder modelicares are symbolic links and I had to delete them in order to run the installation routine successfully.

Please check if these files are necessary and consider removing the symlinks or add the real files.

Thanks again,
Jorrit

Adjust SimResList.plot() to account for continued simulations

The SimResList class does an excellent job of plotting simulation results of different simulations with the same start and stop time.

For continued simulations, it is unnecessary to divide the plot in different segments and give each segment a new name and color. For example:

image

I see two solutions:

  • Adjust the plot() method to take this into account
  • Create a new method (e.g. merge()) which merges the different simulation results in a new single result file

ImportError: cannot import name read_options

ImportError Traceback (most recent call last)
in ()
----> 1 from modelicares.exps.simulators import dymosim

/home/danie/.virtualenvs/vhm/local/lib/python2.7/site-packages/modelicares/exps/simulators.py in ()
42 from multiprocessing import Pool
43 from shutil import copy, move, rmtree
---> 44 from . import read_options, read_params, write_options, write_params
45 from ..simres import SimRes, SimResSequence
46 from ..util import ParamDict, call, cleanpath

ImportError: cannot import name read_options

Installation requires control

The line

import modelicares # Only to read the version number

Is a problem because this, by itself, tries to load a bunch of dependencies.

There are two ways to approach this:

  1. Add the control package to the path during setup.py
  2. Skip the import and provide the version number some other way.

If you do 1) there are lots of dependencies. Some are listed in the setup.py file (matplotlib, wx and numpy). Of these, wx is not the correct name for the extension you want. You want wxPython (which installs a package named wx, but is not the same as the PyPI listing for wx). But scipy is also a dependency even though it is not listed. The big problem here is that the mechanisms in setup.py don't kick in to load all these things. In other words, since modelicares is imported into setup.py, all the dependencies have to be installed in advance. On the other hand, if the import wasn't there and pip was used to install modelicares from PyPI, all the dependencies could actually be loaded automatically. Even if you load all of those dependencies, you still have the problem that the control package really needs to be installed first (because the external/control/src directory name doesn't match the package name). After all of this, I eventually gave up on this approach.

Taking approach 2 (which simply means commenting out the import line and substituting the version number ("0.8.1", in my case) into the setup.py script worked perfectly and modelicares installed without issue. Of course, this doesn't address the dependency issue (since a local install doesn't pull in all the dependencies). The issue with the dependencies (that wx should be wxPython that scipy is missing) are not addressed. Also, the control package still needs to be installed manually in that case.

One word of advice...the best way to test for these kinds of issues is to use virtualenv to create a pristine "install". These things come out of the woodwork in such cases.

Syntax errors in ModelicaRes_Master

There's two syntax errors in the sources.

  1. In modelicares/simres.py, line 1723 and
  2. In modelicares/_io/dymola.py line 131

substitute '<>' by '!='.

Set and read simulation start and stop times from a Dymola dsin.txt

The simulator.run() method should be able to set start and stop times for the simulation. This can be done by changing their respective values in the corresponding dsin.txt if we extend the write_params() method. For example:

import modelicares.exps.write_params as write_params
write_params({
  'StartTime': 0,
  'StopTime': 1000
}

I'm no expert in these file manipulations so could you @kdavies4 have a look at how to efficiently implement this?

Using subplot and other matplotlib functionality

Hi,

I started working with ModelicaRes today. I was exploring the options but I'm stuck at the following.

I'd like to use the subplot command from matplotlib. Intuitively I tried:

sim = SimRes(arguments)
sim.add_subplot(2,1,1)    //from http://matplotlib.org/examples/animation/subplots.html
sim.plot(title="Title", ynames1=  ... etc)

but this does not seem to work. I can't seem to find an example in the documentation either. How can I approach this?

Thank you!

Is it enough to use dymola_script class to run simulations?

Hi!
I am using this class, in modelicares.exps.simulators file, and... the script seems to be written fine, but I do not see how the class executes the .mos file. Its run method seems only to write commands into the .mos file, but how the .mos file is executed?
Cheers!

Add unit conversion

Use the displayUnit by default but allow custom override in SimRes.get_values(), SimRes.get_IV(), etc.

Ideas for implementation:

  • Replace the function f argument to SimRes.get_values(), etc. with a unit argument:
    • If default (None), then use displayUnit.
    • Accept string in Modelica notation (e.g., "m/s2"). The units may contain SI prefixes.
    • Accept values (e.g., m/s**2) where the values are available from a submodule (modelicares.units).
    • Accept functions (e.g., degC, dB), also from a submodule.
    • Build the units into the transformation from the data space to the axis space of matplotlib?
  • Allow configuration of default units (via config file or code).
  • Order of precedence: unit argument, default units, displayUnit attribute, unit attribute
  • Also include constants in the units submodule (e.g., c/(m/s) should return 299792458).
  • Each unit is a class that contains a dimension as well as a value. Use the dimension for dimension checking.
  • List available units and constants in the documentation of modelicares.units.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.