Add desoto and pvsyst as dc_model options to ModelChain#555
Conversation
| 'ModelChain object. singlediode is ' | ||
| 'ambiguous, use desoto instead. singlediode ' | ||
| 'keyword will be removed in v0.7.0 and ' | ||
| 'later', DeprecationWarning) |
There was a problem hiding this comment.
This should be a pvlibDeprecationWarning.
Can you also look into adding a test that will fail on pvlib versions >= 0.7? See test_irradiance.py::test_deprecated_07 for an example.
There was a problem hiding this comment.
Near the top of both modelchain.py and test_modelchain.py:
from pvlib._deprecation import pvlibDeprecationWarning
On line 22 of test_modelchain.py:
from conftest import fail_on_pvlib_version, requires_scipy
|
|
||
| self.dc = self.system.scale_voltage_current_power(self.dc).fillna(0) | ||
|
|
||
| return self |
There was a problem hiding this comment.
I don't love the very similar copy/paste code. But it's explicit and that is important too. So I lean towards this approach.
There was a problem hiding this comment.
I would mark this with FIXME. IMO the copy/paste only seems explicit, but it is WET code. DRY code is robust and not prone to errors. I agree this is probably maintainable in the short term, but I think it might become a burden in the future, especially if more "models" are added, such as pvsyst_v7, ...
There are only two lines of difference between these:
--- desoto.py
+++ pvsyst.py
@@ -1,7 +1,7 @@
-def desoto(self):
+def pvsyst(self):
(photocurrent, saturation_current, resistance_series,
resistance_shunt, nNsVth) = (
- self.system.calcparams_desoto(self.effective_irradiance,
+ self.system.calcparams_pvsyst(self.effective_irradiance,
self.temps['temp_cell']))
self.diode_params = (photocurrent, saturation_current,
You could add a tiny dispatcher that you delegate this common task to that is DRY and IMHO also explicit:
def desoto(self):
"""calculate desoto model"""
return self._model_dispatcher(self.system.calcparams_desoto, 'desoto')
def pvsyst(self):
"""calculate pvsyst model"""
return self._model_dispatcher(self.system.calcparams_pvsyst, 'pvsyst')
def _model_dispatcher(self, model_calcparams, model_name=None):
"""
Delegate that dispatches the model
Parameters
----------
model_calcparams : function
A function that calculates the models parameters given irradiance and cell temperature.
model_name : str
Optional string that may be used to further distinguish the model in the future.
"""
(photocurrent, saturation_current, resistance_series,
resistance_shunt, nNsVth) = (
model_calcparams(self.effective_irradiance,
self.temps['temp_cell']))
self.diode_params = (photocurrent, saturation_current,
resistance_series,
resistance_shunt, nNsVth)
self.dc = self.system.singlediode(
photocurrent, saturation_current, resistance_series,
resistance_shunt, nNsVth)
self.dc = self.system.scale_voltage_current_power(self.dc).fillna(0)
return selfThere was a problem hiding this comment.
Either approach is ok with me at this point. Keep in mind that we've had discussions elsewhere about whether or not it even makes sense to define these model-specific methods on ModelChain and if we could replace them with wrappers on PVSystem. So I'm not too concerned about perfection here.
There was a problem hiding this comment.
okay, me too, I fine either way 😁
There was a problem hiding this comment.
@mikofski that's a good suggestion. You are right that we have more diode models waiting - CEC hasn't been connected up yet. But we will (at least I hope) also have system.doublediode someday, and perhaps other variations on the calculate parameters -> calculate IV curve pattern.
There was a problem hiding this comment.
Let's keep the bite small, merge this, and take up improvements in another pull request.
|
Nice job modifying the test. I think we should remove the deprecated method from Alternatively, you could add the docstring |
| self.temps['temp_cell'])) | ||
|
|
||
| self.diode_params = (photocurrent, saturation_current, resistance_series, | ||
| resistance_shunt, nNsVth) |
There was a problem hiding this comment.
Should read as:
self.diode_params = (photocurrent, saturation_current,
resistance_series, resistance_shunt, nNsVth)
same in pvsyst below. Not sure why the git diff/flake8 command doesn't pick up on this. Maybe time for another github/CI integration tool.
|
Great. I think this is ready to merge. |


pvlib python pull request guidelines
Thank you for your contribution to pvlib python! You may delete all of these instructions except for the list below.
You may submit a pull request with your code at any stage of completion.
The following items must be addressed before the code can be merged. Please don't hesitate to ask for help if you're unsure of how to accomplish any of the items below:
docs/sphinx/source/api.rstfor API changes.docs/sphinx/source/whatsnewfile for all changes.git diff upstream/master -u -- "*.py" | flake8 --diffBrief description of the problem and proposed solution (if not already fully described in the issue linked to above):