Skip to content

Commit 61e9582

Browse files
Antoine-0pmloikjuyhbncwhanse
authored
Added rounding of aa and b in _schumaker_qspline.py, see Issue #1311 (#1315)
* Added rounding of aa and b in _schumaker_qspline.py, see Issue #1311 * adjust EPS constants, remove part of test * lint, whatsnew * add whatnew v0.9.1 to index Co-authored-by: Antoine Ravetta <[email protected]> Co-authored-by: Cliff Hansen <[email protected]>
1 parent 862ac82 commit 61e9582

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

docs/sphinx/source/whatsnew.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ What's New
66

77
These are new features and improvements of note in each release.
88

9+
.. include:: whatsnew/v0.9.1.rst
910
.. include:: whatsnew/v0.9.0.rst
1011
.. include:: whatsnew/v0.8.1.rst
1112
.. include:: whatsnew/v0.8.0.rst
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.. _whatsnew_0910:
2+
3+
v0.9.1 (December 1, 2021)
4+
--------------------------
5+
6+
Breaking changes
7+
~~~~~~~~~~~~~~~~
8+
9+
Deprecations
10+
~~~~~~~~~~~~
11+
12+
Enhancements
13+
~~~~~~~~~~~~
14+
15+
Bug fixes
16+
~~~~~~~~~
17+
* Address round-off effects in :py:func:`pvlib.ivtools.utils._schumaker_qspline`
18+
(:issue:`1311`, :pull:`1315`)
19+
20+
Testing
21+
~~~~~~~
22+
23+
Documentation
24+
~~~~~~~~~~~~~
25+
26+
Requirements
27+
~~~~~~~~~~~~
28+
29+
Contributors
30+
~~~~~~~~~~~~
31+
* Cliff Hansen (:ghuser:`cwhanse`)
32+
* :ghuser:`Antoine-0`

pvlib/ivtools/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010

1111
# A small number used to decide when a slope is equivalent to zero
12-
EPS = np.finfo('float').eps**(1/3)
12+
EPS_slope = np.finfo('float').eps**(1/3)
13+
# A small number used to decide when a slope is equivalent to zero
14+
EPS_val = np.finfo('float').eps
1315

1416

1517
def _numdiff(x, f):
@@ -263,7 +265,7 @@ def _schumaker_qspline(x, y):
263265
# [2], Algorithm 4.1 first 'if' condition of step 5 defines intervals
264266
# which won't get internal knots
265267
tests = s[:-1] + s[1:]
266-
u = np.isclose(tests, 2.0 * delta, atol=EPS)
268+
u = np.isclose(tests, 2.0 * delta, atol=EPS_slope)
267269
# u = true for an interval which will not get an internal knot
268270

269271
k = n + sum(~u) # total number of knots = original data + inserted knots
@@ -313,6 +315,11 @@ def _schumaker_qspline(x, y):
313315
aa = s[:-1] - delta
314316
b = s[1:] - delta
315317

318+
# Since the above two lines can lead to numerical errors, aa and b
319+
# are rounded to 0.0 is their absolute value is small enough.
320+
aa[np.isclose(aa, 0., atol=EPS_val)] = 0.
321+
b[np.isclose(b, 0., atol=EPS_val)] = 0.
322+
316323
sbar = np.zeros(k)
317324
eta = np.zeros(k)
318325
# will contain mapping from the left points of intervals containing an

pvlib/tests/ivtools/test_sde.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ def test_fit_sandia_simple_bad_iv(get_bad_iv_curves):
5353

5454

5555
@pytest.mark.parametrize('i,v,nsvth,expected', [
56-
(np.array(
57-
[4., 3.95, 3.92, 3.9, 3.89, 3.88, 3.82, 3.8, 3.75, 3.7, 3.68, 3.66,
58-
3.65, 3.5, 3.2, 2.7, 2.2, 1.3, .6, 0.]),
59-
np.array(
60-
[0., .2, .4, .6, .8, 1., 1.2, 1.4, 1.6, 1.8, 2., 2.2, 2.4, 2.6, 2.7,
61-
2.76, 2.78, 2.81, 2.85, 2.88]),
62-
2.,
63-
(-96695.792, 96699.876, 7.4791, .0288, -.1413)),
6456
(np.array([3., 2.9, 2.8, 2.7, 2.6, 2.5, 2.4, 1.7, 0.8, 0.]),
6557
np.array([0., 0.2, 0.4, 0.6, 0.8, 1., 1.2, 1.4, 1.45, 1.5]),
6658
10.,

0 commit comments

Comments
 (0)