From 01fa4aaf02f6b00899bb95eb841c908672e8f26d Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Mon, 16 May 2016 08:52:46 +0300 Subject: [PATCH 01/10] "add __repr__ function to class PVSystem and LocalizedPVSystem" --- pvlib/pvsystem.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index f6cc44ee3a..df870e020f 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -139,6 +139,9 @@ 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) def get_aoi(self, solar_zenith, solar_azimuth): """Get the angle of incidence on the system. @@ -452,6 +455,9 @@ def __init__(self, pvsystem=None, location=None, **kwargs): list(kwargs.items())) super(LocalizedPVSystem, self).__init__(**new_kwargs) + + def __repr__(self): + return 'LocalizedPVSystem' def systemdef(meta, surface_tilt, surface_azimuth, albedo, series_modules, From a0ad437d16f2c7e1b114264d134dc38dceb036b3 Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Tue, 17 May 2016 08:07:17 +0300 Subject: [PATCH 02/10] update __repr__ in PVSystem and LocalizedPVSystem and add self.location in LocalizedPVSystem --- pvlib/pvsystem.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index df870e020f..abfcb70653 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -141,7 +141,10 @@ def __init__(self, super(PVSystem, self).__init__(**kwargs) def __repr__(self): - return 'PVSystem with tilt:' + str(self.surface_tilt) + ' and azimuth: ' + str(self.surface_azimuth) + 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. @@ -439,7 +442,9 @@ def __init__(self, pvsystem=None, location=None, **kwargs): # get and combine attributes from the pvsystem and/or location # with the rest of the kwargs - + + self.location = location + if pvsystem is not None: pv_dict = pvsystem.__dict__ else: @@ -457,7 +462,11 @@ def __init__(self, pvsystem=None, location=None, **kwargs): super(LocalizedPVSystem, self).__init__(**new_kwargs) def __repr__(self): - return 'LocalizedPVSystem' + return ('LocalizedPVSystem with tilt:' + str(self.surface_tilt) + + ' and azimuth: ' + str(self.surface_azimuth) + + ' with Module: ' + str(self.module) + + ' and Inverter: ' + str(self.inverter) + + ' and Location: ' + str(self.location)) def systemdef(meta, surface_tilt, surface_azimuth, albedo, series_modules, From c2da2635da3d99c1bb99f32a7beffacbe41a9196 Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Wed, 18 May 2016 08:31:36 +0300 Subject: [PATCH 03/10] add __repr__ for SingleAxisTracker and LocalizedSingleAxisTracker and self.location --- pvlib/tracking.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pvlib/tracking.py b/pvlib/tracking.py index 4feee28706..70b4aaeb4a 100644 --- a/pvlib/tracking.py +++ b/pvlib/tracking.py @@ -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, @@ -143,6 +148,8 @@ def __init__(self, pvsystem=None, location=None, **kwargs): # get and combine attributes from the pvsystem and/or location # with the rest of the kwargs + self.location = location + if pvsystem is not None: pv_dict = pvsystem.__dict__ else: @@ -158,6 +165,12 @@ 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: ' + str(self.location)) def singleaxis(apparent_zenith, apparent_azimuth, From b575cf6bb4874f2dcd22e2fd26426aa5e4653997 Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Thu, 19 May 2016 09:10:02 +0300 Subject: [PATCH 04/10] add tests for __repr__() functions --- pvlib/test/test_location.py | 7 +++++++ pvlib/test/test_modelchain.py | 15 +++++++++++++++ pvlib/test/test_pvsystem.py | 25 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/pvlib/test/test_location.py b/pvlib/test/test_location.py index 9ac4719cd3..b2a9163d7b 100644 --- a/pvlib/test/test_location.py +++ b/pvlib/test/test_location.py @@ -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') + + diff --git a/pvlib/test/test_modelchain.py b/pvlib/test/test_modelchain.py index e590325113..03a7df0e39 100644 --- a/pvlib/test/test_modelchain.py +++ b/pvlib/test/test_modelchain.py @@ -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 with '+ + 'orientation_startegy: south_at_latitude_tilt clearsky_model:ineichen '+ + 'transposition_model: haydavies solar_position_method: nrel_numpy '+ + 'airmass_model: kastenyoung1989') diff --git a/pvlib/test/test_pvsystem.py b/pvlib/test/test_pvsystem.py index 3bd6dadc7e..c1747c9ef6 100644 --- a/pvlib/test/test_pvsystem.py +++ b/pvlib/test/test_pvsystem.py @@ -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 and Location: None:'+ + ' latitude=32, longitude=-111, tz=UTC, altitude=0') + # we could retest each of the models tested above # when they are attached to LocalizedPVSystem, but # that's probably not necessary at this point. @@ -495,3 +510,13 @@ 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 and Location: None') From 91ccfd486179432cc4a987bea74ebe5bc735e486 Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Sat, 21 May 2016 17:26:01 +0300 Subject: [PATCH 05/10] test function for SingelAxisTrackerand LocalizedSingleAxisTracker --- pvlib/test/test_tracking.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pvlib/test/test_tracking.py b/pvlib/test/test_tracking.py index f77a33d7e4..65cfc19929 100644 --- a/pvlib/test/test_tracking.py +++ b/pvlib/test/test_tracking.py @@ -286,3 +286,22 @@ 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') + From 6aa1597dfa78ca194855ef48f2f70160bc6259d7 Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Sat, 21 May 2016 17:43:22 +0300 Subject: [PATCH 06/10] remove unnecassary location override and adjust __repr__ statement in Tracking --- pvlib/test/test_tracking.py | 4 +++- pvlib/tracking.py | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pvlib/test/test_tracking.py b/pvlib/test/test_tracking.py index 65cfc19929..a0ccd3632e 100644 --- a/pvlib/test/test_tracking.py +++ b/pvlib/test/test_tracking.py @@ -303,5 +303,7 @@ def test_LocalizedSingleAxisTracker___repr__(): assert localized_system.__repr__() == ('LocalizedSingleAxisTracker with '+ - 'max_angle: 90 at Location: None') + 'max_angle: 90 at Location: None: '+ + 'latitude=32, longitude=-111, ' + + 'tz=UTC, altitude=0') diff --git a/pvlib/tracking.py b/pvlib/tracking.py index 70b4aaeb4a..14fdaadb37 100644 --- a/pvlib/tracking.py +++ b/pvlib/tracking.py @@ -148,8 +148,6 @@ def __init__(self, pvsystem=None, location=None, **kwargs): # get and combine attributes from the pvsystem and/or location # with the rest of the kwargs - self.location = location - if pvsystem is not None: pv_dict = pvsystem.__dict__ else: @@ -170,7 +168,10 @@ def __init__(self, pvsystem=None, location=None, **kwargs): def __repr__(self): return ('Localized' + super(LocalizedSingleAxisTracker, self).__repr__() - + ' at Location: ' + str(self.location)) + + ' at Location: ' + + ('{}: latitude={}, longitude={}, tz={}, altitude={}' + .format(self.name, self.latitude, self.longitude, + self.tz, self.altitude))) def singleaxis(apparent_zenith, apparent_azimuth, From 36a2d28a8e09c1e38e2ae6a82228b20aa335b06f Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Tue, 24 May 2016 15:44:08 +0300 Subject: [PATCH 07/10] adjust str to repr in location file --- pvlib/location.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/location.py b/pvlib/location.py index 1b0b9db23e..f926244a58 100644 --- a/pvlib/location.py +++ b/pvlib/location.py @@ -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)) From 9a135872e3d8c7bddb2bfac1271a2c9f503297e2 Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Tue, 24 May 2016 15:51:58 +0300 Subject: [PATCH 08/10] add __repr__ to Modelchain --- pvlib/modelchain.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pvlib/modelchain.py b/pvlib/modelchain.py index cedffce9fc..010fed8270 100644 --- a/pvlib/modelchain.py +++ b/pvlib/modelchain.py @@ -265,6 +265,14 @@ def __init__(self, system, location, # calls setter self.orientation_strategy = orientation_strategy + + def __repr__(self): + 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): From 217b0481e486afc64efd4810d486343ad9333dea Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Sun, 29 May 2016 09:15:51 +0300 Subject: [PATCH 09/10] correct bug in modelchain reppr test --- pvlib/test/test_modelchain.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pvlib/test/test_modelchain.py b/pvlib/test/test_modelchain.py index 03a7df0e39..bbbe143e33 100644 --- a/pvlib/test/test_modelchain.py +++ b/pvlib/test/test_modelchain.py @@ -231,7 +231,7 @@ def test_ModelChain___repr__(): # 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 with '+ - 'orientation_startegy: south_at_latitude_tilt clearsky_model:ineichen '+ - 'transposition_model: haydavies solar_position_method: nrel_numpy '+ - 'airmass_model: kastenyoung1989') + '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') From 1077bff8615872ec85a94723f09ad37740536343 Mon Sep 17 00:00:00 2001 From: Johannes Oos Date: Sun, 29 May 2016 09:40:13 +0300 Subject: [PATCH 10/10] fix bug in test localized system repr and remove self.location in same --- pvlib/pvsystem.py | 5 ++--- pvlib/test/test_pvsystem.py | 7 ++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index abfcb70653..5f5237e57a 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -443,8 +443,6 @@ def __init__(self, pvsystem=None, location=None, **kwargs): # get and combine attributes from the pvsystem and/or location # with the rest of the kwargs - self.location = location - if pvsystem is not None: pv_dict = pvsystem.__dict__ else: @@ -466,7 +464,8 @@ def __repr__(self): ' and azimuth: ' + str(self.surface_azimuth) + ' with Module: ' + str(self.module) + ' and Inverter: ' + str(self.inverter) + - ' and Location: ' + str(self.location)) + ' at Latitude: ' + str(self.latitude) + + ' and Longitude: ' + str(self.longitude)) def systemdef(meta, surface_tilt, surface_azimuth, albedo, series_modules, diff --git a/pvlib/test/test_pvsystem.py b/pvlib/test/test_pvsystem.py index c1747c9ef6..9910a9633f 100644 --- a/pvlib/test/test_pvsystem.py +++ b/pvlib/test/test_pvsystem.py @@ -492,8 +492,8 @@ def test_PVSystem_localize___repr__(): 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 and Location: None:'+ - ' latitude=32, longitude=-111, tz=UTC, altitude=0') + ' 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 @@ -519,4 +519,5 @@ def test_LocalizedPVSystem___repr__(): inverter='blarg') assert localized_system.__repr__()==('LocalizedPVSystem with tilt:0 and'+ - ' azimuth: 180 with Module: blah and Inverter: blarg and Location: None') + ' azimuth: 180 with Module: blah and Inverter: blarg at Latitude: 32 ' + + 'and Longitude: -111')