Beispiel #1
0
def showResults(time, x, sqrtP, y, Sy, y_full, csvTrue, m):

    # convert results
    x = numpy.array(x)
    y = numpy.squeeze(numpy.array(y))
    sqrtP = numpy.array(sqrtP)
    Sy = numpy.array(Sy)
    y_full = numpy.squeeze(numpy.array(y_full))

    # Read from file
    simResults = CsvReader.CsvReader()
    simResults.OpenCSV(csvTrue)

    # Get time series values
    simResults.SetSelectedColumn("chi.etaPL")
    t = simResults.GetDataSeries().index
    eta_PL = simResults.GetDataSeries().values

    simResults.SetSelectedColumn("P")
    P = simResults.GetDataSeries().values

    simResults.SetSelectedColumn("T_CH_Lea")
    T_ch = simResults.GetDataSeries().values

    simResults.SetSelectedColumn("T_CW_lea")
    T_cw = simResults.GetDataSeries().values

    simResults.SetSelectedColumn("chi.COP")
    COP = simResults.GetDataSeries().values

    # plot and save images
    fig0 = plt.figure()
    fig0.set_size_inches(12, 8)
    ix = 2
    ax0 = fig0.add_subplot(111)
    ax0.plot(t, eta_PL, 'g', label='$\eta_{PL}$', alpha=1.0)
    ax0.plot(time, x[:, ix], 'r', label='$\hat{\eta}_{PL}$')
    ax0.fill_between(time,
                     x[:, ix] - sqrtP[:, ix, ix],
                     x[:, ix] + sqrtP[:, ix, ix],
                     facecolor='red',
                     interpolate=True,
                     alpha=0.3)
    ax0.set_xlabel('Time [s]')
    ax0.set_ylabel('COP')
    ax0.set_xlim([t[0], t[-1]])
    legend = ax0.legend(loc='upper center',
                        bbox_to_anchor=(0.5, 1.1),
                        ncol=1,
                        fancybox=True,
                        shadow=True)
    legend.draggable()
    ax0.grid(False)
    plt.savefig('PartLoadEffectiveness.pdf',
                dpi=400,
                bbox_inches='tight',
                transparent=True,
                pad_inches=0.1)

    fig1 = plt.figure()
    ax2 = fig1.add_subplot(111)
    ax2.plot(t, T_ch, 'bo', label='$T_{CH}$', alpha=1.0)
    ax2.plot(t, T_cw, 'ro', label='$T_{CW}$', alpha=1.0)
    ax2.plot(time, x[:, 0], 'r', label='$Tcw$', alpha=1.0)
    ax2.fill_between(time,
                     x[:, 0] - sqrtP[:, 0, 0],
                     x[:, 0] + sqrtP[:, 0, 0],
                     facecolor='red',
                     interpolate=True,
                     alpha=0.3)
    ax2.plot(time, x[:, 1], 'b', label='$Tch$', alpha=1.0)
    ax2.fill_between(time,
                     x[:, 1] - sqrtP[:, 1, 1],
                     x[:, 1] + sqrtP[:, 1, 1],
                     facecolor='blue',
                     interpolate=True,
                     alpha=0.3)
    ax2.set_xlabel('Time [s]')
    ax2.set_ylabel('Output temperatures')
    ax2.set_xlim([t[0], t[-1]])
    legend = ax2.legend(loc='upper center',
                        bbox_to_anchor=(0.5, 1.1),
                        ncol=1,
                        fancybox=True,
                        shadow=True)
    legend.draggable()
    ax2.grid(False)
    plt.savefig('OutputTemperatures.pdf',
                dpi=400,
                bbox_inches='tight',
                transparent=True,
                pad_inches=0.1)

    fig2 = plt.figure()
    ax3 = fig2.add_subplot(111)
    ax3.plot(t, P, 'go', label='$P$', alpha=1.0)
    ax3.plot(time, y_full[:, 0], 'r', label='$\hat{P}$')
    ax3.fill_between(time,
                     y_full[:, 0] - Sy[:, 0, 0],
                     y_full[:, 0] + Sy[:, 0, 0],
                     facecolor='red',
                     interpolate=True,
                     alpha=0.3)
    ax3.set_xlabel('Time [s]')
    ax3.set_ylabel('Output Variable')
    ax3.set_xlim([t[0], t[-1]])
    legend = ax3.legend(loc='upper center',
                        bbox_to_anchor=(0.5, 1.1),
                        ncol=1,
                        fancybox=True,
                        shadow=True)
    legend.draggable()
    ax3.grid(False)

    fig3 = plt.figure()
    ax4 = fig3.add_subplot(111)
    ax4.plot(t, COP, 'k--', label='$COP$', alpha=1.0)
    ax4.plot(time, y_full[:, 1], 'r', label='$\hat{COP}$')
    ax4.fill_between(time,
                     y_full[:, 1] - Sy[:, 1, 1],
                     y_full[:, 1] + Sy[:, 1, 1],
                     facecolor='red',
                     interpolate=True,
                     alpha=0.3)
    ax4.set_xlabel('Time [s]')
    ax4.set_ylabel('COP')
    ax4.set_xlim([t[0], t[-1]])
    legend = ax4.legend(loc='upper center',
                        bbox_to_anchor=(0.5, 1.1),
                        ncol=1,
                        fancybox=True,
                        shadow=True)
    legend.draggable()
    ax4.grid(False)

    plt.show()
