Skip to content

Commit

Permalink
remove arbitrary kwargs from Location, PVSystem, SingleAxisTracker, M…
Browse files Browse the repository at this point in the history
…odelChain
  • Loading branch information
wholmgren committed Aug 27, 2020
1 parent 75369dc commit 313d2ef
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 37 deletions.
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.8.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ API Changes
The index of the input DataFrame is used instead.
* ``temp_model`` keyword argument of
:py:meth:`pvlib.modelchain.ModelChain`. Use ``temperature_model`` instead.
* Objects :py:class:`pvlib.location.Location`, :py:class:`pvlib.pvsystem.PVSystem`,
:py:class:`pvlib.tracking.SingleAxisTracker`, :py:class:`pvlib.modelchain.ModelChain`,
and subclasses no longer accept arbitrary keyword arguments. (:issue:`1029`)

Enhancements
~~~~~~~~~~~~
Expand Down
7 changes: 1 addition & 6 deletions pvlib/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,12 @@ class Location(object):
name : None or string, default None.
Sets the name attribute of the Location object.
**kwargs
Arbitrary keyword arguments.
Included for compatibility, but not used.
See also
--------
pvlib.pvsystem.PVSystem
"""

def __init__(self, latitude, longitude, tz='UTC', altitude=0,
name=None, **kwargs):
def __init__(self, latitude, longitude, tz='UTC', altitude=0, name=None):

self.latitude = latitude
self.longitude = longitude
Expand Down
6 changes: 1 addition & 5 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,6 @@ class ModelChain(object):
name: None or str, default None
Name of ModelChain instance.
**kwargs
Arbitrary keyword arguments. Included for compatibility, but not
used.
"""

def __init__(self, system, location,
Expand All @@ -330,7 +326,7 @@ def __init__(self, system, location,
airmass_model='kastenyoung1989',
dc_model=None, ac_model=None, aoi_model=None,
spectral_model=None, temperature_model=None,
losses_model='no_loss', name=None, **kwargs):
losses_model='no_loss', name=None):

self.name = name
self.system = system
Expand Down
49 changes: 27 additions & 22 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,35 @@
}


def _combine_localized_attributes(pvsystem=None, location=None, **kwargs):
def _parse_localized_attributes(pvsystem=None, tracker=False, location=None,
**kwargs):
"""
Get and combine attributes from the pvsystem and/or location
Get and parse attributes from the pvsystem and/or location
with the rest of the kwargs.
"""
if pvsystem is not None:
pv_dict = pvsystem.__dict__
pvsystem_kwargs = [
'surface_tilt', 'surface_azimuth', 'surface_type', 'albedo', 'module',
'module_parameters', 'module_type', 'racking_model',
'temperature_model_parameters', 'modules_per_string',
'strings_per_inverter', 'inverter', 'inverter_parameters',
'losses_parameters', 'name'
]
if tracker:
pvsystem_kwargs += [
'axis_tilt', 'axis_azimuth', 'max_angle', 'backtrack', 'gcr'
]
if pvsystem is None:
pv_dict = {k: kwargs[k] for k in pvsystem_kwargs if k in kwargs}
else:
pv_dict = {}
pv_dict = {attr: getattr(pvsystem, attr) for attr in pvsystem_kwargs}

if location is not None:
loc_dict = location.__dict__
location_kwargs = ['latitude', 'longitude', 'tz', 'altitude', 'name']
if location is None:
loc_dict = {k: kwargs[k] for k in location_kwargs if k in kwargs}
else:
loc_dict = {}
loc_dict = {attr: getattr(location, attr) for attr in location_kwargs}

new_kwargs = dict(
list(pv_dict.items()) + list(loc_dict.items()) + list(kwargs.items())
)
return new_kwargs
return pv_dict, loc_dict


# not sure if this belongs in the pvsystem module.
Expand Down Expand Up @@ -156,10 +166,6 @@ class PVSystem(object):
name : None or string, default None
**kwargs
Arbitrary keyword arguments.
Included for compatibility, but not used.
See also
--------
pvlib.location.Location
Expand All @@ -175,8 +181,7 @@ def __init__(self,
temperature_model_parameters=None,
modules_per_string=1, strings_per_inverter=1,
inverter=None, inverter_parameters=None,
racking_model=None, losses_parameters=None, name=None,
**kwargs):
racking_model=None, losses_parameters=None, name=None):

self.surface_tilt = surface_tilt
self.surface_azimuth = surface_azimuth
Expand Down Expand Up @@ -856,14 +861,14 @@ class LocalizedPVSystem(PVSystem, Location):
"""
def __init__(self, pvsystem=None, location=None, **kwargs):

new_kwargs = _combine_localized_attributes(
pv_dict, loc_dict = _parse_localized_attributes(
pvsystem=pvsystem,
location=location,
**kwargs,
**kwargs
)

PVSystem.__init__(self, **new_kwargs)
Location.__init__(self, **new_kwargs)
PVSystem.__init__(self, **pv_dict)
Location.__init__(self, **loc_dict)

def __repr__(self):
attrs = ['name', 'latitude', 'longitude', 'altitude', 'tz',
Expand Down
11 changes: 7 additions & 4 deletions pvlib/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pandas as pd

from pvlib.tools import cosd, sind
from pvlib.pvsystem import _combine_localized_attributes
from pvlib.pvsystem import _parse_localized_attributes
from pvlib.pvsystem import PVSystem
from pvlib.location import Location
from pvlib import irradiance, atmosphere
Expand Down Expand Up @@ -43,6 +43,8 @@ class SingleAxisTracker(PVSystem):
between the tracking axes has a gcr of 2/6=0.333. If gcr is not
provided, a gcr of 2/7 is default. gcr must be <=1.
**kwargs
Passed to PVSystem
"""

def __init__(self, axis_tilt=0, axis_azimuth=0,
Expand Down Expand Up @@ -228,14 +230,15 @@ class LocalizedSingleAxisTracker(SingleAxisTracker, Location):

def __init__(self, pvsystem=None, location=None, **kwargs):

new_kwargs = _combine_localized_attributes(
pv_dict, loc_dict = _parse_localized_attributes(
pvsystem=pvsystem,
tracker=True,
location=location,
**kwargs,
)

SingleAxisTracker.__init__(self, **new_kwargs)
Location.__init__(self, **new_kwargs)
SingleAxisTracker.__init__(self, **pv_dict)
Location.__init__(self, **loc_dict)

def __repr__(self):
attrs = ['latitude', 'longitude', 'altitude', 'tz']
Expand Down

0 comments on commit 313d2ef

Please sign in to comment.