def _load_header_file(filename, input_directory): """Load header file.""" # Load file file = open(os.path.join(input_directory, '{}.hea'.format(filename)), 'r') content = file.read().split('\n') file.close() return parse_header(header_data=content)
def _load_header_file(self, filename): """Load header file.""" # Load file file = open( os.path.join(self.raw_path, EXTRACTED_FOLDER_NAMES[self.dataset], '{}.hea'.format(filename)), 'r') content = file.read().split('\n') file.close() return parse_header(header_data=content)
def _import_meta_data(self): """Import meta data JSON files.""" if self.header_data is None: return json.load( open( os.path.join(DATA_PATH, 'formatted', '{}.json'.format(self.filename)))) else: meta_data = parse_header(self.header_data) self.filename = meta_data['filename'] return meta_data
def inference_data_loader(waveforms, header, fs_resampled, p_and_t_waves=False): """Convert data and header_data to .npy and dict format.""" # Parse header data header = parse_header(header_data=header, inference=True) # Transpose waveforms array waveforms = waveforms.T # Resample waveforms samples = int(waveforms.shape[0] * fs_resampled / header['fs']) waveforms = signal.resample(x=waveforms, num=samples, axis=0) # Compute heart rate hr = _compute_heart_rate(waveforms=waveforms, fs=fs_resampled) # Get rpeaks rpeaks = _get_rpeaks(waveforms=waveforms, fs=fs_resampled) rpeak_array = _get_peak_array(waveforms=waveforms, peaks=rpeaks) rpeak_times = _get_peak_times(waveforms=waveforms, peak_array=rpeak_array, fs=fs_resampled) # Get P-waves and T-waves if p_and_t_waves: p_waves, t_waves = _get_p_and_t_waves(waveforms=waveforms, rpeaks=rpeaks) else: p_waves = None t_waves = None p_wave_array = _get_peak_array(waveforms=waveforms, peaks=p_waves) p_wave_times = _get_peak_times(waveforms=waveforms, peak_array=p_wave_array, fs=fs_resampled) t_wave_array = _get_peak_array(waveforms=waveforms, peaks=t_waves) t_wave_times = _get_peak_times(waveforms=waveforms, peak_array=t_wave_array, fs=fs_resampled) # Get meta data meta_data = { 'filename': None, 'dataset': None, 'datetime': header['datetime'], 'channel_order': header['channel_order'], 'age': header['age'], 'sex': header['sex'], 'amp_conversion': header['amp_conversion'], 'fs': header['fs'], 'fs_resampled': fs_resampled, 'length': header['length'], 'num_leads': header['num_leads'], 'labels_SNOMEDCT': None, 'labels_short': None, 'labels_full': None, 'labels_int': None, 'labels_training': None, 'labels_training_merged': None, 'shape': waveforms.shape, 'hr': hr, 'rpeaks': rpeaks, 'rpeak_array': rpeak_array.tolist(), 'rpeak_times': rpeak_times, 'p_waves': p_waves, 'p_wave_array': p_wave_array.tolist(), 'p_wave_times': p_wave_times, 't_waves': t_waves, 't_wave_array': t_wave_array.tolist(), 't_wave_times': t_wave_times, 'labels_unscored_SNOMEDCT': None, 'labels_unscored_short': None, 'labels_unscored_full': None, 'p_and_t_waves': p_and_t_waves } return waveforms, meta_data