8000 Rename ivtools.utility to ivtools.utils, and silence ivtools.sdm warn… · km2mishra/pvlib-python@2819ac1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2819ac1

Browse files
authored
Rename ivtools.utility to ivtools.utils, and silence ivtools.sdm warnings (pvlib#1048)
* rename utility to utils, silence some warnings * rename test_utility.py * squelch more
1 parent edea606 commit 2819ac1

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

pvlib/ivtools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
55
"""
66

7-
from pvlib.ivtools import sde, sdm, utility # noqa: F401
7+
from pvlib.ivtools import sde, sdm, utils # noqa: F401

pvlib/ivtools/sde.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numpy as np
99

10-
from pvlib.ivtools.utility import _schumaker_qspline
10+
from pvlib.ivtools.utils import _schumaker_qspline
1111

1212

1313
# set constant for numpy.linalg.lstsq parameter rcond

pvlib/ivtools/sdm.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from pvlib.pvsystem import singlediode, v_from_i
1616

17-
from pvlib.ivtools.utility import constants, rectify_iv_curve, _numdiff
17+
from pvlib.ivtools.utils import rectify_iv_curve, _numdiff
1818
from pvlib.ivtools.sde import _fit_sandia_cocontent
1919

2020

@@ -299,7 +299,7 @@ def _system_of_equations_desoto(params, specs):
299299
return y
300300

301301

302-
def fit_pvsyst_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
302+
def fit_pvsyst_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
303303
"""
304304
Estimate parameters for the PVsyst module performance model.
305305
@@ -414,6 +414,9 @@ def fit_pvsyst_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
414414
.. [7] PVLib MATLAB https://github.com/sandialabs/MATLAB_PV_LIB
415415
"""
416416

417+
if const is None:
418+
const = {'E0': 1000.0, 'T0': 25.0, 'k': 1.38066e-23, 'q': 1.60218e-19}
419+
417420
ee = ivcurves['ee']
418421
tc = ivcurves['tc']
419422
tck = tc + 273.15
@@ -474,7 +477,7 @@ def fit_pvsyst_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
474477
return pvsyst
475478

476479

477-
def fit_desoto_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
480+
def fit_desoto_sandia(ivcurves, specs, const=None, maxiter=5, eps1=1.e-3):
478481
"""
479482
Estimate parameters for the De Soto module performance model.
480483
@@ -573,6 +576,9 @@ def fit_desoto_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
573576
.. [4] PVLib MATLAB https://github.com/sandialabs/MATLAB_PV_LIB
574577
"""
575578

579+
if const is None:
580+
const = {'E0': 1000.0, 'T0': 25.0, 'k': 1.38066e-23, 'q': 1.60218e-19}
581+
576582
ee = ivcurves['ee']
577583
tc = ivcurves['tc']
578584
tck = tc + 273.15
@@ -936,10 +942,11 @@ def _update_io(voc, iph, io, rs, rsh, nnsvth):
936942
dvoc = pvoc - voc
937943

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

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

@@ -1128,8 +1135,9 @@ def _update_rsh_fixed_pt(vmp, imp, iph, io, rs, rsh, nnsvth):
11281135

11291136
for i in range(niter):
11301137
_, z = _calc_theta_phi_exact(vmp, imp, iph, io, rs, x1, nnsvth)
1131-
next_x1 = (1 + z) / z * ((iph + io) * x1 / imp - nnsvth * z / imp - 2 *
1132-
vmp / imp)
1138+
with np.errstate(divide="ignore"):
1139+
next_x1 = (1 + z) / z * ((iph + io) * x1 / imp - nnsvth * z / imp
1140+
- 2 * vmp / imp)
11331141
x1 = next_x1
11341142

11351143
return x1
@@ -1191,12 +1199,12 @@ def _calc_theta_phi_exact(vmp, imp, iph, io, rs, rsh, nnsvth):
11911199

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

12011209
# NaN where argw overflows. Switch to log space to evaluate
12021210
u = np.isinf(argw)
@@ -1216,21 +1224,23 @@ def _calc_theta_phi_exact(vmp, imp, iph, io, rs, rsh, nnsvth):
12161224

12171225
# Argument for Lambert W function involved in I = I(V) [2] Eq. 11; [3]
12181226
# E1. 2
1219-
with np.errstate(over="ignore"):
1227+
with np.errstate(over="ignore", divide="ignore", invalid="ignore"):
12201228
argw = np.where(
12211229
nnsvth == 0,
12221230
np.nan,
12231231
rsh / (rsh + rs) * rs * io / nnsvth * np.exp(
12241232
rsh / (rsh + rs) * (rs * (iph + io) + vmp) / nnsvth))
1225-
theta = np.where(argw > 0, lambertw(argw).real, np.nan)
1233+
theta = np.where(argw > 0, lambertw(argw).real, np.nan)
12261234

12271235
# NaN where argw overflows. Switch to log space to evaluate
12281236
u = np.isinf(argw)
12291237
if np.any(u):
1230-
logargw = (
1231-
np.log(rsh[u]) / (rsh[u] + rs[u]) + np.log(rs[u]) + np.log(io[u])
1232-
- np.log(nnsvth[u]) + (rsh[u] / (rsh[u] + rs[u]))
1233-
* (rs[u] * (iph[u] + io[u]) + vmp[u]) / nnsvth[u])
1238+
with np.errstate(divide="ignore"):
1239+
logargw = (
1240+
np.log(rsh[u]) - np.log(rsh[u] + rs[u]) + np.log(rs[u])
1241+
+ np.log(io[u]) - np.log(nnsvth[u])
1242+
+ (rsh[u] / (rsh[u] + rs[u]))
1243+
* (rs[u] * (iph[u] + io[u]) + vmp[u]) / nnsvth[u])
12341244
# Three iterations of Newton-Raphson method to solve w+log(w)=logargW.
12351245
# The initial guess is w=logargW. Where direct evaluation (above)
12361246
# results in NaN from overflow, 3 iterations of Newton's method gives

pvlib/ivtools/utility.py renamed to pvlib/ivtools/utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
The ``pvlib.ivtools.utility.py`` module contains utility functions related to
2+
The ``pvlib.ivtools.utils.py`` module contains utility functions related to
33
working with IV curves, or fitting equations to IV curve data.
44
55
"""
@@ -12,9 +12,6 @@
1212
EPS = np.finfo('float').eps**(1/3)
1313

1414

15-
constants = {'E0': 1000.0, 'T0': 25.0, 'k': 1.38066e-23, 'q': 1.60218e-19}
16-
17-
1815
def _numdiff(x, f):
1916
"""
2017
Compute first and second order derivative using possibly unequally

pvlib/tests/ivtools/test_utility.py renamed to pvlib/tests/ivtools/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import numpy as np
22
import pandas as pd
33
import pytest
4-
from pvlib.ivtools.utility import _numdiff, rectify_iv_curve
5-
from pvlib.ivtools.utility import _schumaker_qspline
4+
from pvlib.ivtools.utils import _numdiff, rectify_iv_curve
5+
from pvlib.ivtools.utils import _schumaker_qspline
66

77
from conftest import DATA_DIR
88

0 commit comments

Comments
 (0)
0