Skip to content

WIP: Feature/interpolate #1640

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

Merged
merged 27 commits into from
Dec 30, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1582c1f
initial interpolate commit
Oct 17, 2017
ab727e7
fix to interpolate wrapper function
Nov 11, 2017
95006c4
remove duplicate limit handling in ffill/bfill
Nov 11, 2017
4a4f6eb
tests are passing
Nov 12, 2017
42d63ef
more docs, more tests
Nov 13, 2017
263ec98
Merge branch 'master' of github.com:pydata/xarray into feature/interp…
Nov 13, 2017
19d21b8
backward compat and add benchmarks
Nov 13, 2017
f937c07
skip tests for numpy versions before 1.12
Nov 13, 2017
8717e38
test fixes for py27 fixture
Nov 13, 2017
3d5c1b1
try reording decorators
Nov 13, 2017
1864e8f
minor reorg of travis to make the flake8 check useful
Nov 16, 2017
f58d464
cleanup following @fujiisoup's comments
Nov 18, 2017
1b93808
dataset missing methods, some more docs, and more scipy interpolators
Nov 27, 2017
6f83b7b
Merge branch 'master' of github.com:pydata/xarray into feature/interp…
Dec 6, 2017
33df6af
Merge branch 'master' of github.com:pydata/xarray into feature/interp…
Dec 10, 2017
eafe67a
Merge remote-tracking branch 'upstream/master' into feature/interpolate
Dec 16, 2017
dd9fa8c
workaround for parameterized tests that are skipped in missing.py module
Dec 16, 2017
88d1569
requires_np112 for dataset interpolate test
Dec 18, 2017
3fb9261
Merge branch 'master' of github.com:pydata/xarray into feature/interp…
Dec 21, 2017
37882b7
remove req for np 112
Dec 21, 2017
a04e83e
fix typo in docs
Dec 21, 2017
48505a5
@requires_np112 for methods that use apply_ufunc in missing.py
Dec 21, 2017
20f957d
Merge branch 'master' of github.com:pydata/xarray into feature/interp…
Dec 21, 2017
282bb65
reuse type in apply over vars with dim
Dec 21, 2017
a6fcb7f
rework the fill value convention for linear interpolation, no longer …
Dec 22, 2017
2b0d9e1
flake8
Dec 30, 2017
d3220f3
Merge branch 'master' of github.com:pydata/xarray into feature/interp…
Dec 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ Computation
:py:attr:`~DataArray.count`
:py:attr:`~DataArray.dropna`
:py:attr:`~DataArray.fillna`
:py:attr:`~DataArray.ffill`
:py:attr:`~DataArray.bfill`
:py:attr:`~DataArray.interpolate_na`
:py:attr:`~DataArray.where`

**ndarray methods**:
Expand Down
48 changes: 48 additions & 0 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,54 @@ def fillna(self, value):
out = ops.fillna(self, value)
return out

def interpolate_na(self, dim=None, method='linear', inplace=False,
limit=None, **kwargs):
"""Interpolate values according to different methods.

Parameters
----------
dim : str
Specifies the dimension along which to interpolate.
method : {'linear', 'time', 'index', 'values', 'nearest'}
'linear': ignore the index and treat the values as equally
spaced. default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor point, but can we format this a little more consistently?

The compat arg on the Dataset constructor gets formatted nicely into a list by Sphinx and is still pretty readable as plain text:

compat : {'broadcast_equals', 'equals', 'identical'}, optional
String indicating how to compare variables of the same name for
potential conflicts when initializing this dataset:
- 'broadcast_equals': all values must be equal when variables are
broadcast against each other to ensure common dimensions.
- 'equals': all values and dimensions must be the same.
- 'identical': all values, dimensions and attributes must be the
same.

'time': interpolation works on daily and higher resolution data to
interpolate given length of interval
'index', 'values': use the actual numerical values of the index
'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'barycentric',
'polynomial' is passed to scipy.interpolate.interp1d with the
order given both 'polynomial' and 'spline' require that you also
specify and order (int) e.g. da.interpolate_na(method='polynomial',
order=4)
limit : limit : int, default None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit : is repeated twice

Maximum number of consecutive NaNs to fill. Must be greater than 0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "or None for no limit"


Returns
-------
DataArray
"""
from .missing import interp_na
return interp_na(self, dim=dim, method=method, inplace=inplace,
**kwargs)

def interpolate_at(self, dim, locs, method='linear', inplace=False,
limit=None, **kwargs):
# this is just here so I remember the signature we discussed
# dim: the dimension along which to interpolate
# locs: a broadcastable boolean mask describing where interpolation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean mask? I'm not quite sure how that would make sense. My immediate thought would be that locs should be a 1d array of coordinate values.

# should happen
raise NotImplementedError()

def ffill(self, dim, limit=None):
'''TODO'''
from .missing import ffill
return ffill(self, dim, limit=limit)

def bfill(self, dim, limit=None):
'''TODO'''
from .missing import bfill
return bfill(self, dim, limit=limit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need bottleneck installed to use bfill or ffill? Maybe it should be noted in docstrings.


def combine_first(self, other):
"""Combine two DataArray objects, with union of coordinates.

Expand Down
Loading