Repository navigation
Closed
Description
Describe the bug
0.9.4 introduced the following changes in the _golden_sect_DataFrame: We are checking upper and lower parameters and raise an error if lower > upper.
Lines 344 to 345 in 81598e4
| if np.any(upper - lower < 0.): | |
| raise ValueError('upper >= lower is required') |
_golden_sect_DataFrame is used by _lambertw:
pvlib-python/pvlib/singlediode.py
Lines 644 to 649 in 81598e4
| # Compute open circuit voltage | |
| v_oc = _lambertw_v_from_i(0., **params) | |
| # Find the voltage, v_mp, where the power is maximized. | |
| # Start the golden section search at v_oc * 1.14 | |
| p_mp, v_mp = _golden_sect_DataFrame(params, 0., v_oc * 1.14, _pwr_optfcn) |
I often have slightly negative v_oc values (really close to 0) when running simulations (second number in the array below):
array([ 9.46949758e-16, -8.43546518e-15, 2.61042547e-15, 3.82769773e-15,
1.01292315e-15, 4.81308106e+01, 5.12484772e+01, 5.22675087e+01,
5.20708941e+01, 5.16481028e+01, 5.12364071e+01, 5.09209060e+01,
5.09076598e+01, 5.10187680e+01, 5.11328118e+01, 5.13997628e+01,
5.15121386e+01, 5.05621451e+01, 4.80488068e+01, 7.18224446e-15,
1.21386700e-14, 6.40136698e-16, 4.36081007e-16, 6.51236255e-15])
If we have one negative number in a large timeseries, the simulation will crash which seems too strict.
Expected behavior
That would be great to either:
- Have this data check be less strict and allow for slightly negative numbers, which are not going to affect the quality of the results.
- On
_lambertw: Do not allow negativev_ocand set negative values tonp.nan, so that the error is not triggered. It will be up to the upstream code (user) to manage thosenp.nan.
Versions:
pvlib.__version__: >= 0.9.4pandas.__version__: 1.5.3- python: 3.10.11
Activity
echedey-ls commentedon Jun 19, 2023
See #1673
cwhanse commentedon Jun 20, 2023
@cedricleroy can you provide the inputs and function call that produced the negative
v_ocshown above?cedricleroy commentedon Jun 20, 2023
@echedey-ls Thanks! I thought I checked for related issues, but apparently not enough 😄
@cwhanse Sure thing:
Running
_lambertw_v_from_iin_lambertwwith the following data:data.csv
cwhanse commentedon Jun 21, 2023
Agree this is not desirable.
My thoughts:
v_oc = np.maximum(v_oc, 0)above this line. That would preserve nan._lambertw_v_from_i. That function's job is to solve the diode equation, which is valid for negative current. I don't think this function should make decisions about its solution. There will always be some degree of imprecision (currently it's around 10-13 or smaller, I think)._golden_sect_DataFramefor similar reasons - the function's job should be to find a minimum using the golden section search. Complying with thelower < upperrequirement is the job of the code that calls this function.cedricleroy commentedon Jun 21, 2023
1/ makes sense to me. I agree with the CONS for 2/ and 3/
Happy to open a PR with 1. if that helps.
cwhanse commentedon Jun 21, 2023
That is welcome. Because I'm cautious about junk values with larger magnitude being covered up by 0s, maybe
adapt test values for module_dc_voltage_at_mpp due to bufix by pvlib …