@@ -440,7 +440,7 @@ def interp(aoi, theta_ref, iam_ref, method='linear', normalize=True):
440440 method : str, default 'linear'
441441 Specifies the interpolation method.
442442 Useful options are: 'linear', 'quadratic', 'cubic'.
443- See scipy.interpolate.interp1d for more options.
443+ See scipy.interpolate for more options.
444444
445445 normalize : boolean, default True
446446 When true, the interpolated values are divided by the interpolated
@@ -470,7 +470,7 @@ 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 CubicSpline , make_interp_spline
474474
475475 # Scipy doesn't give the clearest feedback, so check number of points here.
476476 MIN_REF_VALS = {'linear' : 2 , 'quadratic' : 3 , 'cubic' : 4 , 1 : 2 , 2 : 3 , 3 : 4 }
@@ -483,10 +483,31 @@ def interp(aoi, theta_ref, iam_ref, method='linear', normalize=True):
483483 raise ValueError ("Negative value(s) found in 'iam_ref'. "
484484 "This is not physically possible." )
485485
486- interpolator = interp1d (theta_ref , iam_ref , kind = method ,
487- fill_value = 'extrapolate' )
488- aoi_input = aoi
486+ theta_ref = np .asarray (theta_ref )
487+ iam_ref = np .asarray (iam_ref )
488+
489+ if method == "linear" :
490+ spline = make_interp_spline (theta_ref , iam_ref , k = 1 )
491+
492+ def interpolator (x ):
493+ return spline (x )
494+
495+ elif method == "quadratic" :
496+ spline = make_interp_spline (theta_ref , iam_ref , k = 2 )
497+
498+ def interpolator (x ):
499+ return spline (x )
489500
501+ elif method == "cubic" :
502+ spline = CubicSpline (theta_ref , iam_ref , extrapolate = True )
503+
504+ def interpolator (x ):
505+ return spline (x )
506+
507+ else :
508+ raise ValueError (f"Invalid interpolation method '{ method } '." )
509+
510+ aoi_input = aoi
490511 aoi = np .asanyarray (aoi )
491512 aoi = np .abs (aoi )
492513 iam = interpolator (aoi )
0 commit comments