Background
I have 4 sets of data for a brushed DC motor all collected from the same experiment:
- torque vs speed (T vs w)
- torque vs efficiency (T vs n)
- torque vs input power (T vs Pin)
- torque vs output power (T vs Pout)
However, each data set has:
- slightly different x values for the first and last data pairs (T_0 and T_N do not match between each data set)
- different spacing between each data point (dT is not the same for all sets)
- different sizes ("T vs w" has more data pairs than "T vs Pin")
Problem
These differences prevent me from processing between data sets. For example, I can't use the T array of a single experiment for all my calculations, and I can't compare the measured Pout to a calculated Pout (T*w) at different T's.
What's the best way of re-sampling my data to generate uniformly-sized and uniformly-spaced sets?
Attempted solution
For each data set:
find domain shared with all sets (max x_0 and min x_N between all x)
extract indices corresponding to shared domain
#(idx = np.where(np.logical_and(x>=xMin,x<=xMax)))
if set x_0 != shared x_0:
linearly interpolate for new y_0 based on old x & y, shared x_0, and shared y_0
Piecewise linear interpolation (my own custom function) of M data points in the set
However, this still gives me inconsistent results because the "timestep" for each re-meshed data set is still different from data set to data set.
Hypothesis
Use scipy's built-in interpolation libraries to generate a linear interpolation function for each data set and simply populate a new data table with the same start & stop indices and timestep.
UPDATE/solution
Writing this question out helped me quickly realize that scipy's interp1d function was the best solution for me especially since all my data points are ~linear. I solved my problem as follows:
- Looped through each data set to find the shared domain (min T_N, max T_0)
- Loop again (2nd loop necessary) and create interp1d function for each data set
- Evaluate the same uniformly-spaced domain with each interpolant
- Save results to text file