Beispiel #2
0
def showResults(time, x, sqrtP, y, Sy, y_full, csvTrue):

    # convert results
    x = numpy.array(x)
    y = numpy.array(y)
    sqrtP = numpy.array(sqrtP)
    Sy = numpy.array(Sy)
    y_full = numpy.squeeze(numpy.array(y_full))

    # Get the true and unmeasured metal temperature
    simResults = CsvReader.CsvReader()
    simResults.OpenCSV(csvTrue)
    simResults.SetSelectedColumn("heatExchanger.metal.T")
    res = simResults.GetDataSeries()

    t = res["time"]
    d = numpy.squeeze(numpy.asarray(res["data"]))

    fig1 = plt.figure()
    ax1 = fig1.add_subplot(211)
    id = 0
    ax1.plot(time, x[:, id], 'r', label='$\hat{T}_{Metal}$', alpha=1.0)
    ax1.fill_between(time,
                     x[:, id] - sqrtP[:, id, id],
                     x[:, id] + sqrtP[:, id, id],
                     facecolor='red',
                     interpolate=True,
                     alpha=0.3)
    ax1.plot(t, d, 'g', label='$T_{Metal}$', alpha=1.0)
    ax1.set_xlabel('Time [s]')
    ax1.set_ylabel('Metal temperature')
    ax1.set_xlim([time[0], time[-1]])
    legend = ax1.legend(loc='upper center',
                        bbox_to_anchor=(0.5, 1.1),
                        ncol=5,
                        fancybox=True,
                        shadow=True)
    legend.draggable()
    ax1.grid(False)

    ax2 = fig1.add_subplot(212)
    id = 1
    ax2.plot(time, x[:, id], 'b', label='$\hat{G}_{Hot}$', alpha=1.0)
    ax2.fill_between(time,
                     x[:, id] - sqrtP[:, id, id],
                     x[:, id] + sqrtP[:, id, id],
                     facecolor='blue',
                     interpolate=True,
                     alpha=0.3)
    id = 2
    ax2.plot(time, x[:, id], 'c', label='$\hat{G}_{Cold}$', alpha=1.0)
    ax2.fill_between(time,
                     x[:, id] - sqrtP[:, id, id],
                     x[:, id] + sqrtP[:, id, id],
                     facecolor='cyan',
                     interpolate=True,
                     alpha=0.3)
    ax2.set_xlabel('Time [s]')
    ax2.set_ylabel('Thermal conductances')
    ax2.set_xlim([t[0], t[-1]])
    legend = ax2.legend(loc='upper center',
                        bbox_to_anchor=(0.5, 1.1),
                        ncol=2,
                        fancybox=True,
                        shadow=True)
    legend.draggable()
    ax2.grid(False)
    plt.savefig('Heat_Exchanger_UKF.pdf',
                dpi=400,
                bbox_inches='tight',
                transparent=True,
                pad_inches=0.1)
    plt.show()

    plt.show()
