In [1]:
%matplotlib inline
import sys
import os
#sys.path.append('..') #append the parent directory to the system path
import pvlib
import pandas as pd
import matplotlib.pyplot as plt
try:
import seaborn
seaborn.set_context('paper')
except ImportError:
pass
In [2]:
datapath = os.path.join(pvlib.__path__[0], 'test', 'data')
fname = '703165TY.csv' #Use absolute path if the file is not in the local directory
TMY, meta = pvlib.tmy.readtmy3(filename=os.path.join(datapath, fname))
TMY.index.name = 'Time'
meta['SurfTilt'] = 30
meta['SurfAz'] = 0
meta['Albedo'] = 0.2
# create pvlib Location object
sand_point = pvlib.location.Location(meta['latitude'], meta['longitude'], tz='US/Alaska',
altitude=meta['altitude'], name=meta['Name'].replace('"',''))
print(sand_point)
# TMY data seems to be given as hourly data with time stamp at the end
# shift the index 30 Minutes back for calculation of sun postions
TMY = TMY.shift(freq='-30Min')
Calculate the solar position for all times in the TMY file. Requires either PyEphem or a compiled spa_c library.
In [3]:
solpos = pvlib.solarposition.get_solarposition(TMY.index, sand_point, method='pyephem')
solpos.head()
Out[3]:
In [4]:
# append solar position data to TMY DataFrame
TMY['SunAz'] = solpos['apparent_elevation']
TMY['SunZen'] = solpos['apparent_zenith']
TMY['HExtra'] = pvlib.irradiance.extraradiation(doy=TMY.index.dayofyear)
TMY['AM'] = pvlib.atmosphere.relativeairmass(z=TMY.SunZen)
DFOut = pvlib.clearsky.disc(Time=TMY.index,GHI=TMY.GHI, SunZen=TMY.SunZen)
TMY['DNI_gen_DISC'] = DFOut['DNI_gen_DISC']
TMY['Kt_gen_DISC'] = DFOut['Kt_gen_DISC']
TMY['AM'] = DFOut['AM']
TMY['Ztemp'] = DFOut['Ztemp']
In [4]:
models = ['Perez', 'Hay-Davies', 'Isotropic', 'King', 'Klucher', 'Reindl']
TMY['Perez'] = pvlib.pvl_perez(SurfTilt=meta['SurfTilt'],
SurfAz=meta['SurfAz'],
DHI=TMY.DHI,
DNI=TMY.DNI,
HExtra=TMY.HExtra,
SunZen=TMY.SunZen,
SunAz=TMY.SunAz,
AM=TMY.AM)
In [5]:
TMY['Hay-Davies'] = pvlib.pvl_haydavies1980(SurfTilt=meta['SurfTilt'],
SurfAz=meta['SurfAz'],
DHI=TMY.DHI,
DNI=TMY.DNI,
HExtra=TMY.HExtra,
SunZen=TMY.SunZen,
SunAz=TMY.SunAz)
In [6]:
TMY['Isotropic'] = pvlib.pvl_isotropicsky(SurfTilt=meta['SurfTilt'],
DHI=TMY.DHI)
In [7]:
TMY['King'] = pvlib.pvl_kingdiffuse(SurfTilt=meta['SurfTilt'],
DHI=TMY.DHI,
GHI=TMY.GHI,
SunZen=TMY.SunZen)
In [8]:
TMY['Klucher'] = pvlib.pvl_klucher1979(SurfTilt=meta['SurfTilt'],
SurfAz=meta['SurfAz'],
DHI=TMY.DHI,
GHI=TMY.GHI,
SunZen=TMY.SunZen,
SunAz=TMY.SunAz)
In [9]:
TMY['Reindl'] = pvlib.pvl_reindl1990(SurfTilt=meta['SurfTilt'],
SurfAz=meta['SurfAz'],
DHI=TMY.DHI,
DNI=TMY.DNI,
GHI=TMY.GHI,
HExtra=TMY.HExtra,
SunZen=TMY.SunZen,
SunAz=TMY.SunAz)
In [10]:
yearly = TMY[models].resample('A', how='sum').squeeze() / 1000.0 # kWh
monthly = TMY[models].resample('M', how='sum', kind='period') / 1000.0
daily = TMY[models].resample('D', how='sum') / 1000.0
In [12]:
ax = TMY[models].plot(title='Modelled in-plane diffuse irradiance')
# ax.legend(ncol=3, loc='upper center', title='In-plane diffuse irradiance')
ax.set_ylim(0, 800)
ylabel = ax.set_ylabel('Diffuse Irradiance [W]')
In [13]:
TMY[models].describe()
Out[13]:
In [14]:
TMY[models].dropna().plot(kind='density')
Out[14]:
In [15]:
ax_daily = daily[models].plot(title='Daily diffuse irradiation')
ylabel = ax_daily.set_ylabel('Irradiation [kWh]')
In [16]:
ax_monthly = monthly[models].plot(title='Monthly diffuse irradiation', kind='bar')
ylabel = ax_monthly.set_ylabel('Irradiation [kWh]')
In [17]:
yearly.plot(kind='barh')
Out[17]:
In [18]:
mean_yearly = yearly.mean()
yearly_mean_deviation = (yearly - mean_yearly) / yearly * 100.0
yearly_mean_deviation.plot(kind='bar')
Out[18]:
In [ ]: