Skip to content

_golden_sect_DataFrame changes in 0.9.4 #1780

Closed
@cedricleroy

Description

@cedricleroy

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.

pvlib-python/pvlib/tools.py

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:

# 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 negative v_oc and set negative values to np.nan, so that the error is not triggered. It will be up to the upstream code (user) to manage those np.nan.

Versions:

  • pvlib.__version__: >= 0.9.4
  • pandas.__version__: 1.5.3
  • python: 3.10.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions