Graphics - Modelica



In [1]:
# Import the dymola Python package
import os
import threading
import numpy as np
from dymola.dymola_interface import DymolaInterface
from dymola.dymola_exception import DymolaException

In [2]:
from dymola.dymola_interface import DymolaInterface
from dymola.dymola_exception import DymolaException
# Set working directory
os.chdir(r'C:\Users\juliu\Documents\GIT\New folder\Modelica')
# Start the dymola Interface
dymola = DymolaInterface(use64bit = False)

In [3]:
# Name of the result file
studyname = "Gascooler_Valve_System_Tester_Constant_Valve_1.mat"
tsize = dymola.readTrajectorySize(studyname)
#tnames = dymola.readTrajectoryNames(studyname)
# Import needed results
signals = dymola.readTrajectory(studyname,["Time",
                                           "Gascooler_Valve_System.HPValve.vleFluidA.T",
                                           "Gascooler_Valve_System.HPValve.vleFluidA.p",
                                           "Gascooler_Valve_System.HPValve.vleFluidB.T",
                                           "Gascooler_Valve_System.HPValve.vleFluidB.p"],
                                tsize)
# Redefine for readability
t = np.array(signals[0])
T1 = np.array(signals[1])
p1 = np.array(signals[2])/1e5
T2 = np.array(signals[3])
p2 = np.array(signals[4])/1e5


ERROR: Bad return type. Expected int but got <class 'dict'>.
ERROR: Bad return type. Expected list2d but got <class 'dict'>.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-49be5b29aa05> in <module>()
     11                                 tsize)
     12 # Redefine for readability
---> 13 t = np.array(signals[0])
     14 T1 = np.array(signals[1])
     15 p1 = np.array(signals[2])/1e5

TypeError: 'NoneType' object is not subscriptable

In [3]:
# Import Plotly
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
from plotly.graph_objs import *
import plotly
plotly.offline.init_notebook_mode()



In [4]:
# Make a trace

trace1 = Scatter(x = t,
                 y= T1,
                 mode = 'lines+markers',
                 name = 'T1')
trace2 = Scatter(x = t,
                 y= T2,
                 mode = 'lines+markers',
                 name = 'T2')

layout = dict(title = 'Study',
              autosize = False,
              width = 1000,
              height = 1000,
              yaxis = dict(
                  zeroline = False,
                  title = 'Temperature in [K]',
                  #range = [1.2,1.35],
                  autotick = True,
                  ticks='outside',
                  #tick0 = 1.2,
                  #dtick = 0.05,
                  showgrid = True              ),
                  
              xaxis = dict(
                    zeroline = False,
                    title = 'Time in [s]',
                    #range = [300,320],
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 25,
                  showgrid = True
                          )
             )

data1 = [trace1,trace2]
fig = dict(data=data1, layout=layout)
iplot(fig)



In [5]:
# Make a trace

trace1 = Scatter(x = t,
                 y= p1,
                 mode = 'lines+markers',
                 name = 'p1')
trace2 = Scatter(x = t,
                 y= p2,
                 mode = 'lines+markers',
                 name = 'p2')

layout = dict(title = 'Study',
              autosize = False,
              width = 1000,
              height = 1000,
              yaxis = dict(
                  zeroline = False,
                  title = 'Pressure',
                  #range = [1.2,1.35],
                  autotick = True,
                  ticks='outside',
                  #tick0 = 1.2,
                  #dtick = 0.05,
                  showgrid = True              ),
                  
              xaxis = dict(
                    zeroline = False,
                    title = 'Time in [s]',
                    #range = [300,320],
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 25,
                  showgrid = True
                          )
             )

data1 = [trace1,trace2]
fig = dict(data=data1, layout=layout)
iplot(fig)



In [39]:
layout = dict(title = 'Ratio of Normalized Time, P = 80 kW',
              autosize = False,
              width = 1000,
              height = 1000,
              yaxis = dict(
                  zeroline = False,
                  title = 'Ratio of Main Diagonal to Minor Diagonal',
                  #range = [1.2,1.35],
                  autotick = True,
                  ticks='outside',
                  #tick0 = 1.2,
                  #dtick = 0.05,
                  showgrid = True              ),
                  
              xaxis = dict(
                    zeroline = False,
                    title = 'Operating points in [K]',
                    range = [271,313],
                    autotick = False,
                    ticks='outside',
                    tick0 = 273,
                    dtick = 2,
                  showgrid = True
                          )
             )


data3 = [trace5,trace6]
fig = dict(data=data3, layout=layout)
iplot(fig)



