8000 Change setter for losses_model to allow it to set multiple loss funct… by ncroft-b4 · Pull Request #1084 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Change setter for losses_model to allow it to set multiple loss funct… #1084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add dc_ohmic_model to model chain
  • Loading branch information
ncroft-b4 committed Nov 29, 2020
commit 6860cdf97e186e7e36f2fdb4978f798615e47861
45 changes: 45 additions & 0 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ class ModelChain:
The ModelChain instance will be passed as the first argument to a
user-defined function.

dc_ohmic_model: None, str or function, default None
Valid strings are 'dc_ohms_from_percent', 'no_loss'. The ModelChain
instance will be passed as the first argument to a user-defined
function.

losses_model: str or function, default 'no_loss'
Valid strings are 'pvwatts', 'no_loss'. The ModelChain instance
will be passed as the first argument to a user-defined function.
Expand All @@ -343,6 +348,7 @@ def __init__(self, system, location,
airmass_model='kastenyoung1989',
dc_model=None, ac_model=None, aoi_model=None,
spectral_model=None, temperature_model=None,
dc_ohmic_model=None,
losses_model='no_loss', name=None, **kwargs):

self.name = name
Expand All @@ -361,7 +367,10 @@ def __init__(self, system, location,
self.spectral_model = spectral_model
self.temperature_model = temperature_model

# losses
self.dc_ohmic_model = dc_ohmic_model
self.losses_model = losses_model

self.orientation_strategy = orientation_strategy

self.weather = None
Expand Down Expand Up @@ -924,6 +933,41 @@ def fuentes_temp(self):
self.weather['wind_speed'])
return self

@property
def dc_ohmic_model(self):
return self._dc_ohmic_model

@dc_ohmic_model.setter
def dc_ohmic_model(self, model):
if model is None:
self._dc_ohmic_model = self.no_dc_ohmic_loss
elif isinstance(model, str):
model = model.lower()
if model == 'dc_ohms_from_percent':
self._dc_ohmic_model = self.dc_ohms_from_percent
elif model == 'no_loss':
self._dc_ohmic_model = self.no_dc_ohmic_loss
else:
raise ValueError(model + ' is not a valid losses model')
else:
self._dc_ohmic_model = partial(model, self)

def dc_ohms_from_percent(self):
"""
Calculate time series of ohmic losses and apply those to the mpp power
output of the `dc_model` based on the pvsyst equivalent resistance
method. Uses a `dc_ohmic_percent` parameter in the `losses_parameters`
of the PVsystem.
"""
Rw = self.system.dc_ohms_from_percent()
ohmic_loss_fraction = Rw * self.dc['i_mp'] / self.dc['v_mp']
self.dc_ohmic_losses = ohmic_loss_fraction * self.dc['p_mp']
self.dc['p_mp'] = self.dc['p_mp'] - self.dc_ohmic_losses
return self

def no_dc_ohmic_loss(self):
return self

@property
def losses_model(self):
return self._losses_model
Expand Down Expand Up @@ -1374,6 +1418,7 @@ def _run_from_effective_irrad(self, data=None):
"""
self._prepare_temperature(data)
self.dc_model()
self.dc_ohmic_model()
self.losses_model()
self.ac_model()

Expand Down
0