Beispiel #3
0
def showResults(time, x, sqrtP, y, Sy, y_full, Xsmooth, Ssmooth, Yfull_smooth,
                csvTrue):
    # Convert list to arrays
    time = time / 3600.0
    x = numpy.squeeze(numpy.array(x))
    y = numpy.squeeze(numpy.array(y))
    sqrtP = numpy.squeeze(numpy.array(sqrtP))
    Sy = numpy.squeeze(numpy.array(Sy))

    xs = numpy.array(Xsmooth)
    Ss = numpy.array(Ssmooth)
    Ys = numpy.array(Yfull_smooth)

    print "smoothed end", xs[-1, :]
    print "smoothed start", xs[0, :]
    print "smoothed average", numpy.average(xs, 0)

    print "filtered end", x[-1, :]
    print "filtered start", x[0, :]
    print "filtered average", numpy.average(x, 0)

    ####################################################################
    # Display results
    simResults = CsvReader.CsvReader()
    simResults.OpenCSV(csvTrue)
    simResults.SetSelectedColumn("Pump.kW")
    res = simResults.GetDataSeries()

    t = res["time"]
    t = t / 3600.0
    d_kW = numpy.squeeze(numpy.asarray(res["data"]))

    simResults.SetSelectedColumn("Pump.Speed")
    res = simResults.GetDataSeries()
    d_rpm = numpy.squeeze(numpy.asarray(res["data"]))

    simResults.SetSelectedColumn("Pump.gpm")
    res = simResults.GetDataSeries()
    d_gpm = numpy.squeeze(numpy.asarray(res["data"]))

    fig0 = plt.figure()
    fig0.set_size_inches(12, 8)
    ax0 = fig0.add_subplot(111)
    #ax0.plot(time,x,'r',label='$a_5$',alpha=1.0)
    #ax0.fill_between(time, x - sqrtP, x + sqrtP, facecolor='red', interpolate=True, alpha=0.3)
    idx = 0
    ax0.plot(time, x[:, idx], 'r', label='$a_1$', alpha=1.0)
    ax0.fill_between(time,
                     x[:, idx] - sqrtP[:, idx, idx],
                     x[:, idx] + sqrtP[:, idx, idx],
                     facecolor='red',
                     interpolate=True,
                     alpha=0.05)
    ax0.plot(time, xs[:, idx], 'r--', label='$a_1$', alpha=1.0)
    ax0.fill_between(time,
                     xs[:, idx] - Ss[:, idx, idx],
                     xs[:, idx] + Ss[:, idx, idx],
                     facecolor='red',
                     interpolate=True,
                     alpha=0.05)
    idx = 1
    ax0.plot(time, x[:, idx], 'b', label='$a_3$', alpha=1.0)
    ax0.fill_between(time,
                     x[:, idx] - sqrtP[:, idx, idx],
                     x[:, idx] + sqrtP[:, idx, idx],
                     facecolor='blue',
                     interpolate=True,
                     alpha=0.05)
    ax0.plot(time, xs[:, idx], 'b--', label='$a_3$', alpha=1.0)
    ax0.fill_between(time,
                     xs[:, idx] - Ss[:, idx, idx],
                     xs[:, idx] + Ss[:, idx, idx],
                     facecolor='blue',
                     interpolate=True,
                     alpha=0.05)
    idx = 2
    ax0.plot(time, x[:, idx], 'k', label='$a_5$', alpha=1.0)
    ax0.fill_between(time,
                     x[:, idx] - sqrtP[:, idx, idx],
                     x[:, idx] + sqrtP[:, idx, idx],
                     facecolor='black',
                     interpolate=True,
                     alpha=0.05)
    ax0.plot(time, xs[:, idx], 'k--', label='$a_5$', alpha=1.0)
    ax0.fill_between(time,
                     xs[:, idx] - Ss[:, idx, idx],
                     xs[:, idx] + Ss[:, idx, idx],
                     facecolor='black',
                     interpolate=True,
                     alpha=0.05)
    idx = 3
    ax0.plot(time, x[:, idx], 'c', label='$a_7$', alpha=1.0)
    ax0.fill_between(time,
                     x[:, idx] - sqrtP[:, idx, idx],
                     x[:, idx] + sqrtP[:, idx, idx],
                     facecolor='cyan',
                     interpolate=True,
                     alpha=0.05)
    ax0.plot(time, xs[:, idx], 'c--', label='$a_7$', alpha=1.0)
    ax0.fill_between(time,
                     xs[:, idx] - Ss[:, idx, idx],
                     xs[:, idx] + Ss[:, idx, idx],
                     facecolor='cyan',
                     interpolate=True,
                     alpha=0.05)

    ax0.set_xlabel('Time [hours]')
    ax0.set_ylabel('Coefficients [$\cdot$]')
    ax0.set_xlim([time[0], time[-1]])
    ax0.set_ylim([0.0, 1.0])
    legend = ax0.legend(loc='upper center',
                        bbox_to_anchor=(0.5, 1.0),
                        ncol=4,
                        fancybox=True,
                        shadow=True)
    legend.draggable()
    ax0.grid(False)

    plt.savefig('Coefficients.pdf',
                dpi=400,
                bbox_inches='tight',
                transparent=True,
                pad_inches=0.1)

    ####################################################################
    # Display results

    fig1 = plt.figure()
    fig1.set_size_inches(20, 8)
    ax1 = fig1.add_subplot(111)
    ax1.plot(t, d_kW, 'g', label='$P_{EL}^{Measured}$', alpha=1.0)
    #ax1.plot(t,d_gpm,'g',label='$\dot{m}_{PUMP}^{Measured}$',alpha=1.0)
    ax1.plot(time, y, 'r', label='$P_{EL}^{UKF}$', alpha=1.0)
    ax1.plot(time, Ys[:, 0], 'b', label='$P_{EL}^{Smooth}$', alpha=1.0)
    #ax1.plot(time,y,'r',label='$\dot{m}_{PUMP}^{UKF}$',alpha=1.0)
    ax1.set_xlabel('Time [hours]')
    ax1.set_ylabel('Electrical power [kW]')
    #ax1.set_ylabel('Volume flow rate [gpm]')
    ax1.set_xlim([t[0], t[-1]])
    ax1.set_ylim([0, 4.6])
    #ax1.set_ylim([300, 600])
    legend = ax1.legend(loc='upper center',
                        bbox_to_anchor=(0.5, 1.1),
                        ncol=4,
                        fancybox=True,
                        shadow=True)
    legend.draggable()
    ax1.grid(False)
    plt.savefig('Power.pdf',
                dpi=400,
                bbox_inches='tight',
                transparent=True,
                pad_inches=0.1)

    plt.show()
