Skip to content

Commit 5b56dae

Browse files
JohannesOoswholmgren
authored andcommitted
add __repr__ method to PVSystem, LocalizedPVSystem, ModelChain, SingleAxisTracker, Location (#174)
* "add __repr__ function to class PVSystem and LocalizedPVSystem" * update __repr__ in PVSystem and LocalizedPVSystem and add self.location in LocalizedPVSystem * add __repr__ for SingleAxisTracker and LocalizedSingleAxisTracker and self.location * add tests for __repr__() functions * test function for SingelAxisTrackerand LocalizedSingleAxisTracker * remove unnecassary location override and adjust __repr__ statement in Tracking * adjust str to repr in location file * add __repr__ to Modelchain * correct bug in modelchain reppr test * fix bug in test localized system repr and remove self.location in same
1 parent a8fe59f commit 5b56dae

8 files changed

+108
-3
lines changed

pvlib/location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(self, latitude, longitude, tz='UTC', altitude=0,
8787

8888

8989

90-
def __str__(self):
90+
def __repr__(self):
9191
return ('{}: latitude={}, longitude={}, tz={}, altitude={}'
9292
.format(self.name, self.latitude, self.longitude,
9393
self.tz, self.altitude))

pvlib/modelchain.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ def __init__(self, system, location,
268268

269269
# calls setter
270270
self.orientation_strategy = orientation_strategy
271+
272+
def __repr__(self):
273+
return ('ModelChain for: '+ str(self.system) +
274+
' orientation_startegy: ' + str(self.orientation_strategy) +
275+
' clearsky_model: ' + str(self.clearsky_model) +
276+
'transposition_model: ' + str(self.transposition_model) +
277+
' solar_position_method: ' + str(self.solar_position_method) +
278+
'airmass_model: ' + str(self.airmass_model))
271279

272280
@property
273281
def orientation_strategy(self):

pvlib/pvsystem.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ def __init__(self,
139139

140140
# needed for tying together Location and PVSystem in LocalizedPVSystem
141141
super(PVSystem, self).__init__(**kwargs)
142+
143+
def __repr__(self):
144+
return ('PVSystem with tilt:' + str(self.surface_tilt) +
145+
' and azimuth: ' + str(self.surface_azimuth) +
146+
' with Module: ' + str(self.module) +
147+
' and Inverter: ' + str(self.inverter))
142148

143149
def get_aoi(self, solar_zenith, solar_azimuth):
144150
"""Get the angle of incidence on the system.
@@ -437,7 +443,7 @@ def __init__(self, pvsystem=None, location=None, **kwargs):
437443

438444
# get and combine attributes from the pvsystem and/or location
439445
# with the rest of the kwargs
440-
446+
441447
if pvsystem is not None:
442448
pv_dict = pvsystem.__dict__
443449
else:
@@ -453,6 +459,14 @@ def __init__(self, pvsystem=None, location=None, **kwargs):
453459
list(kwargs.items()))
454460

455461
super(LocalizedPVSystem, self).__init__(**new_kwargs)
462+
463+
def __repr__(self):
464+
return ('LocalizedPVSystem with tilt:' + str(self.surface_tilt) +
465+
' and azimuth: ' + str(self.surface_azimuth) +
466+
' with Module: ' + str(self.module) +
467+
' and Inverter: ' + str(self.inverter) +
468+
' at Latitude: ' + str(self.latitude) +
469+
' and Longitude: ' + str(self.longitude))
456470

457471

458472
def systemdef(meta, surface_tilt, surface_azimuth, albedo, modules_per_string,

pvlib/test/test_location.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,10 @@ def test_get_airmass_valueerror():
160160
end='20160101T1800-0700',
161161
freq='3H')
162162
clearsky = tus.get_airmass(times, model='invalid_model')
163+
164+
def test_Location___repr__():
165+
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
166+
assert tus.__repr__()==('Tucson: latitude=32.2, longitude=-111, '+
167+
'tz=US/Arizona, altitude=700')
168+
169+

pvlib/test/test_modelchain.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,18 @@ def test_basic_chain_altitude_pressure():
220220
expected = pd.Series(np.array([ 1.15771428788e+02, -2.00000000e-02]),
221221
index=times)
222222
assert_series_equal(ac, expected)
223+
224+
225+
def test_ModelChain___repr__():
226+
system = PVSystem()
227+
location = Location(32.2, -111, altitude=700)
228+
strategy = 'south_at_latitude_tilt'
229+
230+
mc = ModelChain(system, location, orientation_strategy=strategy)
231+
232+
# the || accounts for the coercion of 'None' to None
233+
assert mc.__repr__() == ('ModelChain for: PVSystem with tilt:32.2 and '+
234+
'azimuth: 180 with Module: None and Inverter: None '+
235+
'orientation_startegy: south_at_latitude_tilt clearsky_model: '+
236+
'ineichentransposition_model: haydavies solar_position_method: '+
237+
'nrel_numpyairmass_model: kastenyoung1989')

pvlib/test/test_pvsystem.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,21 @@ def test_PVSystem_localize_with_latlon():
473473
assert localized_system.longitude == -111
474474

475475

476+
def test_PVSystem___repr__():
477+
system = pvsystem.PVSystem(module='blah', inverter='blarg')
478+
479+
assert system.__repr__()==('PVSystem with tilt:0 and azimuth:'+
480+
' 180 with Module: blah and Inverter: blarg')
481+
482+
483+
def test_PVSystem_localize___repr__():
484+
system = pvsystem.PVSystem(module='blah', inverter='blarg')
485+
localized_system = system.localize(latitude=32, longitude=-111)
486+
487+
assert localized_system.__repr__()==('LocalizedPVSystem with tilt:0 and'+
488+
' azimuth: 180 with Module: blah and Inverter: blarg at '+
489+
'Latitude: 32 and Longitude: -111')
490+
476491
# we could retest each of the models tested above
477492
# when they are attached to LocalizedPVSystem, but
478493
# that's probably not necessary at this point.
@@ -488,3 +503,14 @@ def test_LocalizedPVSystem_creation():
488503
assert localized_system.inverter == 'blarg'
489504
assert localized_system.latitude == 32
490505
assert localized_system.longitude == -111
506+
507+
508+
def test_LocalizedPVSystem___repr__():
509+
localized_system = pvsystem.LocalizedPVSystem(latitude=32,
510+
longitude=-111,
511+
module='blah',
512+
inverter='blarg')
513+
514+
assert localized_system.__repr__()==('LocalizedPVSystem with tilt:0 and'+
515+
' azimuth: 180 with Module: blah and Inverter: blarg at Latitude: 32 ' +
516+
'and Longitude: -111')

pvlib/test/test_tracking.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,24 @@ def test_get_irradiance():
286286
irradiance = np.round(irradiance, 4)
287287
expected = np.round(expected, 4)
288288
assert_frame_equal(irradiance, expected)
289+
290+
291+
def test_SingleAxisTracker___repr__():
292+
system = tracking.SingleAxisTracker(max_angle=45, gcr=.25,
293+
module='blah', inverter='blarg')
294+
295+
assert system.__repr__() == 'SingleAxisTracker with max_angle: 45'
296+
297+
298+
def test_LocalizedSingleAxisTracker___repr__():
299+
localized_system = tracking.LocalizedSingleAxisTracker(latitude=32,
300+
longitude=-111,
301+
module='blah',
302+
inverter='blarg')
303+
304+
305+
assert localized_system.__repr__() == ('LocalizedSingleAxisTracker with '+
306+
'max_angle: 90 at Location: None: '+
307+
'latitude=32, longitude=-111, ' +
308+
'tz=UTC, altitude=0')
309+

pvlib/tracking.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ def __init__(self, axis_tilt=0, axis_azimuth=0,
2929
self.gcr = gcr
3030

3131
super(SingleAxisTracker, self).__init__(**kwargs)
32-
32+
33+
34+
def __repr__(self):
35+
return ('SingleAxisTracker with max_angle: ' +
36+
str(self.max_angle))
37+
3338

3439
def singleaxis(self, apparent_zenith, apparent_azimuth):
3540
tracking_data = singleaxis(apparent_zenith, apparent_azimuth,
@@ -158,6 +163,15 @@ def __init__(self, pvsystem=None, location=None, **kwargs):
158163
list(kwargs.items()))
159164

160165
super(LocalizedSingleAxisTracker, self).__init__(**new_kwargs)
166+
167+
168+
def __repr__(self):
169+
return ('Localized' +
170+
super(LocalizedSingleAxisTracker, self).__repr__()
171+
+ ' at Location: ' +
172+
('{}: latitude={}, longitude={}, tz={}, altitude={}'
173+
.format(self.name, self.latitude, self.longitude,
174+
self.tz, self.altitude)))
161175

162176

163177
def singleaxis(apparent_zenith, apparent_azimuth,

0 commit comments

Comments
 (0)