In [25]:
# Data is stored like Order, Sample, 0 = Real System 1= Model System
#Data = scipy.io.loadmat(r'C:\Users\juliu\Documents\GIT\New folder\Matlab\KTL_5000\Data_80kW_T299.mat')
#Data = scipy.io.loadmat(r'C:\Users\juliu\Documents\GIT\New folder\Matlab\KTL_5000\KTL50000.mat')
Data = scipy.io.loadmat('//home/julius/Thesis/Thesis/Matlab/KTL_5000/Data_50kW_T287.mat')
x= Data['time'].flatten()
u = Data['u'].reshape(2,len(x))
y1 = Data['y1']
y2 = Data['y2']
y3 = Data['y3']
trace1 = Scatter(x=x,
                 y=u[0],
                 mode = 'lines',
                 name = 'Input',
                line = dict(
                 width = 1,
                 dash = 'dot',
                color = 'grey'),
                showlegend = False)
trace2 = Scatter(x=x,
                 y=y1[:,0],
                 mode = 'lines',
                 name = 'RGA',
                 line = dict(
                 width = 1,
                 color = 'red'),
                showlegend = False)
trace3 = Scatter(x=x,
                 y=y2[:,0],
                 mode = 'lines',
                 name = 'Q Design',
                 line = dict(
                 width = 1,
                 color = 'blue'),
                showlegend = False)
trace4 = Scatter(x=x,
                 y=y3[:,0],
                 mode = 'lines',
                 name = 'G Design',
                 line = dict(
                 width = 1,
                 color = 'orange'),
                showlegend = False)


trace5 = Scatter(x=x,
                 y=u[1],
                 mode = 'lines',
                 name = 'Input',
                line = dict(
                 width = 1,
                 dash = 'dot',
                color = 'grey'),
                showlegend = False,
                legendgroup = 1)
trace6 = Scatter(x=x,
                 y=y1[:,1],
                 mode = 'lines',
                 name = 'RGA',
                 line = dict(
                 width = 1,
                 color = 'red'))
trace7 = Scatter(x=x,
                 y=y2[:,1],
                 mode = 'lines',
                 name = 'Q Design',
                 line = dict(
                 width = 1,
                 color = 'blue'))
trace8 = Scatter(x=x,
                 y=y3[:,1],
                 mode = 'lines',
                 name = 'G Design',
                 line = dict(
                 width = 1,
                 color = 'orange'))

from plotly import tools
fig = tools.make_subplots(rows=2, cols=1, shared_xaxes = True, vertical_spacing = 0.01)

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 1)
fig.append_trace(trace3, 1, 1)
fig.append_trace(trace4, 1, 1)
fig.append_trace(trace5, 2, 1)
fig.append_trace(trace6, 2, 1)
fig.append_trace(trace7, 2, 1)
fig.append_trace(trace8, 2, 1)

fig['layout'].update(
    height = 1000,
    width = 1000,
    title = 'Simulation for Operating Point T = 287 K, P = 50 kW', 
    xaxis1 = dict(
                    zeroline = False,
                    title = 'Time in [s]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 250,
                  showgrid = True
                          ),
    yaxis1 = dict(
                    zeroline = True,
                    title = 'Temperature in [K]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 0.5,
                  showgrid = True
                          ),
    yaxis2 = dict(
                    zeroline = True,
                    title = 'Pressure in [bar]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 0.2,
                  showgrid = True
                          )
)


iplot(fig)


This is the format of your plot grid:
[ (1,1) x1,y1 ]
[ (2,1) x1,y2 ]


In [28]:
# Data is stored like Order, Sample, 0 = Real System 1= Model System
#Data = scipy.io.loadmat(r'C:\Users\juliu\Documents\GIT\New folder\Matlab\KTL_5000\Data_80kW_T299_Factorized.mat')
#Data = scipy.io.loadmat(r'C:\Users\juliu\Documents\GIT\New folder\Matlab\KTL_5000\KTL50000.mat')
Data = scipy.io.loadmat('//home/julius/Thesis/Thesis/Matlab/KTL_5000/Data_80kW_T281.mat')
x= Data['time'].flatten()
u = Data['u'].reshape(2,len(x))
y1 = Data['y1']
y2 = Data['y2']
y3 = Data['y3']
trace1 = Scatter(x=x,
                 y=u[0],
                 mode = 'lines',
                 name = 'Input',
                line = dict(
                 width = 1,
                 dash = 'dot',
                color = 'grey'),
                showlegend = False)
trace2 = Scatter(x=x,
                 y=y1[:,0],
                 mode = 'lines',
                 name = 'RGA',
                 line = dict(
                 width = 1,
                 color = 'red'),
                showlegend = False)
trace3 = Scatter(x=x,
                 y=y2[:,0],
                 mode = 'lines',
                 name = 'Q Design',
                 line = dict(
                 width = 1,
                 color = 'blue'),
                showlegend = False)
