-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Replace interp1d #2394 #2741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Replace interp1d #2394 #2741
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,7 +440,7 @@ def interp(aoi, theta_ref, iam_ref, method='linear', normalize=True): | |
| method : str, default 'linear' | ||
| Specifies the interpolation method. | ||
| Useful options are: 'linear', 'quadratic', 'cubic'. | ||
| See scipy.interpolate.interp1d for more options. | ||
| See scipy.interpolate for more options. | ||
|
|
||
| normalize : boolean, default True | ||
| 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): | |
| ''' | ||
| # Contributed by Anton Driesse (@adriesse), PV Performance Labs. July, 2019 | ||
|
|
||
| from scipy.interpolate import interp1d | ||
| from scipy.interpolate import make_interp_spline | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line being here inside the function (instead of at the top of the file as usual) is a relic of the days when scipy was an optional dependency. Optional for this PR, but moving the import to the top would be an improvement. |
||
|
|
||
| # Scipy doesn't give the clearest feedback, so check number of points here. | ||
| 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): | |
| raise ValueError("Negative value(s) found in 'iam_ref'. " | ||
| "This is not physically possible.") | ||
|
|
||
| interpolator = interp1d(theta_ref, iam_ref, kind=method, | ||
| fill_value='extrapolate') | ||
| aoi_input = aoi | ||
| theta_ref = np.asarray(theta_ref) | ||
| iam_ref = np.asarray(iam_ref) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is |
||
|
|
||
| if method == "linear": | ||
| spline = make_interp_spline(theta_ref, iam_ref, k=1) | ||
|
|
||
| def interpolator(x): | ||
| return spline(x) | ||
|
|
||
| elif method == "quadratic": | ||
| spline = make_interp_spline(theta_ref, iam_ref, k=2) | ||
|
|
||
| def interpolator(x): | ||
| return spline(x) | ||
|
|
||
| elif method == "cubic": | ||
| spline = make_interp_spline(theta_ref, iam_ref, k=3) | ||
|
|
||
| def interpolator(x): | ||
| return spline(x) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can surely be simplified as @cwhanse mentioned in #2741 (comment) |
||
|
|
||
| else: | ||
| raise ValueError(f"Invalid interpolation method '{method}'.") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is, technically, a breaking change, since the |
||
|
|
||
| aoi_input = aoi | ||
| aoi = np.asanyarray(aoi) | ||
| aoi = np.abs(aoi) | ||
| iam = interpolator(aoi) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |||||||
| import numpy as np | ||||||||
| import pandas as pd | ||||||||
| import scipy.constants | ||||||||
| from scipy.interpolate import interp1d | ||||||||
| from scipy.interpolate import make_interp_spline | ||||||||
|
|
||||||||
|
|
||||||||
| _PLANCK_BY_LIGHT_SPEED_OVER_ELEMENTAL_CHARGE_BY_BILLION = ( | ||||||||
|
|
@@ -66,16 +66,15 @@ def get_example_spectral_response(wavelength=None): | |||||||
| if wavelength is None: | ||||||||
| resolution = 5.0 | ||||||||
| wavelength = np.arange(280, 1200 + resolution, resolution) | ||||||||
| x = SR_DATA[0] | ||||||||
| y = SR_DATA[1] | ||||||||
| spline = make_interp_spline( | ||||||||
| x, y, k=3) | ||||||||
|
Comment on lines
+71
to
+72
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No reason to not fit this on one line, right? |
||||||||
|
|
||||||||
| interpolator = interp1d(SR_DATA[0], SR_DATA[1], | ||||||||
| kind='cubic', | ||||||||
| bounds_error=False, | ||||||||
| fill_value=0.0, | ||||||||
| copy=False, | ||||||||
| assume_sorted=True) | ||||||||
|
|
||||||||
| sr = pd.Series(data=interpolator(wavelength), index=wavelength) | ||||||||
| values = spline(wavelength) | ||||||||
| values[(wavelength < x[0]) | (wavelength > x[-1])] = 0.0 | ||||||||
|
|
||||||||
| sr = pd.Series(data=values, index=wavelength) | ||||||||
| sr.index.name = 'wavelength' | ||||||||
| sr.name = 'spectral_response' | ||||||||
|
|
||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line may need to be edited, depending on https://github.com/pvlib/pvlib-python/pull/2741/changes#r3137773820