Consider a series of data with a known coordinate (in this case, paleoclimate data with ages in thousands of years before present, or "ka"). For many reasons, the time coordinate for these data are never evenly spaced. But for most analyses, its critical to compare data on the same time coordinate.
What'd I'd love is a simple code that takes unevenly spaced data and linearly interpolates them to an even spacing, with the spacing interval defined by the user. Mathematically there are at least two ways of doing this:
- Take the rate of change between two points and using that rate to map values at intermediate points;
- Do a distance-weighted average, with the closer time point more heavily weighted. You should get the same answer either way.
Columns A through C are paleoclimate data with uneven spacing. Columns E through G are those same data, now evenly spaced to every 5 ka. I want to take the data in columns A through C and get the correct interpolation in Columns E through G subject to a ka parameter I set.
Once that basic code is in place, it'd be nice to add a few bells and whistles. An extrapolation function for time points outside the domain would be really helpful. For example, I have an interpolated value for 400 ka, even though I do not have data from times straddling 400 ka.
I have started with pandas for organizing the data and then another SO post pointed me towards traces. I am still working on it but would appreciate any insight.
A (ka) B C
401.3 3.49 0.34
403.2 3.95 0.25
407.2 3.74 1.13
409.2 3.71 1.03
411.2 3.73 1.05
413.1 3.58 -0.08
415.1 4.4 0.46
ka = 5
E (ka) F G
400 3.18 0.40
405 3.86 0.65
410 3.72 1.04
415 4.36 0.43