Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
target_train[i] = 1
elif Train_data.loc[Train_data[0] == mats[i][:6], 1].values == 'O':
target_train[i] = 2
else:
target_train[i] = 3
Label_set = np.zeros((len(mats), number_of_classes))
for i in range(np.shape(target_train)[0]):
dummy = np.zeros((number_of_classes))
dummy[int(target_train[i])] = 1
Label_set[i, :] = dummy
inputs = 60 #Previus value for 9k check is 95
X_new = np.zeros((size, inputs))
for i in range(size):
out = ecg.christov_segmenter(signal=X[i, :], sampling_rate=300.)
A = np.hstack((0, out[0][:len(out[0]) - 1]))
B = out[0]
dummy = np.lib.pad(B - A, (0, inputs - len(B)), 'constant', constant_values=(0))
X_new[i, :] = dummy
print('All is OK')
X = X_new
X = (X - X.mean())/(X.std())
Label_set = Label_set[:size, :]
# X_new = np.zeros((size, check))
# Label_new = np.zeros((size, 4))
# stop = 0
# j = -1
# for i in range(np.shape(X)[0]):
#ts = int(str(path)[index1:index2])
APC, NORMAL, LBB, PVC, PAB, RBB, VEB = [], [], [], [], [], [], []
output.append(str(path))
result = {"APC": APC, "Normal": NORMAL, "LBB": LBB, "PAB": PAB, "PVC": PVC, "RBB": RBB, "VEB": VEB}
indices = []
kernel = np.ones((4,4),np.uint8)
csv = pd.read_csv(path)
csv_data = csv[' Sample Value']
data = np.array(csv_data)
signals = []
count = 1
peaks = biosppy.signals.ecg.christov_segmenter(signal=data, sampling_rate = 200)[0]
for i in (peaks[1:-1]):
diff1 = abs(peaks[count - 1] - i)
diff2 = abs(peaks[count + 1]- i)
x = peaks[count - 1] + diff1//2
y = peaks[count + 1] - diff2//2
signal = data[x:y]
signals.append(signal)
count += 1
indices.append((x,y))
for count, i in enumerate(signals):
fig = plt.figure(frameon=False)
plt.plot(i)
plt.xticks([]), plt.yticks([])
for spine in plt.gca().spines.values():
def test_rpeaks_simple(data_path):
signal, mdata = load_txt(data_path)
logging.info("--------------------------------------------------")
logging.info("载入信号-%s, 长度 = %d " % (data_path, len(signal)))
fs = 360 # 信号采样率 360 Hz
logging.info("调用 christov_segmenter 进行R波检测 ...")
tic = time.time()
rpeaks = ecg.christov_segmenter(signal, sampling_rate=fs)
toc = time.time()
logging.info("完成. 用时: %f 秒. " % (toc - tic))
# 以上这种方式返回的rpeaks类型为biosppy.utils.ReturnTuple, biosppy的内置类
logging.info("直接调用 christov_segmenter 返回类型为 " + str(type(rpeaks)))
# 得到R波位置序列的方法:
# 1) 取返回值的第1项:
logging.info("使用第1种方式取R波位置序列 ... ")
rpeaks_indices_1 = rpeaks[0]
logging.info("完成. 结果类型为 " + str(type(rpeaks_indices_1)))
# 2) 调用ReturnTuple的as_dict()方法,得到Python有序字典(OrderedDict)类型
logging.info("使用第2种方式取R波位置序列 ... ")
rpeaks_indices_2 = rpeaks.as_dict()
# 然后使用说明文档中的参数名(这里是rpeaks)作为key取值。
rpeaks_indices_2 = rpeaks_indices_2["rpeaks"]
logging.info("完成. 结果类型为 " + str(type(rpeaks_indices_2)))