0

I have this data:

8.7530482   1.34E-01
8.7584016   2.68E-01
8.7637563   6.70E-01
8.769111    1.47E+00
8.7744644   2.15E+00
8.7798191   3.08E+00
...
11.5693578  6.36E+01
11.5747125  6.21E+01
11.5800659  6.17E+01
11.5854193  6.14E+01
11.590774   6.14E+01
11.5961287  6.15E+01
11.6014821  6.45E+01

The problem is that I need the domain of the data to look like this:

8.75
8.76
8.77
8.78
8.79
...
11.57
11.58
11.59
11.60
11.61

While keeping the range values in agreement with the original data. So I need to intelligently average the data to get a regular interval domain.

I'm trying to use python to do this.

Any help would be greatly appreciated.

web nocko
  • 1
  • 1

1 Answers1

0

It sounds like you want to linearly interpolate your data. For this, use scipy's interp1d.

Here's a demo:

import numpy as np
from scipy.interpolate import interp1d

data = """
11.5693578  6.36E+01
11.5747125  6.21E+01
11.5800659  6.17E+01
11.5854193  6.14E+01
11.590774   6.14E+01
11.5961287  6.15E+01
11.6014821  6.45E+01
"""
data = np.fromstring(data, sep=' ')
data = data.reshape((-1, 2))

x, y = data.T
f = interp1d(x, y)

Now we can use f to get the values of the interpolation on the regular domain:

regular_x = np.arange(11.57, np.max(x), .01)

plt.plot(x, y, marker='o')
plt.plot(regular_x, f(regular_x), marker='o')

plt.legend(['Original', 'Interpolated'], loc='best')
plt.ylim([61, 65])

enter image description here

jme
  • 19,895
  • 6
  • 41
  • 39