Repository: pvlib/pvlib-python
Pull request #735 (2019-06-05 20:47:50)

Fixed pvwatts_ac model bug using module pdc0 instead of inverted pdc0
 - [x] Closes issue #734 
 - [x] I am familiar with the [contributing guidelines](http://pvlib-python.readthedocs.io/en/latest/contributing.html).
 - [x] Fully tested. Added and/or modified tests to ensure correct behavior for all reasonable inputs. Tests (usually) must pass on the TravisCI and Appveyor testing services.
 - [x] Adds description and name entries in the appropriate `docs/sphinx/source/whatsnew` file for all changes.
 - [x] Code quality and style is sufficient. Passes LGTM and SticklerCI checks.
 - [x] New code is fully documented. Includes sphinx/numpydoc compliant docstrings and comments in the code where necessary.
 - [x] Pull request is nearly complete and ready for detailed review.

See Issue #734 


JPalakapillyKWH: @cwhanse Not sure how to add you as a reviewer, or if I need to. I think this should fix the bug though. 
cwhanse: > @cwhanse Not sure how to add you as a reviewer, or if I need to. I think this should fix the bug though.

I'll review.  I think the reviewer assignment feature requires Maintainer privilege, or something.
JPalakapillyKWH: stickler has been queued forever. Not sure what's going on here. Manual rebuild?
cwhanse: Must have gotten stuck
cwhanse: One last request: please add a description to the Bug Fixes section of whatsnew/v0.6.4.rst, and add your name to the contributors list in that file.
cwhanse: thanks @JPalakapillyKWH !

Patch:
diff --git a/.gitignore b/.gitignore
index 38e7e4a..ab0452c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -86,3 +86,6 @@ coverage.xml
 #Ignore some notebooks
 *.ipynb
 !docs/tutorials/*.ipynb
+
+#Ignore Mac DS_store files
+*.DS_Store
diff --git a/docs/sphinx/source/whatsnew/v0.6.4.rst b/docs/sphinx/source/whatsnew/v0.6.4.rst
index ef13f7a..4bffa42 100644
--- a/docs/sphinx/source/whatsnew/v0.6.4.rst
+++ b/docs/sphinx/source/whatsnew/v0.6.4.rst
@@ -19,8 +19,8 @@ Bug fixes
 ~~~~~~~~~
 * Fix installation issue due to missing ``requests`` dependency.
   (:issue:`725`)
-
-
+* Fix PVSystem.pvwatts_ac now uses inverter DC input limit instead of module nameplate capacity. 
+  (:issue:`734`)
 Testing
 ~~~~~~~
 
@@ -28,3 +28,4 @@ Testing
 Contributors
 ~~~~~~~~~~~~
 * Will Holmgren (:ghuser:`wholmgren`)
+* Joseph Palakapilly (:ghuser:`JPalakapillyKWH`)
diff --git a/pvlib/modelchain.py b/pvlib/modelchain.py
index bcb0b4f..1455a57 100644
--- a/pvlib/modelchain.py
+++ b/pvlib/modelchain.py
@@ -526,12 +526,11 @@ class ModelChain(object):
 
     def infer_ac_model(self):
         inverter_params = set(self.system.inverter_parameters.keys())
-        module_params = set(self.system.module_parameters.keys())
         if set(['C0', 'C1', 'C2']) <= inverter_params:
             return self.snlinverter
         elif set(['ADRCoefficients']) <= inverter_params:
             return self.adrinverter
-        elif set(['pdc0']) <= module_params:
+        elif set(['pdc0']) <= inverter_params:
             return self.pvwatts_inverter
         else:
             raise ValueError('could not infer AC model from '
diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py
index ad7981f..35701bd 100644
--- a/pvlib/pvsystem.py
+++ b/pvlib/pvsystem.py
@@ -736,7 +736,7 @@ class PVSystem(object):
         kwargs = _build_kwargs(['eta_inv_nom', 'eta_inv_ref'],
                                self.inverter_parameters)
 
-        return pvwatts_ac(pdc, self.module_parameters['pdc0'], **kwargs)
+        return pvwatts_ac(pdc, self.inverter_parameters['pdc0'], **kwargs)
 
     def localize(self, location=None, latitude=None, longitude=None,
                  **kwargs):
@@ -2839,6 +2839,11 @@ def pvwatts_dc(g_poa_effective, temp_cell, pdc0, gamma_pdc, temp_ref=25.):
 
         P_{dc} = \frac{G_{poa eff}}{1000} P_{dc0} ( 1 + \gamma_{pdc} (T_{cell} - T_{ref}))
 
+    Note that the pdc0 is also used as a symbol in :py:func:`pvwatts_ac`. pdc0
+    in this function refers to the DC power of the modules at reference
+    conditions. pdc0 in :py:func:`pvwatts_ac` refers to the DC power input
+    limit of the inverter.
+
     Parameters
     ----------
     g_poa_effective: numeric
@@ -2849,7 +2854,7 @@ def pvwatts_dc(g_poa_effective, temp_cell, pdc0, gamma_pdc, temp_ref=25.):
     temp_cell: numeric
         Cell temperature in degrees C.
     pdc0: numeric
-        Nameplate DC rating.
+        Power of the modules at 1000 W/m2 and cell reference temperature.
     gamma_pdc: numeric
         The temperature coefficient in units of 1/C. Typically -0.002 to
         -0.005 per degree C.
@@ -2942,12 +2947,17 @@ def pvwatts_ac(pdc, pdc0, eta_inv_nom=0.96, eta_inv_ref=0.9637):
 
     where :math:`\zeta=P_{dc}/P_{dc0}` and :math:`P_{dc0}=P_{ac0}/\eta_{nom}`.
 
+    Note that the pdc0 is also used as a symbol in :py:func:`pvwatts_dc`. pdc0
+    in this function refers to the DC power input limit of the inverter.
+    pdc0 in :py:func:`pvwatts_dc` refers to the DC power of the modules
+    at reference conditions.
+
     Parameters
     ----------
     pdc: numeric
         DC power.
     pdc0: numeric
-        Nameplate DC rating.
+        DC input limit of the inverter.
     eta_inv_nom: numeric, default 0.96
         Nominal inverter efficiency.
     eta_inv_ref: numeric, default 0.9637


Test patch:
diff --git a/pvlib/test/test_modelchain.py b/pvlib/test/test_modelchain.py
index 866068d..7fac625 100644
--- a/pvlib/test/test_modelchain.py
+++ b/pvlib/test/test_modelchain.py
@@ -106,7 +106,7 @@ def pvwatts_dc_snl_ac_system(sam_data):
 @pytest.fixture
 def pvwatts_dc_pvwatts_ac_system(sam_data):
     module_parameters = {'pdc0': 220, 'gamma_pdc': -0.003}
-    inverter_parameters = {'eta_inv_nom': 0.95}
+    inverter_parameters = {'pdc0': 220, 'eta_inv_nom': 0.95}
     system = PVSystem(surface_tilt=32.2, surface_azimuth=180,
                       module_parameters=module_parameters,
                       inverter_parameters=inverter_parameters)
diff --git a/pvlib/test/test_pvsystem.py b/pvlib/test/test_pvsystem.py
index 2fd556f..17f70e9 100644
--- a/pvlib/test/test_pvsystem.py
+++ b/pvlib/test/test_pvsystem.py
@@ -1424,7 +1424,7 @@ def test_pvwatts_losses_series():
 
 def make_pvwatts_system_defaults():
     module_parameters = {'pdc0': 100, 'gamma_pdc': -0.003}
-    inverter_parameters = {}
+    inverter_parameters = {'pdc0': 90}
     system = pvsystem.PVSystem(module_parameters=module_parameters,
                                inverter_parameters=inverter_parameters)
     return system
@@ -1432,7 +1432,7 @@ def make_pvwatts_system_defaults():
 
 def make_pvwatts_system_kwargs():
     module_parameters = {'pdc0': 100, 'gamma_pdc': -0.003, 'temp_ref': 20}
-    inverter_parameters = {'eta_inv_nom': 0.95, 'eta_inv_ref': 1.0}
+    inverter_parameters = {'pdc0': 90, 'eta_inv_nom': 0.95, 'eta_inv_ref': 1.0}
     system = pvsystem.PVSystem(module_parameters=module_parameters,
                                inverter_parameters=inverter_parameters)
     return system
@@ -1477,9 +1477,8 @@ def test_PVSystem_pvwatts_ac(mocker):
     mocker.spy(pvsystem, 'pvwatts_ac')
     system = make_pvwatts_system_defaults()
     pdc = 50
-    pdc0 = system.module_parameters['pdc0']
     out = system.pvwatts_ac(pdc)
-    pvsystem.pvwatts_ac.assert_called_once_with(pdc, pdc0,
+    pvsystem.pvwatts_ac.assert_called_once_with(pdc,
                                                 **system.inverter_parameters)
     assert out < pdc
 
@@ -1488,8 +1487,7 @@ def test_PVSystem_pvwatts_ac_kwargs(mocker):
     mocker.spy(pvsystem, 'pvwatts_ac')
     system = make_pvwatts_system_kwargs()
     pdc = 50
-    pdc0 = system.module_parameters['pdc0']
     out = system.pvwatts_ac(pdc)
-    pvsystem.pvwatts_ac.assert_called_once_with(pdc, pdc0,
+    pvsystem.pvwatts_ac.assert_called_once_with(pdc,
                                                 **system.inverter_parameters)
     assert out < pdc