Created
September 22, 2023 13:02
-
-
Save daguiam/f43433afaf605d5609ccfb46014a540b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def interpolate_data(x,y,z, step_y, mincount=400): | |
""" Assumes the x is repeated samples and y is the non-periodic signal | |
""" | |
step = step_y | |
x_list = [] | |
y_list = [] | |
z_list = [] | |
vals, idx_start, idx_inverse, count = np.unique(x, return_counts=True, return_index=True, return_inverse=True) | |
idx_start = idx_start[count>mincount] | |
count = count[count>mincount] | |
x_split = np.split(x, idx_start) | |
y_split = np.split(y, idx_start) | |
z_split = np.split(z, idx_start) | |
new_y = np.arange(y.min(), y.max(), step) | |
for i, (xi, yi, zi) in enumerate(zip(x_split, y_split, z_split)): | |
if len(xi) == 0: | |
continue | |
f = interpolate.interp1d(yi, zi, fill_value="extrapolate") | |
new_z = f(new_y) | |
x_list.append(xi[0]*np.ones(len(new_y))) | |
y_list.append(new_y) | |
z_list.append(new_z) | |
x_list, y_list, z_list | |
z_list | |
x_list = np.array(x_list) | |
y_list = np.array(y_list) | |
z_list = np.array(z_list) | |
# plt.pcolormesh(x_list, y_list, z_list) | |
# plt.plot(y) | |
x_list.shape, y_list.shape, z_list.shape | |
return x_list, y_list, z_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment