Skip to content

Commit

Permalink
Rename ivtools.utility to ivtools.utils, and silence ivtools.sdm warn…
Browse files Browse the repository at this point in the history
…ings (#1048)

* rename utility to utils, silence some warnings

* rename test_utility.py

* squelch more
  • Loading branch information
cwhanse authored Sep 6, 2020
1 parent edea606 commit 2819ac1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
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 @@ -14,7 +14,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 @@ -299,7 +299,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 @@ -414,6 +414,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 @@ -474,7 +477,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 @@ -573,6 +576,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}

ee = ivcurves['ee']
tc = ivcurves['tc']
tck = tc + 273.15
Expand Down Expand Up @@ -936,10 +942,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 @@ -1128,8 +1135,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 @@ -1191,12 +1199,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 @@ -1216,21 +1224,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

0 comments on commit 2819ac1

Please sign in to comment.