Skip to content

Commit 75b579c

Browse files
committed
scipy.interpolate.interp1d updation
1 parent 5c86e8c commit 75b579c

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

docs/examples/shading/plot_partial_module_shading_simple.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from pvlib import pvsystem, singlediode
3939
import pandas as pd
4040
import numpy as np
41-
from scipy.interpolate import interp1d
41+
from scipy.interpolate import make_interp_spline
4242
import matplotlib.pyplot as plt
4343

4444
from scipy.constants import e as qe, k as kB
@@ -178,10 +178,13 @@ def plot_curves(dfs, labels, title):
178178

179179

180180
def interpolate(df, i):
181-
"""convenience wrapper around scipy.interpolate.interp1d"""
182-
f_interp = interp1d(np.flipud(df['i']), np.flipud(df['v']), kind='linear',
183-
fill_value='extrapolate')
184-
return f_interp(i)
181+
x = np.flipud(df['i'])
182+
y = np.flipud(df['v'])
183+
184+
# Create a spline interpolation with linear (k=1) and extrapolation (default behavior)
185+
spline = make_interp_spline(x, y, k=1, bc_type='clamped') # Extrapolation is handled by default
186+
187+
return spline(i)
185188

186189

187190
def combine_series(dfs):

pvlib/iam.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ def interp(aoi, theta_ref, iam_ref, method='linear', normalize=True):
470470
'''
471471
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. July, 2019
472472

473-
from scipy.interpolate import interp1d
473+
from scipy.interpolate import make_interp_spline
474+
import numpy as np
474475

475476
# Scipy doesn't give the clearest feedback, so check number of points here.
476477
MIN_REF_VALS = {'linear': 2, 'quadratic': 3, 'cubic': 4, 1: 2, 2: 3, 3: 4}
@@ -483,8 +484,10 @@ def interp(aoi, theta_ref, iam_ref, method='linear', normalize=True):
483484
raise ValueError("Negative value(s) found in 'iam_ref'. "
484485
"This is not physically possible.")
485486

486-
interpolator = interp1d(theta_ref, iam_ref, kind=method,
487-
fill_value='extrapolate')
487+
theta_ref = np.asarray(theta_ref)
488+
iam_ref = np.asarray(iam_ref)
489+
490+
interpolator = make_interp_spline(theta_ref, iam_ref, k=method, bc_type='clamped')
488491
aoi_input = aoi
489492

490493
aoi = np.asanyarray(aoi)

pvlib/spectrum/response.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
import pandas as pd
88
import scipy.constants
9-
from scipy.interpolate import interp1d
9+
from scipy.interpolate import make_interp_spline
1010

1111

1212
_PLANCK_BY_LIGHT_SPEED_OVER_ELEMENTAL_CHARGE_BY_BILLION = (
@@ -67,12 +67,11 @@ def get_example_spectral_response(wavelength=None):
6767
resolution = 5.0
6868
wavelength = np.arange(280, 1200 + resolution, resolution)
6969

70-
interpolator = interp1d(SR_DATA[0], SR_DATA[1],
71-
kind='cubic',
72-
bounds_error=False,
73-
fill_value=0.0,
74-
copy=False,
75-
assume_sorted=True)
70+
x_data = np.sort(SR_DATA[0])
71+
y_data = SR_DATA[1]
72+
73+
interpolator = make_interp_spline(x_data, y_data, k=3, bc_type='clamped')
74+
7675

7776
sr = pd.Series(data=interpolator(wavelength), index=wavelength)
7877

0 commit comments

Comments
 (0)