Detailed pvlib report¶
In [1]:
Copied!
LATITUDE = 48.77
LONGITUDE = 9.18
LOCATION = 'Stuttgart'
TIMEZONE = 'Etc/GMT-1'
ALTITUDE = 400
ALBEDO = 0.2 # Standard is 0.25. Why?
# -20.9 , 55.5, 'St-Denis, La Réunion' , 100, 'Etc/GMT-4')
LATITUDE = 48.77
LONGITUDE = 9.18
LOCATION = 'Stuttgart'
TIMEZONE = 'Etc/GMT-1'
ALTITUDE = 400
ALBEDO = 0.2 # Standard is 0.25. Why?
# -20.9 , 55.5, 'St-Denis, La Réunion' , 100, 'Etc/GMT-4')
In [2]:
Copied!
AZIMUTH = 180
TILT = 25
AZIMUTH = 180
TILT = 25
In [3]:
Copied!
#TODO: Get timezone automatically
#TODO: Add requirements.txt
#TODO: Define functions each time, with only the strictly required parameters
#TODO: Get timezone automatically
#TODO: Add requirements.txt
#TODO: Define functions each time, with only the strictly required parameters
Enable caching¶
pip install requests-cache
In [4]:
Copied!
# Not required. Avoids downloading same data over and over again:
import requests_cache
requests_cache.install_cache('pvgis_requests_cache', backend='sqlite')
# Not required. Avoids downloading same data over and over again:
import requests_cache
requests_cache.install_cache('pvgis_requests_cache', backend='sqlite')
Get weather¶
pip install pvlib
In [5]:
Copied!
from pvlib.iotools import pvgis
from pvlib.iotools import pvgis
In [6]:
Copied!
weather, _, info, _ = pvgis.get_pvgis_tmy(LATITUDE, LONGITUDE, map_variables=True)
weather, _, info, _ = pvgis.get_pvgis_tmy(LATITUDE, LONGITUDE, map_variables=True)
In [7]:
Copied!
weather_source = '%s (%d - %d)' % (info['meteo_data']['radiation_db'],
info['meteo_data']['year_min'],
info['meteo_data']['year_max'])
latitude_NS = '%.1f°%s' % (abs(LATITUDE), 'N' if LATITUDE > 0 else 'S')
longitude_EW = '%.1f°%s' % (abs(LONGITUDE), 'E' if LONGITUDE > 0 else 'W')
weather_source = '%s (%d - %d)' % (info['meteo_data']['radiation_db'],
info['meteo_data']['year_min'],
info['meteo_data']['year_max'])
latitude_NS = '%.1f°%s' % (abs(LATITUDE), 'N' if LATITUDE > 0 else 'S')
longitude_EW = '%.1f°%s' % (abs(LONGITUDE), 'E' if LONGITUDE > 0 else 'W')
In [8]:
Copied!
# Rename columns from PVGIS TMY in order to define the required data.
weather = weather.rename(columns={'G(h)': 'ghi',
'Gb(n)': 'dni',
'Gd(h)': 'dhi',
'T2m': 'temp_air',
'WS10m': 'wind_speed' # Does it make sense to use wind speed from 10m height?
})
weather
# Rename columns from PVGIS TMY in order to define the required data.
weather = weather.rename(columns={'G(h)': 'ghi',
'Gb(n)': 'dni',
'Gd(h)': 'dhi',
'T2m': 'temp_air',
'WS10m': 'wind_speed' # Does it make sense to use wind speed from 10m height?
})
weather
Out[8]:
temp_air | relative_humidity | ghi | dni | dhi | IR(h) | wind_speed | wind_direction | pressure | |
---|---|---|---|---|---|---|---|---|---|
time(UTC) | |||||||||
2016-01-01 00:00:00+00:00 | 2.70 | 96.70 | 0.0 | 0.0 | 0.0 | 292.75 | 1.06 | 219.0 | 99358.0 |
2016-01-01 01:00:00+00:00 | 3.26 | 97.01 | 0.0 | 0.0 | 0.0 | 299.49 | 1.05 | 228.0 | 99374.0 |
2016-01-01 02:00:00+00:00 | 3.83 | 97.32 | 0.0 | 0.0 | 0.0 | 306.23 | 1.03 | 238.0 | 99390.0 |
2016-01-01 03:00:00+00:00 | 4.39 | 97.62 | 0.0 | 0.0 | 0.0 | 312.97 | 1.01 | 222.0 | 99383.0 |
2016-01-01 04:00:00+00:00 | 4.96 | 97.93 | 0.0 | 0.0 | 0.0 | 319.71 | 0.99 | 207.0 | 99377.0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2007-12-31 19:00:00+00:00 | -0.12 | 95.16 | 0.0 | 0.0 | 0.0 | 259.05 | 1.16 | 248.0 | 99586.0 |
2007-12-31 20:00:00+00:00 | 0.45 | 95.47 | 0.0 | 0.0 | 0.0 | 265.79 | 1.14 | 246.0 | 99574.0 |
2007-12-31 21:00:00+00:00 | 1.01 | 95.78 | 0.0 | 0.0 | 0.0 | 272.53 | 1.12 | 248.0 | 99561.0 |
2007-12-31 22:00:00+00:00 | 1.57 | 96.09 | 0.0 | 0.0 | 0.0 | 279.27 | 1.10 | 249.0 | 99548.0 |
2007-12-31 23:00:00+00:00 | 2.14 | 96.39 | 0.0 | 0.0 | 0.0 | 286.01 | 1.08 | 251.0 | 99535.0 |
8760 rows × 9 columns
In [9]:
Copied!
# Force all dates to be from the same year
COERCE_YEAR = 2019
weather.index = weather.index.map(lambda dt: dt.replace(year=COERCE_YEAR))
# Force all dates to be from the same year
COERCE_YEAR = 2019
weather.index = weather.index.map(lambda dt: dt.replace(year=COERCE_YEAR))
Check and display weather¶
In [10]:
Copied!
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
plt.rcParams['figure.figsize'] = [15, 10]
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
plt.rcParams['figure.figsize'] = [15, 10]
Ambient temperature¶
In [11]:
Copied!
weather.temp_air.plot(title='Ambient temperature in %s\n%s' % (LOCATION, weather_source), color='#603a47')
plt.gca().yaxis.set_major_formatter(mticker.FormatStrFormatter('%d °C'))
weather.temp_air.plot(title='Ambient temperature in %s\n%s' % (LOCATION, weather_source), color='#603a47')
plt.gca().yaxis.set_major_formatter(mticker.FormatStrFormatter('%d °C'))
In [12]:
Copied!
print("Average temperature in %s : %.1f °C" % (LOCATION, weather.temp_air.mean()))
daily_temperatures = weather.temp_air.resample('D').mean()
print("Coldest day in %s : %.1f °C" % (LOCATION, daily_temperatures.min()))
print("Warmest day in %s : %.1f °C" % (LOCATION, daily_temperatures.max()))
print("Average temperature in %s : %.1f °C" % (LOCATION, weather.temp_air.mean()))
daily_temperatures = weather.temp_air.resample('D').mean()
print("Coldest day in %s : %.1f °C" % (LOCATION, daily_temperatures.min()))
print("Warmest day in %s : %.1f °C" % (LOCATION, daily_temperatures.max()))
Average temperature in Stuttgart : 11.7 °C Coldest day in Stuttgart : -6.7 °C Warmest day in Stuttgart : 26.8 °C
In [13]:
Copied!
plt.figure(figsize=(15, 8))
plt.imshow(weather.temp_air.values.reshape(-1,24).T,
aspect='auto',
origin='lower', cmap='inferno')
plt.title('Ambient temperature in %s\n%s' % (LOCATION, weather_source))
plt.xlabel('Day of the year')
plt.ylabel('Hour')
plt.gca().yaxis.set_major_formatter(mticker.FormatStrFormatter('%d h'))
plt.colorbar();
plt.figure(figsize=(15, 8))
plt.imshow(weather.temp_air.values.reshape(-1,24).T,
aspect='auto',
origin='lower', cmap='inferno')
plt.title('Ambient temperature in %s\n%s' % (LOCATION, weather_source))
plt.xlabel('Day of the year')
plt.ylabel('Hour')
plt.gca().yaxis.set_major_formatter(mticker.FormatStrFormatter('%d h'))
plt.colorbar();
Define system¶
In [14]:
Copied!
from pvlib.pvsystem import PVSystem, retrieve_sam
from pvlib.location import Location
from pvlib.modelchain import ModelChain
from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS
# Get the module and inverter specifications from SAM
module = retrieve_sam('SandiaMod')['Canadian_Solar_CS5P_220M___2009_']
inverter = retrieve_sam('cecinverter')['ABB__MICRO_0_25_I_OUTD_US_208__208V_']
temp_parameters = TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_glass']
location = Location(LATITUDE, LONGITUDE, name=LOCATION,
altitude=ALTITUDE, tz=TIMEZONE)
system = PVSystem(module_parameters=module,
inverter_parameters=inverter,
temperature_model_parameters=temp_parameters,
surface_tilt=TILT,
surface_azimuth=AZIMUTH,
albedo = ALBEDO
)
mc = ModelChain(system, location, transposition_model='haydavies')
results = mc.run_model(weather)
from pvlib.pvsystem import PVSystem, retrieve_sam
from pvlib.location import Location
from pvlib.modelchain import ModelChain
from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS
# Get the module and inverter specifications from SAM
module = retrieve_sam('SandiaMod')['Canadian_Solar_CS5P_220M___2009_']
inverter = retrieve_sam('cecinverter')['ABB__MICRO_0_25_I_OUTD_US_208__208V_']
temp_parameters = TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_glass']
location = Location(LATITUDE, LONGITUDE, name=LOCATION,
altitude=ALTITUDE, tz=TIMEZONE)
system = PVSystem(module_parameters=module,
inverter_parameters=inverter,
temperature_model_parameters=temp_parameters,
surface_tilt=TILT,
surface_azimuth=AZIMUTH,
albedo = ALBEDO
)
mc = ModelChain(system, location, transposition_model='haydavies')
results = mc.run_model(weather)
Global horizontal irradiance¶
In [15]:
Copied!
irradiances = weather.ghi.resample('M').mean().to_frame()
irradiances['poa'] = mc.results.total_irrad.poa_global.resample('M').mean()
irradiances = weather.ghi.resample('M').mean().to_frame()
irradiances['poa'] = mc.results.total_irrad.poa_global.resample('M').mean()
In [16]:
Copied!
irradiances.index = irradiances.index.month_name()
irradiances.index = irradiances.index.month_name()
In [17]:
Copied!
plt.figure(figsize=(15, 8))
plt.imshow(weather.ghi.values.reshape(-1,24).T,
aspect='auto',
origin='lower')
plt.title('Global Horizontal Irradiance in %s\n%s'% (LOCATION, weather_source))
plt.xlabel('Day of the year')
plt.ylabel('Hour')
plt.gca().yaxis.set_major_formatter(mticker.FormatStrFormatter('%d h'))
plt.colorbar();
plt.figure(figsize=(15, 8))
plt.imshow(weather.ghi.values.reshape(-1,24).T,
aspect='auto',
origin='lower')
plt.title('Global Horizontal Irradiance in %s\n%s'% (LOCATION, weather_source))
plt.xlabel('Day of the year')
plt.ylabel('Hour')
plt.gca().yaxis.set_major_formatter(mticker.FormatStrFormatter('%d h'))
plt.colorbar();