trace4 = Scatter(x=x,
                 y=y3[:,0],
                 mode = 'lines',
                 name = 'G Design',
                 line = dict(
                 width = 1,
                 color = 'orange'),
                showlegend = False)


trace5 = Scatter(x=x,
                 y=u[1],
                 mode = 'lines',
                 name = 'Input',
                line = dict(
                 width = 1,
                 dash = 'dot',
                color = 'grey'),
                showlegend = False,
                legendgroup = 1)
trace6 = Scatter(x=x,
                 y=y1[:,1],
                 mode = 'lines',
                 name = 'RGA',
                 line = dict(
                 width = 1,
                 color = 'red'))
trace7 = Scatter(x=x,
                 y=y2[:,1],
                 mode = 'lines',
                 name = 'Q Design',
                 line = dict(
                 width = 1,
                 color = 'blue'))
trace8 = Scatter(x=x,
                 y=y3[:,1],
                 mode = 'lines',
                 name = 'G Design',
                 line = dict(
                 width = 1,
                 color = 'orange'))

from plotly import tools
fig = tools.make_subplots(rows=2, cols=1, shared_xaxes = True, vertical_spacing = 0.01)

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 1)
fig.append_trace(trace3, 1, 1)
fig.append_trace(trace4, 1, 1)
fig.append_trace(trace5, 2, 1)
fig.append_trace(trace6, 2, 1)
fig.append_trace(trace7, 2, 1)
fig.append_trace(trace8, 2, 1)

fig['layout'].update(
    height = 1000,
    width = 1000,
    title = 'Simulation for Operating Point T = 281 K, P = 80 kW', 
    xaxis1 = dict(
                    zeroline = False,
                    title = 'Time in [s]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 250,
                  showgrid = True
                          ),
    yaxis1 = dict(
                    zeroline = True,
                    title = 'Temperature in [K]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 0.5,
                  showgrid = True
                          ),
    yaxis2 = dict(
                    zeroline = True,
                    title = 'Pressure in [bar]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 0.2,
                  showgrid = True
    )
)


iplot(fig)


This is the format of your plot grid:
[ (1,1) x1,y1 ]
[ (2,1) x1,y2 ]


In [19]:
# Data is stored like Order, Sample, 0 = Real System 1= Model System
#Data = scipy.io.loadmat(r'C:\Users\juliu\Documents\GIT\New folder\Matlab\KTL_5000\Data_80kW_T299_Factorized.mat')
#Data = scipy.io.loadmat(r'C:\Users\juliu\Documents\GIT\New folder\Matlab\KTL_5000\KTL50000.mat')
Data = scipy.io.loadmat('//home/julius/Thesis/Thesis/Matlab/KTL_5000/Data_80kW_T299.mat')
x= Data['time'].flatten()
u = Data['u'].reshape(2,len(x))
y1 = Data['y1']
y2 = Data['y2']
y3 = Data['y3']
trace1 = Scatter(x=x,
                 y=u[0],
                 mode = 'lines',
                 name = 'Input',
                line = dict(
                 width = 1,
                 dash = 'dot',
                color = 'grey'),
                showlegend = False)
trace2 = Scatter(x=x,
                 y=y1[:,0],
                 mode = 'lines',
                 name = 'RGA',
                 line = dict(
                 width = 1,
                 color = 'red'),
                showlegend = False)
trace3 = Scatter(x=x,
                 y=y2[:,0],
                 mode = 'lines',
                 name = 'Q Design',
                 line = dict(
                 width = 1,
                 color = 'blue'),
                showlegend = False)
trace4 = Scatter(x=x,
                 y=y3[:,0],
                 mode = 'lines',
                 name = 'G Design',
                 line = dict(
                 width = 1,
                 color = 'orange'),
                showlegend = False)


trace5 = Scatter(x=x,
                 y=u[1],
                 mode = 'lines',
                 name = 'Input',
                line = dict(
                 width = 1,
                 dash = 'dot',
                color = 'grey'),
                showlegend = False,
                legendgroup = 1)
trace6 = Scatter(x=x,
                 y=y1[:,1],
                 mode = 'lines',
                 name = 'RGA',
                 line = dict(
                 width = 1,
                 color = 'red'))
trace7 = Scatter(x=x,
                 y=y2[:,1],
                 mode = 'lines',
                 name = 'Q Design',
                 line = dict(
                 width = 1,
                 color = 'blue'))
trace8 = Scatter(x=x,
                 y=y3[:,1],
                 mode = 'lines',
                 name = 'G Design',
                 line = dict(
                 width = 1,
                 color = 'orange'))

