Skip to content

interp over time coordinate #2284

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

Closed
ghost opened this issue Jul 12, 2018 · 2 comments · Fixed by #2325
Closed

interp over time coordinate #2284

ghost opened this issue Jul 12, 2018 · 2 comments · Fixed by #2325

Comments

@ghost
Copy link

ghost commented Jul 12, 2018

Before I start, I'm very excited about the interp addition in 0.10.7. Great addition and thanks to @fujiisoup and @shoyer.

I see there was a bit of a discussion in the interp pull request, #2104, about interpolating over times and that it was suggested to wait for use cases. I can think of an immediate use case in my line of work.
I frequently use regular gridded geophysical data (time, lat, lon), not unlike the sample tutorial air_temperature data, and the data must be interpolated to line up with corresponding satellite measurements that are irregularly spaced in lat, lon and time.

Being able to interpolate in one quick step would be fantastic. For example:

ds = xr.tutorial.load_dataset('air_temperature')
ds.interp(lat=60.5, lon=211, time='2013-01-01T03:14:37')

Problem description

Currently issues TypeError: cannot perform reduce with flexible type.

Desired Output

<xarray.Dataset>
Dimensions:  ()
Coordinates:
    lat      float64 60.5
    lon      int64 211
    time    datetime64[ns] 2013-01-01T03:14:37
Data variables:
    air      float64 273.5
@shoyer
Copy link
Member

shoyer commented Jul 12, 2018

Thanks for bringing this up.

@fujiisoup actually implemented interpolation for datetime64 as part of writing interp_like() , which will be in the next release of xarray (0.10.8). With the current development version of xarray:

In [6]: import numpy as np

In [7]: ds.interp(lat=60.5, lon=211, time=np.datetime64('2013-01-01T03:14:37'))
Out[7]:
<xarray.Dataset>
Dimensions:  ()
Coordinates:
    lat      float64 60.5
    lon      int64 211
    time     datetime64[ns] 2013-01-01T03:14:37
Data variables:
    air      float64 273.5
Attributes:
    Conventions:  COARDS
    title:        4x daily NMC reanalysis (1948)
    description:  Data is from NMC initialized reanalysis\n(4x/day).  These a...
    platform:     Model
    references:   http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly...

However, you do currently need to wrap your indexer explicitly in a np.datetime64 object. It would be nice to support casting strings to dates, somewhat like what we do in .sel(). This would be a good candidate for a pull request.

(I'll try to release 0.10.8 soon, maybe within the next week)

@ghost
Copy link
Author

ghost commented Jul 12, 2018

Thanks, I will gladly exercise patience until then.

dcherian pushed a commit to dcherian/xarray that referenced this issue Jul 28, 2018
dcherian pushed a commit to dcherian/xarray that referenced this issue Jul 28, 2018
fujiisoup pushed a commit that referenced this issue Jul 29, 2018
…2325)

* interp() now accepts date strings as desired co-ordinate locations

Fixes #2284

* Consolidated tests.

* Update condition for python 2

* Add additional test.

* Add decorator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant