Skip to content

Commit 16e69d4

Browse files
committed
refactor ModelChain. add SingleDiode modelchain
1 parent f1b36f2 commit 16e69d4

File tree

1 file changed

+78
-6
lines changed

1 file changed

+78
-6
lines changed

pvlib/modelchain.py

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def get_orientation(strategy, **kwargs):
208208

209209
class ModelChain(object):
210210
"""
211-
An experimental class that represents all of the modeling steps
211+
An experimental base class that represents all of the modeling steps
212212
necessary for calculating power or energy for a PV system at a given
213213
location.
214214
@@ -278,7 +278,7 @@ def orientation_strategy(self, strategy):
278278

279279
self._orientation_strategy = strategy
280280

281-
def run_model(self, times, irradiance=None, weather=None):
281+
def prepare_inputs(self, times, irradiance=None, weather=None):
282282
"""
283283
Run the model.
284284
@@ -301,15 +301,19 @@ def run_model(self, times, irradiance=None, weather=None):
301301
self
302302
303303
Assigns attributes: times, solar_position, airmass, irradiance,
304-
total_irrad, weather, temps, aoi, dc, ac
304+
total_irrad, weather, aoi
305305
"""
306+
306307
self.times = times
307308

308309
self.solar_position = self.location.get_solarposition(self.times)
309310

310311
self.airmass = self.location.get_airmass(
311312
solar_position=self.solar_position, model=self.airmass_model)
312313

314+
self.aoi = self.system.get_aoi(self.solar_position['apparent_zenith'],
315+
self.solar_position['azimuth'])
316+
313317
if irradiance is None:
314318
irradiance = self.location.get_clearsky(
315319
self.solar_position.index, self.clearsky_model,
@@ -329,13 +333,39 @@ def run_model(self, times, irradiance=None, weather=None):
329333
weather = {'wind_speed': 0, 'temp_air': 20}
330334
self.weather = weather
331335

336+
return self
337+
338+
def run_model(self):
339+
"""
340+
A stub function meant to be subclassed.
341+
"""
342+
raise NotImplementedError(
343+
'you must subclass ModelChain and implement this method')
344+
345+
346+
class SAPM(ModelChain):
347+
"""
348+
Uses the SAPM to calculate cell temperature, DC power and AC power.
349+
"""
350+
def run_model(self):
351+
"""
352+
Run the model.
353+
354+
Parameters
355+
----------
356+
357+
Returns
358+
-------
359+
self
360+
361+
Assigns attributes: temps, dc, ac
362+
"""
363+
364+
332365
self.temps = self.system.sapm_celltemp(self.total_irrad['poa_global'],
333366
self.weather['wind_speed'],
334367
self.weather['temp_air'])
335368

336-
self.aoi = self.system.get_aoi(self.solar_position['apparent_zenith'],
337-
self.solar_position['azimuth'])
338-
339369
self.dc = self.system.sapm(self.total_irrad['poa_direct'],
340370
self.total_irrad['poa_diffuse'],
341371
self.temps['temp_cell'],
@@ -345,3 +375,45 @@ def run_model(self, times, irradiance=None, weather=None):
345375
self.ac = self.system.snlinverter(self.dc['v_mp'], self.dc['p_mp'])
346376

347377
return self
378+
379+
380+
class SingleDiode(ModelChain):
381+
"""
382+
Uses the DeSoto and single diode models to calculate the DC power,
383+
and the SAPM models to calculate cell temperature and AC power.
384+
"""
385+
386+
def run_model(self):
387+
"""
388+
Run the model.
389+
390+
Parameters
391+
----------
392+
393+
Returns
394+
-------
395+
self
396+
397+
Assigns attributes: temps, dc, ac
398+
"""
399+
400+
401+
self.temps = self.system.sapm_celltemp(self.total_irrad['poa_global'],
402+
self.weather['wind_speed'],
403+
self.weather['temp_air'])
404+
405+
(photocurrent, saturation_current, resistance_series,
406+
resistance_shunt, nNsVth) = (
407+
self.system.calcparams_desoto(self.total_irrad['poa_global'],
408+
self.temps['temp_cell']))
409+
410+
self.desoto = (photocurrent, saturation_current, resistance_series,
411+
resistance_shunt, nNsVth)
412+
413+
self.dc = self.system.singlediode(
414+
photocurrent, saturation_current, resistance_series,
415+
resistance_shunt, nNsVth)
416+
417+
self.ac = self.system.snlinverter(self.dc['v_mp'], self.dc['p_mp'])
418+
419+
return self

0 commit comments

Comments
 (0)