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)) 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): diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index f6cc44ee3a..5f5237e57a 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -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. @@ -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: @@ -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, 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..bbbe143e33 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 '+ + 'orientation_startegy: south_at_latitude_tilt clearsky_model: '+ + 'ineichentransposition_model: haydavies solar_position_method: '+ + 'nrel_numpyairmass_model: kastenyoung1989') diff --git a/pvlib/test/test_pvsystem.py b/pvlib/test/test_pvsystem.py index 3bd6dadc7e..9910a9633f 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 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. @@ -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') diff --git a/pvlib/test/test_tracking.py b/pvlib/test/test_tracking.py index f77a33d7e4..a0ccd3632e 100644 --- a/pvlib/test/test_tracking.py +++ b/pvlib/test/test_tracking.py @@ -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') + diff --git a/pvlib/tracking.py b/pvlib/tracking.py index 4feee28706..14fdaadb37 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, @@ -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,