How to bundle an FMU with a png-file that illustrates the system?

85 Views Asked by At

I use FMU a lot for simulation of Modelica models in a Python environment. It would be nice to bundle the obtained FMU from compilation with a png-file that shows the system. Is that possible?

And how to access that png-file and show it in a Jupyter notebook?

3

There are 3 best solutions below

2
janpeter On BEST ANSWER

With the input from Christian and Dag and reading about package zipfile https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.open we can handle the problem as follows for FMU (2.0):

  1. Create a file 'processDiagram.png' by for instance a screenshot of the Modelica-configuration.
  2. Unzip the FMU.
  3. Place the png-file in a folder called "documentation" at the top in parallell to the modelDescription-xml file. If the folder is not there you create one.
  4. Zip the FMU and name it for example: 'fmu_model.fmu'

The person who receive this FMU can now do the following in Python to show the process_diagram.png

import matplotlib.pyplot as plt
import matplotlib.image as img
import zipfile

fmu_file = zipfile.ZipFile('fmu_model.fmu', 'r')
process_diagram = fmu_file.open('documentation/processDiagram.png')
plt.imshow(img.imread(process_diagram))
plt.axis('off')
plt.show()

For a safe handling we need to also include a system with checksum or similar to avoid the possibility to corrupt the FMU with wrong png-files. Design of this safety handling I leave to the designers of PyFMI and FMPy. In fact FMPy has some general handling of checksum already for FMI 2.0, but to my knowledge no functionality to extract a process_diagram file.

5
Dag B On

In Dymola you can export an FMU with an automatically generated icon containing either the icon layer or the diagram layer from Dymola. Inside the FMU there is a top-level directory terminalsAndIcons.

If I remember correctly, this is a new feature in FMI 3; see the specification for details.

2
Christian Bertsch On

For FMI 3.0.1: There is a standardized place and name in the documentation folder for a diagram picture https://fmi-standard.org/docs/3.0.1/#structure-of-zip enter image description here Additionally you can place an icon in the TerminalsAndIcons Folder, but this is not intended for the diagram.

For FMI 2.0.4 a location for a diagram picture is not standardized, but you could still place it in the documentation folder, see section 2.3 of https://github.com/modelica/fmi-standard/releases/download/v2.0.4/FMI-Specification-2.0.4.pdf enter image description here

It is up to the importing tool how to display or make the the concentent of the documentation folder available.

For FMI 3.0 you could ask the creators of your FMI-import-toolbox (fmpy? pyfmi?)to provide an access function for the diagram.png