from plotly import tools
fig = tools.make_subplots(rows=2, cols=1, shared_xaxes = True, vertical_spacing = 0.01)

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 1)
fig.append_trace(trace3, 1, 1)
fig.append_trace(trace4, 1, 1)
fig.append_trace(trace5, 2, 1)
fig.append_trace(trace6, 2, 1)
fig.append_trace(trace7, 2, 1)
fig.append_trace(trace8, 2, 1)

fig['layout'].update(
    height = 1000,
    width = 1000,
    title = 'Simulation for Operating Point T = 299 K, P = 80 kW', 
    xaxis1 = dict(
                    zeroline = False,
                    title = 'Time in [s]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 250,
                  showgrid = True
                          ),
    yaxis1 = dict(
                    zeroline = True,
                    title = 'Temperature in [K]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 0.5,
                  showgrid = True
                          ),
    yaxis2 = dict(
                    zeroline = True,
                    title = 'Pressure in [bar]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 0.2,
                  showgrid = True
                          )
)


iplot(fig)


This is the format of your plot grid:
[ (1,1) x1,y1 ]
[ (2,1) x1,y2 ]


In [27]:
# Data is stored like Order, Sample, 0 = Real System 1= Model System
#Data = scipy.io.loadmat(r'C:\Users\juliu\Documents\GIT\New folder\Matlab\KTL_5000\Data_80kW_T299_Factorized.mat')
#Data = scipy.io.loadmat(r'C:\Users\juliu\Documents\GIT\New folder\Matlab\KTL_5000\KTL50000.mat')
Data = scipy.io.loadmat('//home/julius/Thesis/Thesis/Matlab/KTL_5000/Data_80kW_T299_Factorized.mat')
x= Data['time'].flatten()
u = Data['u'].reshape(2,len(x))
y1 = Data['y1']
y2 = Data['y2']
y3 = Data['y3']
trace1 = Scatter(x=x,
                 y=u[0],
                 mode = 'lines',
                 name = 'Input',
                line = dict(
                 width = 1,
                 dash = 'dot',
                color = 'grey'),
                showlegend = False)
trace2 = Scatter(x=x,
                 y=y1[:,0],
                 mode = 'lines',
                 name = 'RGA',
                 line = dict(
                 width = 1,
                 color = 'red'),
                showlegend = False)
trace3 = Scatter(x=x,
                 y=y2[:,0],
                 mode = 'lines',
                 name = 'Q Design',
                 line = dict(
                 width = 1,
                 color = 'blue'),
                showlegend = False)
trace4 = Scatter(x=x,
                 y=y3[:,0],
                 mode = 'lines',
                 name = 'G Design',
                 line = dict(
                 width = 1,
                 color = 'orange'),
                showlegend = False)


trace5 = Scatter(x=x,
                 y=u[1],
                 mode = 'lines',
                 name = 'Input',
                line = dict(
                 width = 1,
                 dash = 'dot',
                color = 'grey'),
                showlegend = False,
                legendgroup = 1)
trace6 = Scatter(x=x,
                 y=y1[:,1],
                 mode = 'lines',
                 name = 'RGA',
                 line = dict(
                 width = 1,
                 color = 'red'))
trace7 = Scatter(x=x,
                 y=y2[:,1],
                 mode = 'lines',
                 name = 'Q Design',
                 line = dict(
                 width = 1,
                 color = 'blue'))
trace8 = Scatter(x=x,
                 y=y3[:,1],
                 mode = 'lines',
                 name = 'G Design',
                 line = dict(
                 width = 1,
                 color = 'orange'))

from plotly import tools
fig = tools.make_subplots(rows=2, cols=1, shared_xaxes = True, vertical_spacing = 0.01)

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 1)
fig.append_trace(trace3, 1, 1)
fig.append_trace(trace4, 1, 1)
fig.append_trace(trace5, 2, 1)
fig.append_trace(trace6, 2, 1)
fig.append_trace(trace7, 2, 1)
fig.append_trace(trace8, 2, 1)

fig['layout'].update(
    height = 1000,
    width = 1000,
    title = 'Simulation for Operating Point T = 299 K, P = 80 kW, Weighted G Design', 
    xaxis1 = dict(
                    zeroline = False,
                    title = 'Time in [s]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 250,
                  showgrid = True
                          ),
    yaxis1 = dict(
                    zeroline = True,
                    title = 'Temperature in [K]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 0.5,
                  showgrid = True
                          ),
    yaxis2 = dict(
                    zeroline = True,
                    title = 'Pressure in [bar]',
                    autotick = False,
                    ticks='outside',
                    tick0 = 0,
                    dtick = 0.2,
                  showgrid = True
                          )
)


iplot(fig)


This is the format of your plot grid:
[ (1,1) x1,y1 ]
[ (2,1) x1,y2 ]


In [ ]: