根据具有mr_mo出色答案的帖子,我正在寻找一种解决方案,以计算应变和温度的温度偏移信号。 Calculate time shift between two signals and shifting
def process_data_time_delay(temperature, strain, df):
from scipy import signal
# normalization before ACF
def normalize(data):
return (data - np.mean(data, axis=0).reshape((1, -11))) / (np.std(data, axis=0).reshape((1, -1)))
# select subset of columns, seems relevant as a group
SCOLS = ['T1', 'W_A1']
# just to see the data
f = plt.figure()
ax = f.add_subplot(111)
df[SCOLS[:2]].iloc[::10].plot(ax=ax)
ax.set_title('Raw data')
# normalization
normalized = normalize(df[SCOLS].values)
f = plt.figure()
ax = f.add_subplot(111)
ax.plot(np.arange(normalized.shape[0]), normalized[:, 0], label='TW_A1')
ax.plot(np.arange(normalized.shape[0]), normalized[:, 1], label='W_A1')
ax.set_title('Normalized')
# ACF between two components
x1x2 = np.correlate(normalized[:, 0], normalized[:, 1], 'full')
# see the results
f = plt.figure()
ax = f.add_subplot(111)
ax.plot(x1x2)
ax.set_title('ACF')
df['TIMESTAMP'] = pd.to_datetime(df['TIMESTAMP'])
peaks_indices = signal.find_peaks_cwt(array(x1x2).flatten(), np.arange(1, len(x1x2)))
print(peaks_indices)
delta_index = np.argmax(peaks_indices);
delta_time = df['TIMESTAMP'][delta_index] - df['TIMESTAMP'][0]
# assuming timestamps is a datetime64 numpy array that can be easily obtained from pandas;
shifted_signal = x1x2[delta_time:]
f = plt.figure()
ax = f.add_subplot(111)
ax.plot(shifted_signal)
# mainloop
plt.show()
return x1x2
现在,在计算信号峰值时出现内存错误。