Skip to content

"add __repr__() function to class PVSystem, LocalizedPVSystem, ModelChain, SingleAxisTracker, Location and add test for same" #174

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

Merged
merged 10 commits into from
Jun 10, 2016
Merged
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
2 changes: 1 addition & 1 deletion pvlib/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, latitude, longitude, tz='UTC', altitude=0,



def __str__(self):
def __repr__(self):
return ('{}: latitude={}, longitude={}, tz={}, altitude={}'
.format(self.name, self.latitude, self.longitude,
self.tz, self.altitude))
Expand Down
8 changes: 8 additions & 0 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ def __init__(self, system, location,

# calls setter
self.orientation_strategy = orientation_strategy

def __repr__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. edit the PR name to reflect this addition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks.

return ('ModelChain for: '+ str(self.system) +
' orientation_startegy: ' + str(self.orientation_strategy) +
' clearsky_model: ' + str(self.clearsky_model) +
'transposition_model: ' + str(self.transposition_model) +
' solar_position_method: ' + str(self.solar_position_method) +
'airmass_model: ' + str(self.airmass_model))

@property
def orientation_strategy(self):
Expand Down
16 changes: 15 additions & 1 deletion pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ def __init__(self,

# needed for tying together Location and PVSystem in LocalizedPVSystem
super(PVSystem, self).__init__(**kwargs)

def __repr__(self):
return ('PVSystem with tilt:' + str(self.surface_tilt) +
' and azimuth: ' + str(self.surface_azimuth) +
' with Module: ' + str(self.module) +
' and Inverter: ' + str(self.inverter))

def get_aoi(self, solar_zenith, solar_azimuth):
"""Get the angle of incidence on the system.
Expand Down Expand Up @@ -436,7 +442,7 @@ def __init__(self, pvsystem=None, location=None, **kwargs):

# get and combine attributes from the pvsystem and/or location
# with the rest of the kwargs

if pvsystem is not None:
pv_dict = pvsystem.__dict__
else:
Expand All @@ -452,6 +458,14 @@ def __init__(self, pvsystem=None, location=None, **kwargs):
list(kwargs.items()))

super(LocalizedPVSystem, self).__init__(**new_kwargs)

def __repr__(self):
return ('LocalizedPVSystem with tilt:' + str(self.surface_tilt) +
' and azimuth: ' + str(self.surface_azimuth) +
' with Module: ' + str(self.module) +
' and Inverter: ' + str(self.inverter) +
' at Latitude: ' + str(self.latitude) +
' and Longitude: ' + str(self.longitude))


def systemdef(meta, surface_tilt, surface_azimuth, albedo, series_modules,
Expand Down
7 changes: 7 additions & 0 deletions pvlib/test/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,10 @@ def test_get_airmass_valueerror():
end='20160101T1800-0700',
freq='3H')
clearsky = tus.get_airmass(times, model='invalid_model')

def test_Location___repr__():
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
assert tus.__repr__()==('Tucson: latitude=32.2, longitude=-111, '+
'tz=US/Arizona, altitude=700')


15 changes: 15 additions & 0 deletions pvlib/test/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,18 @@ def test_basic_chain_altitude_pressure():
expected = pd.Series(np.array([ 1.15771428788e+02, -2.00000000e-02]),
index=times)
assert_series_equal(ac, expected)


def test_ModelChain___repr__():
system = PVSystem()
location = Location(32.2, -111, altitude=700)
strategy = 'south_at_latitude_tilt'

mc = ModelChain(system, location, orientation_strategy=strategy)

# the || accounts for the coercion of 'None' to None
assert mc.__repr__() == ('ModelChain for: PVSystem with tilt:32.2 and '+
'azimuth: 180 with Module: None and Inverter: None '+
'orientation_startegy: south_at_latitude_tilt clearsky_model: '+
'ineichentransposition_model: haydavies solar_position_method: '+
'nrel_numpyairmass_model: kastenyoung1989')
26 changes: 26 additions & 0 deletions pvlib/test/test_pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,21 @@ def test_PVSystem_localize_with_latlon():
assert localized_system.longitude == -111


def test_PVSystem___repr__():
system = pvsystem.PVSystem(module='blah', inverter='blarg')

assert system.__repr__()==('PVSystem with tilt:0 and azimuth:'+
' 180 with Module: blah and Inverter: blarg')


def test_PVSystem_localize___repr__():
system = pvsystem.PVSystem(module='blah', inverter='blarg')
localized_system = system.localize(latitude=32, longitude=-111)

assert localized_system.__repr__()==('LocalizedPVSystem with tilt:0 and'+
' azimuth: 180 with Module: blah and Inverter: blarg at '+
'Latitude: 32 and Longitude: -111')

# we could retest each of the models tested above
# when they are attached to LocalizedPVSystem, but
# that's probably not necessary at this point.
Expand All @@ -495,3 +510,14 @@ def test_LocalizedPVSystem_creation():
assert localized_system.inverter == 'blarg'
assert localized_system.latitude == 32
assert localized_system.longitude == -111


def test_LocalizedPVSystem___repr__():
localized_system = pvsystem.LocalizedPVSystem(latitude=32,
longitude=-111,
module='blah',
inverter='blarg')

assert localized_system.__repr__()==('LocalizedPVSystem with tilt:0 and'+
' azimuth: 180 with Module: blah and Inverter: blarg at Latitude: 32 ' +
'and Longitude: -111')
21 changes: 21 additions & 0 deletions pvlib/test/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,24 @@ def test_get_irradiance():
irradiance = np.round(irradiance, 4)
expected = np.round(expected, 4)
assert_frame_equal(irradiance, expected)


def test_SingleAxisTracker___repr__():
system = tracking.SingleAxisTracker(max_angle=45, gcr=.25,
module='blah', inverter='blarg')

assert system.__repr__() == 'SingleAxisTracker with max_angle: 45'


def test_LocalizedSingleAxisTracker___repr__():
localized_system = tracking.LocalizedSingleAxisTracker(latitude=32,
longitude=-111,
module='blah',
inverter='blarg')


assert localized_system.__repr__() == ('LocalizedSingleAxisTracker with '+
'max_angle: 90 at Location: None: '+
'latitude=32, longitude=-111, ' +
'tz=UTC, altitude=0')

16 changes: 15 additions & 1 deletion pvlib/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ def __init__(self, axis_tilt=0, axis_azimuth=0,
self.gcr = gcr

super(SingleAxisTracker, self).__init__(**kwargs)



def __repr__(self):
return ('SingleAxisTracker with max_angle: ' +
str(self.max_angle))


def singleaxis(self, apparent_zenith, apparent_azimuth):
tracking_data = singleaxis(apparent_zenith, apparent_azimuth,
Expand Down Expand Up @@ -158,6 +163,15 @@ def __init__(self, pvsystem=None, location=None, **kwargs):
list(kwargs.items()))

super(LocalizedSingleAxisTracker, self).__init__(**new_kwargs)


def __repr__(self):
return ('Localized' +
super(LocalizedSingleAxisTracker, self).__repr__()
+ ' at Location: ' +
('{}: latitude={}, longitude={}, tz={}, altitude={}'
.format(self.name, self.latitude, self.longitude,
self.tz, self.altitude)))


def singleaxis(apparent_zenith, apparent_azimuth,
Expand Down