def test_boxplot(self): ''' Test the :mod:`buildingspy.io.Plotter.boxplot` function. ''' import numpy as np # Construct 3 days of data with 1/2 hour time interval # The first time stamp is 0, the last time stamp is 72 t = np.arange(0, 24 * 3 + 0.5, 0.5) y = t # Convert to period of 24 hours # (tP, y) = Plotter.convertToPeriodic(24, t, y) # Create plot Plotter.boxplot(t, y, increment=0.5, nIncrement=2 * 24, notch=0, sym='b+', vert=1, whis=1.5, positions=None, widths=None, patch_artist=False, bootstrap=None, hold=None)
def test_boxplot(self): """ Test the :mod:`buildingspy.io.Plotter.boxplot` function. """ import numpy as np # Construct 3 days of data with 1/2 hour time interval # The first time stamp is 0, the last time stamp is 72 t = np.arange(0, 24 * 3 + 0.5, 0.5) y = t # Convert to period of 24 hours # (tP, y) = Plotter.convertToPeriodic(24, t, y) # Create plot Plotter.boxplot(t, y, increment=0.5, nIncrement=2 * 24, notch=0, sym='b+', vert=1, whis=1.5, positions=None, widths=None, patch_artist=False, bootstrap=None, hold=None)
def test_interpolate(self): ''' Tests the :mod:`buildingspy.io.Plotter.interpolate` function. ''' t10 = range(10) t100 = range(100) f = lambda x: 10 + 2 * x y10 = map(f, t10) y100 = map(f, t100) y10Int = Plotter.interpolate(t10, t100, y100) numpy.testing.assert_allclose(y10, y10Int) # Add one more element to t100. This emulates an event # at t=10, in which case dymola adds two points t100.append(10) y100 = map(f, sorted(t100)) y10Int = Plotter.interpolate(t10, sorted(t100), y100) numpy.testing.assert_allclose(y10, y10Int)
def test_interpolate(self): ''' Tests the :mod:`buildingspy.io.Plotter.interpolate` function. ''' t10 = range(10) t100 = range(100) f = lambda x: 10+2*x y10 = map(f, t10) y100 = map(f, t100) y10Int = Plotter.interpolate(t10, t100, y100) numpy.testing.assert_allclose(y10, y10Int) # Add one more element to t100. This emulates an event # at t=10, in which case dymola adds two points t100.append(10) y100=map(f, sorted(t100)) y10Int = Plotter.interpolate(t10, sorted(t100), y100) numpy.testing.assert_allclose(y10, y10Int)
def test_interpolate(self): """ Tests the :mod:`buildingspy.io.Plotter.interpolate` function. """ t10 = list(range(10)) t100 = list(range(100)) def f(x): return 10 + 2 * x y10 = list(map(f, t10)) y100 = list(map(f, t100)) y10Int = Plotter.interpolate(t10, t100, y100) numpy.testing.assert_allclose(y10, y10Int) # Add one more element to t100. This emulates an event # at t=10, in which case dymola adds two points t100.append(10) y100 = list(map(f, sorted(t100))) y10Int = Plotter.interpolate(t10, sorted(t100), y100) numpy.testing.assert_allclose(y10, y10Int)
def test_convertToPeriodic(self): ''' Test the :mod:`buildingspy.io.Plotter.convertToPeriodic` function. ''' import numpy as np import random import copy t = np.arange(0, 1000, 1.0) y = copy.copy(t) # Shuffle the y vector random.shuffle(y, random.seed(1)) (tP, yP) = Plotter.convertToPeriodic(10, t, y) # Test whether the time vector is periodic for i in range(10): numpy.testing.assert_allclose(tP[i * 10:(i + 1) * 10], range(10)) # Test whether y remains unchanged numpy.testing.assert_allclose(y, yP)
def test_convertToPeriodic(self): """ Test the :mod:`buildingspy.io.Plotter.convertToPeriodic` function. """ import numpy as np import random import copy t = np.arange(0, 1000, 1.0) y = copy.copy(t) # Shuffle the y vector random.shuffle(y, random.seed(1)) (tP, yP) = Plotter.convertToPeriodic(10, t, y) # Test whether the time vector is periodic for i in range(10): numpy.testing.assert_allclose(tP[i * 10:(i + 1) * 10], list(range(10))) # Test whether y remains unchanged numpy.testing.assert_allclose(y, yP)
def _extract_data(matFile, relVal): """ Extract time series data from mat file. :param matFile: modelica simulation result path :param relVal: list of variables that the data should be extracted """ from buildingspy.io.outputfile import Reader from buildingspy.io.postprocess import Plotter import re nPoi = 8761 try: r = Reader(matFile, TOOL) except IOError: raise ValueError("Failed to read {}.".format(matFile)) result = list() for var in relVal: time = [] val = [] try: var_mat = var # Matrix variables in JModelica are stored in mat file with no space e.g. [1,1]. var_mat = re.sub(' ', '', var_mat) (time, val) = r.values(var_mat) tMin = float(min(time)) tMax = float(max(time)) ti = _getTimeGrid(tMin, tMax, nPoi) except KeyError: raise ValueError("Result {} does not have variable {}.".format( matFile, var)) else: intVal = Plotter.interpolate(ti, time, val) temp = {'variable': var, 'time': ti, 'value': intVal} result.append(temp) return result
r=Reader(resultFile, "dymola") DNI.append(r.values('DNI.y')) NN.append(r.values('EuroTrough.N')) T_su.append(r.values('SensTsu.fluidState.T')) T_ex.append(r.values('SensTex.fluidState.T')) TimeSim.append(T_ex[KKK][0]) T_ex_exp.append(r.values('t_htf_ex.y')) Delta_T.append(r.values('DeltaT.Delta')) m_wf.append(r.values('m_dot_htf.y')) # Create a time vector which values every 10 seconds TimeExp.append(np.linspace(StartModTime[KKK],StopModTime[KKK],num=int((StopModTime[KKK]-StartModTime[KKK])/10))) # Interpolate the Modelica results over the Time vector DNIExp.append(Plotter.interpolate(TimeExp[KKK], DNI[KKK][0], DNI[KKK][1])) T_suExp.append(Plotter.interpolate(TimeExp[KKK],T_su[KKK][0],T_su[KKK][1]-273.15)) T_exExp.append(Plotter.interpolate(TimeExp[KKK],T_ex_exp[KKK][0],T_ex_exp[KKK][1]-273.15)) m_wfExp.append(Plotter.interpolate(TimeExp[KKK],m_wf[KKK][0],m_wf[KKK][1])) ########################################################################## # Steady-state values for model and experiments ########################################################################## # Get index for Modelica model #Define function to get to closer value of index def find_closest(A, target): #A must be sorted idx = A.searchsorted(target) idx = np.clip(idx, 1, len(A)-1) left = A[idx-1]
plt.savefig('plotHeatingCoolingPower.pdf') plt.savefig('plotHeatingCoolingPower.png') fig = plt.figure() #ax = fig.add_subplot(311) #ax.plot(1./3600/24*ep_tim, ep_int_con, label='e+ convective') #ax.plot(1./3600/24*ep_tim, ep_int_rad, label='e+ radiative') #ax.plot(1./3600/24*mo_par, mo_qConGai_flow, label='Modelica convective') #ax.plot(1./3600/24*mo_par, mo_qRadGai_flow, label='Modelica radiative') #ax.set_xlabel('time [days]') #ax.set_ylabel('heat gains [$\mathrm{W}$]') #ax.legend() #ax.grid(True) ax = fig.add_subplot(111) ax.plot(1./3600/24*ep_tim, ep_HBeaInc-Plotter.interpolate(ep_tim, mo_tim, mo_HBeaInc), label='beam') ax.plot(1./3600/24*ep_tim, ep_HTotInc-Plotter.interpolate(ep_tim, mo_tim, mo_HTotInc), label='total') #ax.plot(1./3600/24*ep_tim, ep_HBeaInc, label='e+ total') #ax.plot(1./3600/24*ep_tim, ep_HTotInc, label='e+ beam') #ax.plot(1./3600/24*mo_tim, mo_HBeaInc, label='Modelica total') #ax.plot(1./3600/24*mo_tim, mo_HTotInc, label='Modelica beam') ax.set_xlabel('time [days]') ax.set_ylabel('difference in solar incidence [$\mathrm{W/m^2}$]') ax.legend(loc='lower right') ax.grid(True) # Save figure to file plt.savefig('plotBoundaryCondition.pdf') plt.savefig('plotBoundaryCondition.png')
T_su.append(r.values('SensTsu.fluidState.T')) T_ex.append(r.values('SensTex.fluidState.T')) TimeSim.append(T_ex[KKK][0]) T_ex_exp.append(r.values('t_htf_ex.y')) Delta_T.append(r.values('DeltaT.Delta')) m_wf.append(r.values('m_dot_htf.y')) # Create a time vector which values every 5 seconds TimeExp.append( np.linspace(StartModTime[KKK], StopModTime[KKK], num=int((StopModTime[KKK] - StartModTime[KKK]) / 10))) # Interpolate the Modelica results over the Time vector DNIExp.append(Plotter.interpolate(TimeExp[KKK], DNI[KKK][0], DNI[KKK][1])) T_suExp.append( Plotter.interpolate(TimeExp[KKK], T_su[KKK][0], T_su[KKK][1] - 273.15)) T_exExp.append( Plotter.interpolate(TimeExp[KKK], T_ex_exp[KKK][0], T_ex_exp[KKK][1] - 273.15)) m_wfExp.append( Plotter.interpolate(TimeExp[KKK], m_wf[KKK][0], m_wf[KKK][1])) T_lim_min = [170, 150, 140, 280, 200, 150] T_lim_max = [300, 400, 300, 400, 320, 350] NUMBER = [r'$I$', r'$II$', r'$III$', r'$IV$', r'$V$', r'$VI$'] fig = plt.figure() fig.set_size_inches(8.27, 11.69) fig.subplots_adjust(hspace=.21, right=.52, left=.06, top=.97)
plt.savefig('plotHeatingCoolingPower.png') fig = plt.figure() #ax = fig.add_subplot(311) #ax.plot(1./3600/24*ep_tim, ep_int_con, label='e+ convective') #ax.plot(1./3600/24*ep_tim, ep_int_rad, label='e+ radiative') #ax.plot(1./3600/24*mo_par, mo_qConGai_flow, label='Modelica convective') #ax.plot(1./3600/24*mo_par, mo_qRadGai_flow, label='Modelica radiative') #ax.set_xlabel('time [days]') #ax.set_ylabel('heat gains [$\mathrm{W}$]') #ax.legend() #ax.grid(True) ax = fig.add_subplot(111) ax.plot(1. / 3600 / 24 * ep_tim, ep_HBeaInc - Plotter.interpolate(ep_tim, mo_tim, mo_HBeaInc), label='beam') ax.plot(1. / 3600 / 24 * ep_tim, ep_HTotInc - Plotter.interpolate(ep_tim, mo_tim, mo_HTotInc), label='total') #ax.plot(1./3600/24*ep_tim, ep_HBeaInc, label='e+ total') #ax.plot(1./3600/24*ep_tim, ep_HTotInc, label='e+ beam') #ax.plot(1./3600/24*mo_tim, mo_HBeaInc, label='Modelica total') #ax.plot(1./3600/24*mo_tim, mo_HTotInc, label='Modelica beam') ax.set_xlabel('time [days]') ax.set_ylabel('difference in solar incidence [$\mathrm{W/m^2}$]') ax.legend(loc='lower right') ax.grid(True) # Save figure to file plt.savefig('plotBoundaryCondition.pdf')