def save_signals(self): print("Saving Signals...") for dosage in self.files[self.folder_name]: # Load data self.time, self.signal, self.seis, _, self.phono, _ = hb.load_file_data(files = self.files, folder_name = self.folder_name, dosage = dosage, file_number = self.file_number) # Load Echo Time self.echo_time = self.files[self.folder_name][dosage][self.file_number]["echo_time"] # Clip signal size about echo time self.clip_signals() # Save File Name save_file_name = self.folder_name + "_d" + str(dosage) assert not os.path.isfile('data/Derived/signals/time_' + save_file_name + '.csv'), "Saved signals already exist, please delete before saving new signals." # Save Signals np.savetxt('data/Derived/signals/time_' + save_file_name + '.csv', self.time, delimiter=',') np.savetxt('data/Derived/signals/signal_'+ save_file_name + '.csv', self.signal, delimiter=',') np.savetxt('data/Derived/signals/seis_' + save_file_name + '.csv', self.seis, delimiter=',') np.savetxt('data/Derived/signals/phono_' + save_file_name + '.csv', self.phono, delimiter=',') print("\tDosage " + str(dosage) + " done") print("...Done Saving Signals") # Use these saved files from now on self.preloaded_signal = True
def load_signals(self): # Load Echo Time self.echo_time = self.files[self.folder_name][self.dosage][self.file_number]["echo_time"] if self.preloaded_signal: save_file_name = self.folder_name + "_d" + str(self.dosage) self.time = np.loadtxt('data/Derived/signals/time_' + save_file_name + '.csv', delimiter=',') self.signal = np.loadtxt('data/Derived/signals/signal_' + save_file_name + '.csv', delimiter=',') self.seis = np.loadtxt('data/Derived/signals/seis_' + save_file_name + '.csv', delimiter=',') self.phono = np.loadtxt('data/Derived/signals/phono_' + save_file_name + '.csv', delimiter=',') else: self.time, self.signal, self.seis, _, self.phono, _ = hb.load_file_data(files = self.files, folder_name = self.folder_name, dosage = self.dosage, file_number = self.file_number) # Clip Signals self.clip_signals()
interval = [ min(np.searchsorted(time, int(x)), len(time) - 1) for x in files[folder_name][dosage][1]["intervals"][1] ] interval = range(interval[0], interval[1]) time = time[interval] signal = signal[interval] seis = seis[interval] phono = phono[interval] else: time, signal, seis, _, phono, _ = hb.load_file_data( files=files, folder_name=folder_name, dosage=dosage, file_number=1) # Low Pass Signal signal = hb.bandpass_filter(time=time, signal=signal, freqmin=59, freqmax=61) signal = hb.lowpass_filter(time=time, signal=signal, cutoff_freq=50) # Define T and P peaks to build composites peaks = hb.get_peaks_for_composites(time=time, signal=signal, dosage=dosage, seis1=seis,
# if file_number != 1: # continue print("File Number: ", file_number) for interval_number in files[folder_name][dosage][file_number]["intervals"]: # # if interval_number != sample_interval: # # continue # if interval_number != 1: # continue print("Interval: ", interval_number) # Load Data time, signal, seis1, seis2, phono1, phono2 = hb.load_file_data( files, folder_name, dosage, file_number, interval_number, preloaded_signal, save_signal) # Calculate Composite lowpass_signal = hb.bandpass_filter(time = time, signal = signal, freqmin = 59, freqmax = 61) # Low-Pass filter under 10Hz lowpass_signal = hb.lowpass_filter(time = time, signal = lowpass_signal, cutoff_freq = 50)
os.chdir("../Derived") new_files = hb.load_intervals(folder_name) os.chdir("../..") for dosage in new_files[folder_name]: # Pick file file_name = files[folder_name][dosage][1]["file_name"] save_file_name = folder_name + "_d" + str( dosage) + "_" + file_name + "_i" + str(1) # Load Data time, signal, seis1, seis2, phono1, phono2 = hb.load_file_data( files=new_files, folder_name=folder_name, dosage=dosage, file_number=1, interval_number=1, preloaded_signal=False, save_signal=False) # Calculate Composite lowpass_signal = hb.bandpass_filter(time=time, signal=signal, freqmin=59, freqmax=61) lowpass_signal = hb.lowpass_filter(time=time, signal=lowpass_signal, cutoff_freq=50) peaks = hb.get_peaks_for_composites(time=time, signal=lowpass_signal,