Graphics - Coupling



In [1]:
# Get the package for importing matalab data
import scipy.io

In [34]:
# 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\KTL80000.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/KTL80000.mat')
Data = Data['TFData']
OP =Data['OperatingPoint']
FT =Data['Fan_Temperature']
VT =Data['Valve_Temperature']
FP =Data['Fan_Pressure']
VP =Data['Valve_Pressure']

In [35]:
# 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 [37]:
# Make a trace

x = []
y1 = []
y2 = []
y3 = []
y4 = []
y5 = []
y6 = []
for op in range(0,OP[0][0][0].shape[0]):
    #print(OP[op])
    #print(FT[0][0][1][op])
    x.append(OP[0][0][0][op])
    # Coupling Analysis
    y1.append(FT[0][0][1][op] + FT[0][0][2][op])
    y2.append(VT[0][0][1][op] + VT[0][0][2][op])
    y3.append(FP[0][0][1][op] + FP[0][0][2][op])
    y4.append(VP[0][0][1][op] + VP[0][0][2][op])
    # Normalized Time 
    y5.append(FT[0][0][2][op]/(FT[0][0][1][op] + FT[0][0][2][op]) / (VT[0][0][2][op]/(VT[0][0][1][op] + VT[0][0][2][op])))
    y6.append(VP[0][0][2][op]/(VP[0][0][1][op] + VP[0][0][2][op]) / (FP[0][0][2][op]/(FP[0][0][1][op] + FP[0][0][2][op])))

trace1 = Scatter(x=x,
                 y=y1,
                 mode = 'lines+markers',
                 name = 'Fan to Temperature')
trace2 = Scatter(x=x,
                 y=y2,
                 mode = 'lines+markers',
                 name = 'Valve to Temperature',
                 line = dict(
                 width = 1,
                 dash = 'dot'))
trace3 = Scatter(x=x,
                 y=y3,
                 mode = 'lines+markers',
                name = 'Fan to Pressure')
trace4 = Scatter(x=x,
                 y=y4,
                 mode = 'lines+markers',
                name = 'Valve to Pressure',
                line = dict(
                width = 1,
                dash = 'dot'))

trace5 = Scatter(x=x,
                 y=y5,
                 mode = 'lines+markers',
                name = 'Temperature',
                line = dict(
                width = 1,
                dash = 'dot'))
trace6 = Scatter(x=x,
                 y=y4,
                 mode = 'lines+markers',
                name = 'Pressure',
                line = dict(
                width = 1,
                dash = 'dot'))

layout = dict(title = 'Similarity of the System Dynamics, P = 50 kW',
              autosize = False,
              width = 1000,
              height = 1000,
              yaxis = dict(
                  zeroline = False,
                  title = 'Small Signal Time Constant [s]',
                  #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
                          )
             )

data1 = [trace1,trace2]
data2 = [trace3,trace4]
data3 = [trace5,trace6]
fig = dict(data=data1, layout=layout)
iplot(fig)



In [38]:
fig2 = dict(data=data2,layout=layout)
iplot(fig2)



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 [ ]: