Skip to content

remove arbitrary kwargs from Location, PVSystem, SingleAxisTracker, ModelChain #1034

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -68,6 +68,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:
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 @@ -333,10 +333,6 @@ class ModelChain:

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 @@ -347,7 +343,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:

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
12 changes: 8 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, tand
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 @@ -55,6 +55,9 @@ class SingleAxisTracker(PVSystem):
:func:`~pvlib.tracking.calc_cross_axis_tilt` to calculate
`cross_axis_tilt`. [degrees]

**kwargs
Passed to PVSystem

See also
--------
pvlib.tracking.singleaxis
Expand Down Expand Up @@ -249,14 +252,15 @@ class combines the attributes and methods of the

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