Beispiel #4
0
def showResults(time, results, csvPath, pars):

    ####################################################################
    # Display results
    simResults = CsvReader.CsvReader()
    simResults.OpenCSV(csvPath)
    simResults.SetSelectedColumn("Pump.kW")
    res = simResults.GetDataSeries()

    t = res["time"]
    t = t / 3600.0
    time = time / 3600
    d_kW = numpy.squeeze(numpy.asarray(res["data"]))
    P_el = results["P_el"]

    Ndata = numpy.max([len(d_kW), len(P_el)])
    new_t = numpy.linspace(time[0], time[-1], Ndata)
    d_kW = numpy.interp(new_t, t, d_kW)
    P_el = numpy.interp(new_t, time, P_el)

    error = d_kW - P_el
    MSE = numpy.sqrt(numpy.sum(numpy.power(error, 2.0)))

    fig1 = plt.figure()
    ax1 = fig1.add_subplot(111)
    ax1.plot(new_t, P_el, 'r', label='$P_{kW}^{MODEL}$', alpha=1.0)
    ax1.plot(new_t, d_kW, 'g', label='$P_{kW}^{DATA}$', alpha=1.0)
    ax1.set_xlabel('Time [hours]')
    ax1.set_ylabel('Power [kW]')
    ax1.set_title('$MSE=%.6f$ \n $p_1=%.4f \ p_2=%.4f \ p_3=%.4f \ p_4=%.4f$' %
                  (MSE, pars[0], pars[1], pars[2], pars[3]))
    ax1.set_xlim([time[0], time[-1]])
    ax1.set_ylim([0, 5])
    legend = ax1.legend(loc='upper right',
                        bbox_to_anchor=(1.0, 1.0),
                        ncol=1,
                        fancybox=True,
                        shadow=True)
    legend.draggable()
    ax1.grid(False)

    plt.savefig('PumpElectrical.pdf',
                dpi=300,
                bbox_inches='tight',
                transparent=True,
                pad_inches=0.1)
    corr_coeff = numpy.corrcoef(d_kW, P_el)

    fig2 = plt.figure()
    ax2 = fig2.add_subplot(111)
    ax2.plot(d_kW / numpy.max(d_kW), P_el / numpy.max(P_el), 'ro', alpha=0.5)
    ax2.plot(d_kW / numpy.max(d_kW), d_kW / numpy.max(d_kW), 'b', alpha=1.0)
    ax2.set_xlabel('Normalized measured power')
    ax2.set_ylabel('Normalized simulated power')
    ax2.set_title('$r=%.6f$' % (corr_coeff[0, 1]))
    ax2.set_ylim([0, 1.1])
    ax2.set_ylim([0, 1.1])
    ax2.grid(False)

    plt.savefig('PumpElectrical_2.pdf',
                dpi=300,
                bbox_inches='tight',
                transparent=True,
                pad_inches=0.1)

    plt.show()