def generate_wavelet(list_ecg, parameters, name): freq = parameters[0] epi_qrs = [parameters[1] for i in range(5)] wavelet = fb.WaveletExtraction(epi_qrs=epi_qrs) for sig in list_ecg: wavelet.evaluete_signal(sig.input_signal, freq, label=sig.label) utils.write_file('models/wavelet_model_' + name, wavelet.serialize())
def generate_wavelet(list_ecg, freq, name): wavelet = fb.WaveletExtraction() for sig in list_ecg: wavelet.evaluete_signal(sig.input_signal, freq, is_valey=sig.is_valey) utils.write_file('models/wavelet_model_' + name, wavelet.serialize())
def generate_wavelet_db1(list_ecg, freq, name): wavelet_db1 = fb.WaveletTransform() for sig in list_ecg: wavelet_db1.evaluete_signal(sig.input_signal, label=sig.label) utils.write_file('models/wavelet_db1_model_' + name, wavelet_db1.serialize())
def generate_morfology(list_ecg, freq, name): morfology = fb.MorfologyDetector() for sig in list_ecg: morfology.evaluete_signal(sig.input_signal, int(len(sig.input_signal)/2)+1, is_valey=sig.is_valey) utils.write_file('models/morfology_model_' + name, morfology.serialize())
def generate_mathematical(list_ecg, offset, name): # Matemathical Models Evaluetion list_of_templates = utils.get_default_templates(offset) list_of_packets = utils.mp_signal_apply(utils.consume_packet_helper, list_ecg, list_of_templates, workers=3) m_model = fb.ECG.build_from_packets(list_of_packets) utils.write_file('models/m_model_' + name, m_model.serialize())
def generate_morfology(list_ecg, parameters, name): morfology = fb.MorfologyDetector(a=parameters[:2], b=parameters[2:4], c=parameters[4:6], d=parameters[6:]) for sig in list_ecg: morfology.evaluete_signal(sig.input_signal, int(len(sig.input_signal) / 2) + 1, is_valey=sig.is_valey, label=sig.label) utils.write_file('models/morfology_model_' + name, morfology.serialize())
def my_generate_random(list_ecg, offset, name): random.results = [] for sig in list_ecg: random.evaluete_signal(sig.input_signal) utils.write_file('models/random_model_' + name, random.serialize())
my_ecg = fb.ECG.build_from_packets(list_of_packets) len_packet = 35 list_ecg = my_ecg.build_packets(len_packet) list_ecg = my_ecg.packets return list_ecg if __name__ == '__main__': list_ecg = main() rd = fb.RandomExtraction(offset=35) for sig in list_ecg: rd.evaluete_signal(sig.input_signal) utils.write_file('teste', rd.serialize()) data = utils.read_file('teste') rd = fb.deserialize(data) table = rd.get_table_erros() t = [] for p in list_ecg: t.append(p.label) t = ['qRs_4' if x == 2 else x for x in t] t = ['QS_5' if x == 14 else x for x in t] t = ['rRs_8' if x == 10 else x for x in t] t = ['RS_9' if x == 5 else x for x in t] t = ['artifact' if x in [12, 11, 1, 18, 6, 15, -1] else x for x in t] X = table.values
heart_rate = np.mean(heart_rate) labels = [name for x in rpeaks] my_ecg = fb.ECG(input_signal=ecg_signal, indicators=rpeaks, labels=labels, is_filtered=False) if name == 'qRs_4': offset = int(intervals / 7) elif name == 'QS_5': offset = int(intervals / 7) elif name == 'rRs_8': offset = int(intervals / 7) elif name == 'RS_9': offset = int(intervals / 7) else: offset = int(intervals / 7) offset = 40 my_ecg.packets = my_ecg.build_packets(offset) utils.write_file('data/signal_' + name + '_' + str(i), my_ecg.serialize()) list_of_signals = [] for name in ListName: for i in range(10): data = utils.read_file('data/signal_' + name + '_' + str(i)) list_of_signals.append(fb.deserialize(data)) for i in range(len(list_of_signals)): plt.plot(list_of_signals[i].packets[0].input_signal) plt.show() plt.close()
# list_ecg, list_of_templates) my_ecg.packets = lst_of_packets return my_ecg if __name__ == '__main__': __spec__ = "ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>)" results = main() error = results.get_errors_table() param1 = results.get_param_table() [signals, models, names, errors, types] = results.get_signals_and_models(normalized=False, only_best=True) data = results.serialize() utils.write_file('outfile', data) data = utils.read_file('outfile') c = fb.deserialize(data) # t = [] # for p in results.packets: # t.append(p.label) # # error['types'] = [int(x) for x in types] # X = error.values # # # X_train, X_test, y_train, y_test = train_test_split( # X, t, test_size=0.4, random_state=0) #
def generate_hermite(list_ecg, freq, name): hermite = fb.HermiteExtraction() for sig in list_ecg: hermite.evaluete_signal(sig.input_signal, label=sig.label) utils.write_file('models/hermite_model_' + name, hermite.serialize())
def generate_hos(list_ecg, freq, name): hos = fb.HOSExtraction() for sig in list_ecg: hos.evaluete_signal(sig.input_signal, label=sig.label) utils.write_file('models/hos_model_' + name, hos.serialize())
def generate_ulbp(list_ecg, freq, name): ulbp = fb.ULBP1DExtraction() for sig in list_ecg: ulbp.evaluete_signal(sig.input_signal, label=sig.label) utils.write_file('models/ulbp_model_' + name, ulbp.serialize())