Repository: pvlib/pvlib-python

Issue:
expand PVSystem repr
The PVSystem repr is

https://github.com/pvlib/pvlib-python/blob/27872b83b0932cc419116f79e442963cced935bb/pvlib/pvsystem.py#L239-L243

The main issue that I have is that the repr doesn't give me enough information about the temperature model settings. It's relatively important because `temperature_model_params` (not printed) may be inferred from `module_type` (not printed) and `racking_model` (printed). So I'd like to add both `temperature_model_params` and `module_type`.

We also don't include `module_parameters`, `inverter_parameters`, and `losses_parameters` in the repr. If I recall correctly, we decided against including these because they can be relatively long. I still think that's reasonable. We could add something like `if len(module_parameters): 'Set. See PVSystem.module_parameters'; else: {}`, but I don't know if that's worth the effort.


Discussion:

Patch:
diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py
--- a/pvlib/pvsystem.py
+++ b/pvlib/pvsystem.py
@@ -238,8 +238,9 @@ def __init__(self,
 
     def __repr__(self):
         attrs = ['name', 'surface_tilt', 'surface_azimuth', 'module',
-                 'inverter', 'albedo', 'racking_model']
-        return ('PVSystem: \n  ' + '\n  '.join(
+                 'inverter', 'albedo', 'racking_model', 'module_type',
+                 'temperature_model_parameters']
+        return ('PVSystem:\n  ' + '\n  '.join(
             ('{}: {}'.format(attr, getattr(self, attr)) for attr in attrs)))
 
     def get_aoi(self, solar_zenith, solar_azimuth):
@@ -898,8 +899,9 @@ def __init__(self, pvsystem=None, location=None, **kwargs):
     def __repr__(self):
         attrs = ['name', 'latitude', 'longitude', 'altitude', 'tz',
                  'surface_tilt', 'surface_azimuth', 'module', 'inverter',
-                 'albedo', 'racking_model']
-        return ('LocalizedPVSystem: \n  ' + '\n  '.join(
+                 'albedo', 'racking_model', 'module_type',
+                 'temperature_model_parameters']
+        return ('LocalizedPVSystem:\n  ' + '\n  '.join(
             ('{}: {}'.format(attr, getattr(self, attr)) for attr in attrs)))
 
 
diff --git a/pvlib/tracking.py b/pvlib/tracking.py
--- a/pvlib/tracking.py
+++ b/pvlib/tracking.py
@@ -61,7 +61,7 @@ def __init__(self, axis_tilt=0, axis_azimuth=0,
 
     def __repr__(self):
         attrs = ['axis_tilt', 'axis_azimuth', 'max_angle', 'backtrack', 'gcr']
-        sat_repr = ('SingleAxisTracker: \n  ' + '\n  '.join(
+        sat_repr = ('SingleAxisTracker:\n  ' + '\n  '.join(
             ('{}: {}'.format(attr, getattr(self, attr)) for attr in attrs)))
         # get the parent PVSystem info
         pvsystem_repr = super(SingleAxisTracker, self).__repr__()


Test patch:
diff --git a/pvlib/tests/test_pvsystem.py b/pvlib/tests/test_pvsystem.py
--- a/pvlib/tests/test_pvsystem.py
+++ b/pvlib/tests/test_pvsystem.py
@@ -1119,23 +1119,43 @@ def test_PVSystem_localize_with_latlon():
 
 
 def test_PVSystem___repr__():
-    system = pvsystem.PVSystem(module='blah', inverter='blarg', name='pv ftw')
-
-    expected = ('PVSystem: \n  name: pv ftw\n  surface_tilt: 0\n  '
-                'surface_azimuth: 180\n  module: blah\n  inverter: blarg\n  '
-                'albedo: 0.25\n  racking_model: open_rack')
-
+    system = pvsystem.PVSystem(
+        module='blah', inverter='blarg', name='pv ftw',
+        temperature_model_parameters={'a': -3.56})
+
+    expected = """PVSystem:
+  name: pv ftw
+  surface_tilt: 0
+  surface_azimuth: 180
+  module: blah
+  inverter: blarg
+  albedo: 0.25
+  racking_model: open_rack
+  module_type: glass_polymer
+  temperature_model_parameters: {'a': -3.56}"""
     assert system.__repr__() == expected
 
 
 def test_PVSystem_localize___repr__():
-    system = pvsystem.PVSystem(module='blah', inverter='blarg', name='pv ftw')
+    system = pvsystem.PVSystem(
+        module='blah', inverter='blarg', name='pv ftw',
+        temperature_model_parameters={'a': -3.56})
     localized_system = system.localize(latitude=32, longitude=-111)
-
-    expected = ('LocalizedPVSystem: \n  name: None\n  latitude: 32\n  '
-                'longitude: -111\n  altitude: 0\n  tz: UTC\n  '
-                'surface_tilt: 0\n  surface_azimuth: 180\n  module: blah\n  '
-                'inverter: blarg\n  albedo: 0.25\n  racking_model: open_rack')
+    # apparently name is not preserved when creating a system using localize
+    expected = """LocalizedPVSystem:
+  name: None
+  latitude: 32
+  longitude: -111
+  altitude: 0
+  tz: UTC
+  surface_tilt: 0
+  surface_azimuth: 180
+  module: blah
+  inverter: blarg
+  albedo: 0.25
+  racking_model: open_rack
+  module_type: glass_polymer
+  temperature_model_parameters: {'a': -3.56}"""
 
     assert localized_system.__repr__() == expected
 
@@ -1158,16 +1178,24 @@ def test_LocalizedPVSystem_creation():
 
 
 def test_LocalizedPVSystem___repr__():
-    localized_system = pvsystem.LocalizedPVSystem(latitude=32,
-                                                  longitude=-111,
-                                                  module='blah',
-                                                  inverter='blarg',
-                                                  name='my name')
-
-    expected = ('LocalizedPVSystem: \n  name: my name\n  latitude: 32\n  '
-                'longitude: -111\n  altitude: 0\n  tz: UTC\n  '
-                'surface_tilt: 0\n  surface_azimuth: 180\n  module: blah\n  '
-                'inverter: blarg\n  albedo: 0.25\n  racking_model: open_rack')
+    localized_system = pvsystem.LocalizedPVSystem(
+        latitude=32, longitude=-111, module='blah', inverter='blarg',
+        name='my name', temperature_model_parameters={'a': -3.56})
+
+    expected = """LocalizedPVSystem:
+  name: my name
+  latitude: 32
+  longitude: -111
+  altitude: 0
+  tz: UTC
+  surface_tilt: 0
+  surface_azimuth: 180
+  module: blah
+  inverter: blarg
+  albedo: 0.25
+  racking_model: open_rack
+  module_type: glass_polymer
+  temperature_model_parameters: {'a': -3.56}"""
 
     assert localized_system.__repr__() == expected
 
diff --git a/pvlib/tests/test_tracking.py b/pvlib/tests/test_tracking.py
--- a/pvlib/tests/test_tracking.py
+++ b/pvlib/tests/test_tracking.py
@@ -438,28 +438,51 @@ def test_get_irradiance():
 
 
 def test_SingleAxisTracker___repr__():
-    system = tracking.SingleAxisTracker(max_angle=45, gcr=.25,
-                                        module='blah', inverter='blarg')
-    expected = ('SingleAxisTracker: \n  axis_tilt: 0\n  axis_azimuth: 0\n  '
-                'max_angle: 45\n  backtrack: True\n  gcr: 0.25\n  '
-                'name: None\n  surface_tilt: None\n  surface_azimuth: None\n  '
-                'module: blah\n  inverter: blarg\n  albedo: 0.25\n  '
-                'racking_model: open_rack')
+    system = tracking.SingleAxisTracker(
+        max_angle=45, gcr=.25, module='blah', inverter='blarg',
+        temperature_model_parameters={'a': -3.56})
+    expected = """SingleAxisTracker:
+  axis_tilt: 0
+  axis_azimuth: 0
+  max_angle: 45
+  backtrack: True
+  gcr: 0.25
+  name: None
+  surface_tilt: None
+  surface_azimuth: None
+  module: blah
+  inverter: blarg
+  albedo: 0.25
+  racking_model: open_rack
+  module_type: glass_polymer
+  temperature_model_parameters: {'a': -3.56}"""
     assert system.__repr__() == expected
 
 
 def test_LocalizedSingleAxisTracker___repr__():
-    localized_system = tracking.LocalizedSingleAxisTracker(latitude=32,
-                                                           longitude=-111,
-                                                           module='blah',
-                                                           inverter='blarg',
-                                                           gcr=0.25)
-
-    expected = ('LocalizedSingleAxisTracker: \n  axis_tilt: 0\n  '
-                'axis_azimuth: 0\n  max_angle: 90\n  backtrack: True\n  '
-                'gcr: 0.25\n  name: None\n  surface_tilt: None\n  '
-                'surface_azimuth: None\n  module: blah\n  inverter: blarg\n  '
-                'albedo: 0.25\n  racking_model: open_rack\n  '
-                'latitude: 32\n  longitude: -111\n  altitude: 0\n  tz: UTC')
+    localized_system = tracking.LocalizedSingleAxisTracker(
+        latitude=32, longitude=-111, module='blah', inverter='blarg',
+        gcr=0.25, temperature_model_parameters={'a': -3.56})
+    # apparently the repr order is different for LocalizedSingleAxisTracker
+    # than for LocalizedPVSystem. maybe a MRO thing.
+    expected = """LocalizedSingleAxisTracker:
+  axis_tilt: 0
+  axis_azimuth: 0
+  max_angle: 90
+  backtrack: True
+  gcr: 0.25
+  name: None
+  surface_tilt: None
+  surface_azimuth: None
+  module: blah
+  inverter: blarg
+  albedo: 0.25
+  racking_model: open_rack
+  module_type: glass_polymer
+  temperature_model_parameters: {'a': -3.56}
+  latitude: 32
+  longitude: -111
+  altitude: 0
+  tz: UTC"""
 
     assert localized_system.__repr__() == expected