-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Implement Akima1DInterpolator #12833
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
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ openpyxl | |
xlsxwriter | ||
xlrd | ||
xlwt | ||
scipy | ||
numexpr | ||
pytables | ||
html5lib | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ def clean_interp_method(method, **kwargs): | |
order = kwargs.get('order') | ||
valid = ['linear', 'time', 'index', 'values', 'nearest', 'zero', 'slinear', | ||
'quadratic', 'cubic', 'barycentric', 'polynomial', 'krogh', | ||
'piecewise_polynomial', 'pchip', 'spline'] | ||
'piecewise_polynomial', 'pchip', 'akima', 'spline'] | ||
if method in ('spline', 'polynomial') and order is None: | ||
raise ValueError("You must specify the order of the spline or " | ||
"polynomial.") | ||
|
@@ -188,7 +188,7 @@ def _interp_limit(invalid, fw_limit, bw_limit): | |
|
||
sp_methods = ['nearest', 'zero', 'slinear', 'quadratic', 'cubic', | ||
'barycentric', 'krogh', 'spline', 'polynomial', | ||
'piecewise_polynomial', 'pchip'] | ||
'piecewise_polynomial', 'pchip', 'akima'] | ||
if method in sp_methods: | ||
inds = np.asarray(xvalues) | ||
# hack for DatetimeIndex, #1646 | ||
|
@@ -232,12 +232,19 @@ def _interpolate_scipy_wrapper(x, y, new_x, method, fill_value=None, | |
# GH 5975, scipy.interp1d can't hande datetime64s | ||
x, new_x = x._values.astype('i8'), new_x.astype('i8') | ||
|
||
try: | ||
alt_methods['pchip'] = interpolate.pchip_interpolate | ||
except AttributeError: | ||
if method == 'pchip': | ||
raise ImportError("Your version of scipy does not support " | ||
if method == 'pchip': | ||
try: | ||
alt_methods['pchip'] = interpolate.pchip_interpolate | ||
except AttributeError: | ||
raise ImportError("Your version of Scipy does not support " | ||
"PCHIP interpolation.") | ||
elif method == 'akima': | ||
try: | ||
from scipy.interpolate import Akima1DInterpolator # noqa | ||
alt_methods['akima'] = _akima_interpolate | ||
except ImportError: | ||
raise ImportError("Your version of Scipy does not support " | ||
"Akima interpolation.") | ||
|
||
interp1d_methods = ['nearest', 'zero', 'slinear', 'quadratic', 'cubic', | ||
'polynomial'] | ||
|
@@ -267,6 +274,56 @@ def _interpolate_scipy_wrapper(x, y, new_x, method, fill_value=None, | |
return new_y | ||
|
||
|
||
def _akima_interpolate(xi, yi, x, der=0, axis=0): | ||
""" | ||
Convenience function for akima interpolation. | ||
xi and yi are arrays of values used to approximate some function f, | ||
with ``yi = f(xi)``. | ||
|
||
See `Akima1DInterpolator` for details. | ||
|
||
Parameters | ||
---------- | ||
xi : array_like | ||
A sorted list of x-coordinates, of length N. | ||
yi : array_like | ||
A 1-D array of real values. `yi`'s length along the interpolation | ||
axis must be equal to the length of `xi`. If N-D array, use axis | ||
parameter to select correct axis. | ||
x : scalar or array_like | ||
Of length M. | ||
der : int or list, optional | ||
How many derivatives to extract; None for all potentially | ||
nonzero derivatives (that is a number equal to the number | ||
of points), or a list of derivatives to extract. This number | ||
includes the function value as 0th derivative. | ||
axis : int, optional | ||
Axis in the yi array corresponding to the x-coordinate values. | ||
|
||
See Also | ||
-------- | ||
scipy.interpolate.Akima1DInterpolator | ||
|
||
Returns | ||
------- | ||
y : scalar or array_like | ||
The result, of length R or length M or M by R, | ||
|
||
""" | ||
from scipy import interpolate | ||
try: | ||
P = interpolate.Akima1DInterpolator(xi, yi, axis=axis) | ||
except TypeError: | ||
# Scipy earlier than 0.17.0 missing axis | ||
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. so need a test for this. on the 2.7_LOCALE build we install a really old scipy. We may need to install a somewhat newer one on another build to explicity test for this. When did this 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. 0.14.0 (as per scipy/scipy@a0a3b38) I implemented a different check. 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. ok the 3.4 build has remove 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. ok , just remove 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. from ci/requirements-3.5_OSX.run ? 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. yep (we are including a version of scipy on EVERY build, so need to take it from one) 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. Done |
||
P = interpolate.Akima1DInterpolator(xi, yi) | ||
if der == 0: | ||
return P(x) | ||
elif interpolate._isscalar(der): | ||
return P(x, der=der) | ||
else: | ||
return [P(x, nu) for nu in der] | ||
|
||
|
||
def interpolate_2d(values, method='pad', axis=0, limit=None, fill_value=None, | ||
dtype=None): | ||
""" perform an actual interpolation of values, values will be make 2-d if | ||
|
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.
to here
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.
I'm not sure what you are asking here ...
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.
move the import of the Akima1DInterpolate to
_akima_interpolate
.And change how its handled in the
alt_methods
aboveThere 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.
Would you still like to see a change around this?
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 is ok