Skip to content

Instantly share code, notes, and snippets.

@wholmgren
Last active June 23, 2018 18:26
Show Gist options
  • Save wholmgren/d251dae069bce05e5144a8613f67d43d to your computer and use it in GitHub Desktop.
Save wholmgren/d251dae069bce05e5144a8613f67d43d to your computer and use it in GitHub Desktop.
# in ModelChain
def __init__(..., singlediode_calcparams_model=None)
# calls setters
self.singlediode_calcparams_model = singlediode_calcparams_model
@property
def singlediode_calcparams_model(self):
return self._singlediode_calcparams_model
@singlediode_calcparams_model.setter
def singlediode_calcparams_model(self, model):
if model is None:
self._singlediode_calcparams_model = self.infer_singlediode_calcparams_model()
elif isinstance(model, str):
model = model.lower()
if model == 'desoto':
self._singlediode_calcparams_model = self.calcparams_desoto
elif model == 'pvsyst':
self._singlediode_calcparams_model = self.calcparams_pvsyst
else:
raise ValueError(model + ' is not a valid calcparams power model')
else:
self._singlediode_calcparams_model = partial(model, self)
def infer_singlediode_calcparams_model(self):
params = set(self.system.module_parameters.keys())
if set([desoto_params_list]) <= params:
return self.calcparams_desoto
elif set([pvsyst_params_list]) <= params:
return self.calcparams_pvsyst
else:
raise ValueError('could not infer calcparams model from '
'system.module_parameters')
def calcparams_desoto(self):
self.singlediode_params = self.system.calcparams_desoto(self.effective_irradiance,
self.temps['temp_cell']))
return self
def calcparams_pvsyst(self):
self.singlediode_params = self.system.calcparams_pvsyst(self.effective_irradiance,
self.temps['temp_cell']))
return self
def singlediode(self):
# removed call to self.system.calcparams_desoto
# removed assignment to self.desoto
self.dc = self.system.singlediode(*self.singlediode_params)
self.dc = self.system.scale_voltage_current_power(self.dc).fillna(0)
return self
# in modelchain.py
# in ModelChain
def __init__(..., singlediode_calcparams_model=None)
# pure attribute, no setter needed
self.singlediode_calcparams_model = singlediode_calcparams_model
# calls setters
# dc_model will attempt to infer singlediode_calcparams_model
# if necessary
self.dc_model = dc_model
self.ac_model...
@property
def dc_model(self):
return self._dc_model
@dc_model.setter
def dc_model(self, model):
if model is None:
self._dc_model = self.infer_dc_model()
elif isinstance(model, str):
model = model.lower()
if model == 'sapm':
self._dc_model = self.sapm
elif model == 'singlediode':
self._dc_model = self.singlediode
elif model == 'pvwatts':
self._dc_model = self.pvwatts_dc
else:
raise ValueError(model + ' is not a valid DC power model')
else:
self._dc_model = partial(model, self)
def infer_dc_model(self):
if self.singlediode_calcparams_model is not None:
# user wants to use the singlediode model
return self.singlediode
try:
# see if we can use the singlediode model with any param sets
calcparams_model = self.infer_singlediode_calcparams_model()
except ValueError:
# not a singlediode param set, but it could be pvwatts or sapm
# so don't raise an exception to the user
pass
else:
# singlediode parameters detected
self.singlediode_calcparams_model = calcparams_model
return self.singlediode
params = set(self.system.module_parameters.keys())
if set(['A0', 'A1', 'C7']) <= params:
return self.sapm
elif set(['pdc0', 'gamma_pdc']) <= params:
return self.pvwatts_dc
else:
raise ValueError('could not infer DC model from '
'system.module_parameters')
def infer_singlediode_calcparams_model(self):
params = set(self.system.module_parameters.keys())
if set([desoto_params_list]) <= params:
return 'desoto'
elif set([pvsyst_params_list]) <= params:
return 'pvsyst'
else:
raise ValueError('could not infer calcparams model from '
'system.module_parameters')
def singlediode_calcparams(self):
self.singlediode_params = self.system.get_singlediode_params(
self.effective_irradiance, self.temps['temp_cell'],
model=self.singlediode_calcparams_model)
return self
def singlediode(self):
# removed call to self.system.calcparams_desoto
# removed assignment to self.desoto
self.singlediode_params = self.singlediode_calcparams()
self.dc = self.system.singlediode(*self.singlediode_params)
self.dc = self.system.scale_voltage_current_power(self.dc).fillna(0)
return self
# in pvsystem.py
# in PVSystem
def get_singlediode_params(self, effective_irradiance, temp_cell, model):
# dispatch to specified model,
# maybe with a little more model specific logic if necessary
model = model.lower()
if model == 'desoto':
params = self.calcparams_desoto(effective_irradiance, temp_cell)
elif model == 'pvsyst':
params = self.calcparams_pvsyst(effective_irradiance, temp_cell)
else:
raise ValueError(model + ' is not a valid calcparams power model')
return params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment