pvlib-python: AttributeError when using ModelChain with multiple Arrays
Describe the bug A clear and concise description of what the bug is.
Not sure this will be either clear or concise, but: an AttributeError is generated when instantiating a ModelChain with a PVSystem that has multiple Arrays.
The AttributeError results from this line which references a PVSystem.racking_model
attribute. In turn, that line is reached from here where we’re trying to ensure consistency between ModelChain.temperature_model
(a string) and the array temperature models (I think).
To Reproduce See the discussion here which reports the issue.
Expected behavior I don’t see that this user made a mistake. I would not expect the AttributeError.
Versions:
pvlib.__version__
: 0.9.5
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 31 (31 by maintainers)
Sorry for not chiming in earlier. I was a bit confused about what exactly the problem was here, but I think I have a clear view now, and I think . Sorry in advance for the long comment…
There are a two distinct issues here:
ModelChain
sometimes accesses a non-existent attribute ofPVSystem
(the title of this issue) and causesAttributeError
.This occurs when the user makes a mistake and doesn’t supply
temperature_model_parameters
, orracking_model
andmodule_type
, in theArray
s when creating and using aPVSystem
for temperature modeling withModelChain
. There is no way for pvlib to proceed in this case, so raising an error is correct. The only problem is that, due to an oversight made in v0.10.0, the specific error message is confusing in pvlib v0.10.*:KeyError: "Missing required parameter 'a'. Found {} in temperature_model_parameters."
pvlibDeprecationWarning: The PVSystem.racking_model function was deprecated in pvlib 0.9 and will be removed in 0.10. Use PVSystem.arrays[i].racking_model instead.
AttributeError: 'PVSystem' object has no attribute 'racking_model'
I think resolving this is a simple bugfix: fix the error message (and type) being raised. No deprecation period needed or desired.
ModelChain
has (kind of) retained the deprecated behavior of defaulting to the SAPM cell temperature model when parameters aren’t supplied and available for inference.This was supposed to be removed in v0.9, but it was overlooked. I think resolving this problem is also a simple bugfix, not a breaking change: the behavior in question only applies when no parameters are supplied, and it’s not like the model can be run in that situation anyway.
Anyway, I think both of these problems can be solved by just removing the second half of that offending
or
condition inModelChain
. I don’t see why any further modifications are needed in order to fix those problems. In particular, I’m opposed to the idea of raising an error in theArray
constructor when the temperature model parameters weren’t specified and couldn’t be inferred. Valid uses ofArray
/PVSystem
that have no need fortemperature_model_parameters
include:Array
for tasks unrelated to temperature modeling, e.g. irradiance transpositionModelChain
withcell_temperature
included in the input weather dataIn cases like these, the user shouldn’t be burdened and confused by making them specify a parameter set that won’t get used anyway. I think what we want is for un-inferrable parameters to only cause an error when the user runs something that actually needs those parameters.
Thanks for this effort, more than I anticipated 😃 I look forward to seeing the PR.
I vote to simply delete the
or
clause, which will prevent the error we’ve seen.