[SciPy-User] interpolation question

josef.pktd at gmail.com josef.pktd at gmail.com
Wed Sep 23 10:17:02 EDT 2009


On Wed, Sep 23, 2009 at 9:53 AM, Zachary Pincus <zachary.pincus at yale.edu> wrote:
>> Is it possible using scipy to fill the gaps in one list using
>> another list?
>>
>> I have two lists, one with time values and one with meter values.
>> Both lists are the same length and their indexes are linked
>> (timelist[i] and depthlist[i] belong to the same location). The
>> timevalue list has gaps (nodata values).
>>
>> The shape of both lists is very similar. What I would like to do is
>> to use the depthlist shape to fill in the gaps of the timelist. Is
>> there a method within scipy which does the trick? I first tried
>> simple regression but that didn't result in a smooth line. I would
>> like to be able to use the values bordering each gap as control
>> points.
>
>
> First: do these (depth, time) pairs, sorted by depth, describe a
> proper function (e.g. no depth with two associated times, etc.)? If
> not, you'll need to figure out a parametric representation of the
> function: e.g. use the indices (i, depth) and (i, time) to
> parameterized a 2D curve.
>
> Assuming the former case, the first thing you'll need to do is make
> three lists: depth_in with the depth values which have associated
> times, time_in with those time values, and depth_out, with the depth
> values that have no associated times.
>
> times_out = numpy.interp(depth_out, depth_in, time_in) will then
> linearly interpolate the time values for the depths in the depth_out
> list.
>
> You can also use the spline interpolation routines in
> scipy.interpolate. There are some convenient wrapper classes, but the
> ones I use most often are the raw fitpack routines:
>
> smoothing = upper bound on sum of squared distances between the fit
> curve and the (depth, time) input points. Can be zero, but then the
> spline might be prone to ringing.
> order = order of spline interpolation: 0 is nearest-neighbor, 1 is
> linear, 3 is recommended in general.
> tck = scipy.interpolate.splrep(depth_in, time_in, k=order, s=smoothing)
> times_out = scipy.interpolate.splev(depth_out, tck)
>
> You'll probably want to look at what times the spline provides for the
> depths provided in depth_in, to gauge if the curve is being over-
> smoothed.
>
> In the parametric case, you'll want to either do two rounds of linear
> interpolation for the (i, depth) and (i, time) curves, or use
> scipy.interpolate.splprep.
>
> Also there is scipy.interpolate.Rbf which uses radial basis functions
> to interpolate scattered data points. This might be a very smooth way
> of interpolating your data as well.
>
> Zach
>

If you want to use the regression approach instead of interpolation, then
I would try kernel regression, which would locally be much smoother than
linear regression, but might in the outcome be very similar to
scipy.interpolate.Rbf.
But, except for some toy examples, I haven't used this.

Josef

>
>
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list