Skip to content

Commit a2fc762

Browse files
committed
add irradiance and weather kwargs to run_model
1 parent 9901538 commit a2fc762

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

docs/sphinx/source/package_overview.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,31 @@ configuration at a handful of sites listed below.
3333
3434
import pandas as pd
3535
import matplotlib.pyplot as plt
36+
37+
# seaborn makes the plots look nicer
3638
import seaborn as sns
3739
sns.set_color_codes()
3840
3941
times = pd.DatetimeIndex(start='2015', end='2016', freq='1h')
4042
4143
# very approximate
44+
# latitude, longitude, name, altitude
4245
coordinates = [(30, -110, 'Tucson', 700),
4346
(35, -105, 'Albuquerque', 1500),
4447
(40, -120, 'San Francisco', 10),
4548
(50, 10, 'Berlin', 34)]
4649
4750
import pvlib
4851
52+
# get the module and inverter specifications from SAM
4953
sandia_modules = pvlib.pvsystem.retrieve_sam('SandiaMod')
5054
sapm_inverters = pvlib.pvsystem.retrieve_sam('sandiainverter')
5155
module = sandia_modules['Canadian_Solar_CS5P_220M___2009_']
5256
inverter = sapm_inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_']
57+
58+
# specify constant ambient air temp and wind
59+
temp_air = 20
60+
wind_speed = 0
5361
5462
5563
Procedural
@@ -85,7 +93,8 @@ to accomplish our system modeling goal:
8593
cs['dni'], cs['ghi'], cs['dhi'],
8694
dni_extra=dni_extra,
8795
model='haydavies')
88-
temps = pvlib.pvsystem.sapm_celltemp(total_irrad['poa_global'], 0, 20)
96+
temps = pvlib.pvsystem.sapm_celltemp(total_irrad['poa_global'],
97+
wind_speed, temp_air)
8998
dc = pvlib.pvsystem.sapm(module, total_irrad['poa_direct'],
9099
total_irrad['poa_diffuse'], temps['temp_cell'],
91100
am_abs, aoi)
@@ -140,6 +149,7 @@ objects to accomplish our system modeling goal:
140149
# very experimental
141150
mc = ModelChain(system, location,
142151
orientation_strategy='south_at_latitude_tilt')
152+
# optional parameters for irradiance and weather data
143153
dc, ac = mc.run_model(times)
144154
annual_energy = ac.sum()
145155
energies[name] = annual_energy
@@ -188,7 +198,8 @@ object to accomplish our modeling goal:
188198
clearsky['dni'],
189199
clearsky['ghi'],
190200
clearsky['dhi'])
191-
temps = localized_system.sapm_celltemp(total_irrad['poa_global'], 0, 20)
201+
temps = localized_system.sapm_celltemp(total_irrad['poa_global'],
202+
wind_speed, temp_air)
192203
aoi = localized_system.get_aoi(solar_position['apparent_zenith'],
193204
solar_position['azimuth'])
194205
am_rel = pvlib.atmosphere.relativeairmass(solar_position['apparent_zenith'])

pvlib/modelchain.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,45 @@ def orientation_strategy(self, strategy):
8686
self._orientation_strategy = strategy
8787

8888

89-
def run_model(self, times):
89+
def run_model(self, times=None, irradiance=None, weather=None):
9090
"""
9191
Run the model.
9292
93-
Problems:
94-
95-
* assumes clear sky
96-
* assumes 0 m/s wind and 20 C temp.
97-
* only works with SAPM
98-
93+
Parameters
94+
----------
95+
times : None or DatetimeIndex
96+
irradiance : None or DataFrame
97+
If None, calculates clear sky data.
98+
Columns must be 'dni', 'ghi', 'dhi'
99+
weather : None or DataFrame
100+
If None, assumes air temperature is 20 C and
101+
wind speed is 0 m/s.
102+
Columns must be 'wind_speed', 'temp_air'.
103+
99104
Returns
100105
-------
101106
output : DataFrame
102107
Some combination of AC power, DC power, POA irrad, etc.
103108
"""
104109
solar_position = self.location.get_solarposition(times)
105-
clearsky = self.location.get_clearsky(solar_position.index,
106-
self.clearsky_model)
107-
irradiance = self.system.get_irradiance(solar_position['apparent_zenith'],
108-
solar_position['azimuth'],
109-
clearsky['dni'],
110-
clearsky['ghi'],
111-
clearsky['dhi'],
112-
model=self.transposition_model)
113-
temps = self.system.sapm_celltemp(irradiance['poa_global'], 0, 20)
110+
111+
if irradiance is None:
112+
irradiance = self.location.get_clearsky(solar_position.index,
113+
self.clearsky_model)
114+
115+
total_irrad = self.system.get_irradiance(solar_position['apparent_zenith'],
116+
solar_position['azimuth'],
117+
irradiance['dni'],
118+
irradiance['ghi'],
119+
irradiance['dhi'],
120+
model=self.transposition_model)
121+
122+
if weather is None:
123+
weather = {'wind_speed': 0, 'temp_air': 20}
124+
125+
temps = self.system.sapm_celltemp(total_irrad['poa_global'],
126+
weather['wind_speed'],
127+
weather['temp_air'])
114128

115129
aoi = self.system.get_aoi(solar_position['apparent_zenith'],
116130
solar_position['azimuth'])
@@ -119,8 +133,9 @@ def run_model(self, times):
119133
self.airmass_model)
120134
am_abs = self.location.get_absoluteairmass(am_rel)
121135

122-
dc = self.system.sapm(irradiance['poa_direct'],
123-
irradiance['poa_diffuse'], temps['temp_cell'],
136+
dc = self.system.sapm(total_irrad['poa_direct'],
137+
total_irrad['poa_diffuse'],
138+
temps['temp_cell'],
124139
am_abs, aoi)
125140

126141
ac = self.system.snlinverter(dc['v_mp'], dc['p_mp'])

0 commit comments

Comments
 (0)