Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ivtools.utility to ivtools.utils, and silence ivtools.sdm warnings #1048

Merged
merged 3 commits into from
Sep 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pvlib/ivtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"""

from pvlib.ivtools import sde, sdm, utility # noqa: F401
from pvlib.ivtools import sde, sdm, utils # noqa: F401
2 changes: 1 addition & 1 deletion pvlib/ivtools/sde.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np

from pvlib.ivtools.utility import _schumaker_qspline
from pvlib.ivtools.utils import _schumaker_qspline


# set constant for numpy.linalg.lstsq parameter rcond
Expand Down
42 changes: 26 additions & 16 deletions pvlib/ivtools/sdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from pvlib.pvsystem import singlediode, v_from_i

from pvlib.ivtools.utility import constants, rectify_iv_curve, _numdiff
from pvlib.ivtools.utils import rectify_iv_curve, _numdiff
from pvlib.ivtools.sde import _fit_sandia_cocontent


Expand Down Expand Up @@ -301,7 +301,7 @@ def _system_of_equations_desoto(params, specs):
return y


def fit_pvsyst_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
def fit_pvsyst_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
"""
Estimate parameters for the PVsyst module performance model.

Expand Down Expand Up @@ -416,6 +416,9 @@ def fit_pvsyst_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
.. [7] PVLib MATLAB https://github.com/sandialabs/MATLAB_PV_LIB
"""

if const is None:
const = {'E0': 1000.0, 'T0': 25.0, 'k': 1.38066e-23, 'q': 1.60218e-19}

ee = ivcurves['ee']
tc = ivcurves['tc']
tck = tc + 273.15
Expand Down Expand Up @@ -476,7 +479,7 @@ def fit_pvsyst_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
return pvsyst


def fit_desoto_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
def fit_desoto_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
"""
Estimate parameters for the De Soto module performance model.

Expand Down Expand Up @@ -575,6 +578,9 @@ def fit_desoto_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
.. [4] PVLib MATLAB https://github.com/sandialabs/MATLAB_PV_LIB
"""

if const is None:
const = {'E0': 1000.0, 'T0': 25.0, 'k': 1.38066e-23, 'q': 1.60218e-19}
mikofski marked this conversation as resolved.
Show resolved Hide resolved

ee = ivcurves['ee']
tc = ivcurves['tc']
tck = tc + 273.15
Expand Down Expand Up @@ -939,10 +945,11 @@ def _update_io(voc, iph, io, rs, rsh, nnsvth):
dvoc = pvoc - voc

# Update Io
new_io = tio * (1. + (2. * dvoc) / (2. * nnsvth - dvoc))
with np.errstate(invalid="ignore", divide="ignore"):
new_io = tio * (1. + (2. * dvoc) / (2. * nnsvth - dvoc))
# Calculate Maximum Percent Difference
maxerr = np.max(np.abs(new_io - tio) / tio) * 100.

# Calculate Maximum Percent Difference
maxerr = np.max(np.abs(new_io - tio) / tio) * 100.
tio = new_io
k += 1.

Expand Down Expand Up @@ -1131,8 +1138,9 @@ def _update_rsh_fixed_pt(vmp, imp, iph, io, rs, rsh, nnsvth):

for i in range(niter):
_, z = _calc_theta_phi_exact(vmp, imp, iph, io, rs, x1, nnsvth)
next_x1 = (1 + z) / z * ((iph + io) * x1 / imp - nnsvth * z / imp - 2 *
vmp / imp)
with np.errstate(divide="ignore"):
next_x1 = (1 + z) / z * ((iph + io) * x1 / imp - nnsvth * z / imp
- 2 * vmp / imp)
x1 = next_x1

return x1
Expand Down Expand Up @@ -1200,12 +1208,12 @@ def _calc_theta_phi_exact(vmp, imp, iph, io, rs, rsh, nnsvth):

# Argument for Lambert W function involved in V = V(I) [2] Eq. 12; [3]
# Eq. 3
with np.errstate(over="ignore"):
with np.errstate(over="ignore", divide="ignore", invalid="ignore"):
argw = np.where(
nnsvth == 0,
np.nan,
rsh * io / nnsvth * np.exp(rsh * (iph + io - imp) / nnsvth))
phi = np.where(argw > 0, lambertw(argw).real, np.nan)
phi = np.where(argw > 0, lambertw(argw).real, np.nan)

# NaN where argw overflows. Switch to log space to evaluate
u = np.isinf(argw)
Expand All @@ -1225,21 +1233,23 @@ def _calc_theta_phi_exact(vmp, imp, iph, io, rs, rsh, nnsvth):

# Argument for Lambert W function involved in I = I(V) [2] Eq. 11; [3]
# E1. 2
with np.errstate(over="ignore"):
with np.errstate(over="ignore", divide="ignore", invalid="ignore"):
argw = np.where(
nnsvth == 0,
np.nan,
rsh / (rsh + rs) * rs * io / nnsvth * np.exp(
rsh / (rsh + rs) * (rs * (iph + io) + vmp) / nnsvth))
theta = np.where(argw > 0, lambertw(argw).real, np.nan)
theta = np.where(argw > 0, lambertw(argw).real, np.nan)

# NaN where argw overflows. Switch to log space to evaluate
u = np.isinf(argw)
if np.any(u):
logargw = (
np.log(rsh[u]) / (rsh[u] + rs[u]) + np.log(rs[u]) + np.log(io[u])
- np.log(nnsvth[u]) + (rsh[u] / (rsh[u] + rs[u]))
* (rs[u] * (iph[u] + io[u]) + vmp[u]) / nnsvth[u])
with np.errstate(divide="ignore"):
logargw = (
np.log(rsh[u]) - np.log(rsh[u] + rs[u]) + np.log(rs[u])
+ np.log(io[u]) - np.log(nnsvth[u])
+ (rsh[u] / (rsh[u] + rs[u]))
* (rs[u] * (iph[u] + io[u]) + vmp[u]) / nnsvth[u])
# Three iterations of Newton-Raphson method to solve w+log(w)=logargW.
# The initial guess is w=logargW. Where direct evaluation (above)
# results in NaN from overflow, 3 iterations of Newton's method gives
Expand Down
5 changes: 1 addition & 4 deletions pvlib/ivtools/utility.py → pvlib/ivtools/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
The ``pvlib.ivtools.utility.py`` module contains utility functions related to
The ``pvlib.ivtools.utils.py`` module contains utility functions related to
working with IV curves, or fitting equations to IV curve data.
"""
Expand All @@ -12,9 +12,6 @@
EPS = np.finfo('float').eps**(1/3)


constants = {'E0': 1000.0, 'T0': 25.0, 'k': 1.38066e-23, 'q': 1.60218e-19}


def _numdiff(x, f):
"""
Compute first and second order derivative using possibly unequally
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import pandas as pd
import pytest
from pvlib.ivtools.utility import _numdiff, rectify_iv_curve
from pvlib.ivtools.utility import _schumaker_qspline
from pvlib.ivtools.utils import _numdiff, rectify_iv_curve
from pvlib.ivtools.utils import _schumaker_qspline

from conftest import DATA_DIR

Expand Down