Skip to content

Commit 0f36234

Browse files
committed
create PVSystem.localize, allow LocalizedPVSystem pvsystem and location kwargs
1 parent 2bbc618 commit 0f36234

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

pvlib/location.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class Location(object):
6262

6363
def __init__(self, latitude, longitude, tz='UTC', altitude=0,
6464
name=None, **kwargs):
65-
66-
pvl_logger.debug('creating Location object')
6765

6866
self.latitude = latitude
6967
self.longitude = longitude
@@ -82,7 +80,8 @@ def __init__(self, latitude, longitude, tz='UTC', altitude=0,
8280
self.name = name
8381

8482
# needed for tying together Location and PVSystem in LocalizedPVSystem
85-
super(Location, self).__init__(**kwargs)
83+
# if LocalizedPVSystem signature is reversed
84+
# super(Location, self).__init__(**kwargs)
8685

8786

8887

pvlib/pvsystem.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,30 @@ def snlinverter(self, v_dc, p_dc):
375375
return snlinverter(self.inverter_parameters, v_dc, p_dc)
376376

377377

378+
def localize(self, location=None, latitude=None, longitude=None,
379+
**kwargs):
380+
"""Creates a LocalizedPVSystem object using this object
381+
and location data. Must supply either location object or
382+
latitude, longitude, and any location kwargs
383+
384+
Parameters
385+
----------
386+
location : None or Location
387+
latitude : None or float
388+
longitude : None or float
389+
**kwargs : see Location
390+
391+
Returns
392+
-------
393+
localized_system : LocalizedPVSystem
394+
"""
395+
396+
if location is None:
397+
location = Location(latitude, longitude, **kwargs)
398+
399+
return LocalizedPVSystem(pvsystem=self, location=location)
400+
401+
378402
class LocalizedPVSystem(PVSystem, Location):
379403
"""
380404
The LocalizedPVSystem class defines a standard set of
@@ -385,8 +409,26 @@ class LocalizedPVSystem(PVSystem, Location):
385409
See the :class:`PVSystem` class for an object model that
386410
describes an unlocalized PV system.
387411
"""
388-
def __init__(self, **kwargs):
389-
super(LocalizedPVSystem, self).__init__(**kwargs)
412+
def __init__(self, pvsystem=None, location=None, **kwargs):
413+
414+
# get and combine attributes from the pvsystem and/or location
415+
# with the rest of the kwargs
416+
417+
if pvsystem is not None:
418+
pv_dict = pvsystem.__dict__
419+
else:
420+
pv_dict = {}
421+
422+
if location is not None:
423+
loc_dict = location.__dict__
424+
else:
425+
loc_dict = {}
426+
427+
new_kwargs = dict(list(pv_dict.items()) +
428+
list(loc_dict.items()) +
429+
list(kwargs.items()))
430+
431+
super(LocalizedPVSystem, self).__init__(**new_kwargs)
390432

391433

392434
def systemdef(meta, surface_tilt, surface_azimuth, albedo, series_modules,

0 commit comments

Comments
 (0)