Beispiel #1
0
 def _read_burst_ranges_file(self, burst_ranges_file):
     patient = utils.get_pt_from_edf_name(burst_ranges_file)
     burst_ranges_idx = burst_ranges_file.find('burst_ranges')
     edf_name_no_ext = burst_ranges_file[:burst_ranges_idx-1]
     burst_ranges_filepath = os.path.join(self.output_dir, patient, edf_name_no_ext, burst_ranges_file)
     burst_ranges_df = pd.read_csv(burst_ranges_filepath, delimiter='\t')
     return burst_ranges_df.as_matrix()
Beispiel #2
0
 def _read_similarity_matfile(self, similarity_matfile, convert_to_np):
     # returns np array of the data contained inside one similarity matfile 
     # (which is similarity array for one episode in one edf)
     patient = utils.get_pt_from_edf_name(similarity_matfile)
     if 'dtw' in similarity_matfile:
         sim_fn_idx = similarity_matfile.find('dtw')
     elif 'xcorr' in similarity_matfile:
         sim_fn_idx = similarity_matfile.find('xcorr')
     else:
         assert('dtw' in similarity_matfile or 'xcorr' in similarity_matfile)
     edf_name_no_ext = similarity_matfile[:sim_fn_idx-1]
     similarity_output_filepath = os.path.join(self.output_dir, patient, edf_name_no_ext, similarity_matfile)
     ## TODO TODO
     f = h5py.File(similarity_output_filepath, 'r')
     similarity_arr = np.array(f[f.keys()[0]]).transpose()
     # if the similarity_struct is empty, matlab would load properly as [], 
     # but h5py loads it as np array([0, 0], dtype=uint64)
     if np.array_equal(similarity_arr, np.array([0,0])):
         # similarity_struct should be empty
         similarity_arr = np.array([])
     else:
         assert(similarity_arr.shape[0]==1), "similarity_arr must have shape 1 x n"
         assert(len(similarity_arr.shape)==2), "similarity_arr must have shape 1 x n"
         similarity_arr = similarity_arr[0]
         if len(similarity_arr)==0:
             print('len sim is 0')
     return similarity_arr
Beispiel #3
0
 def get_edf_results(self, edf_name, filter_condition):
     # returns paths to output files for an edf for which filter_condition is true
     patient = utils.get_pt_from_edf_name(edf_name)
     results_dir = os.path.join(self.output_dir, patient, edf_name)
     edf_results = os.listdir(results_dir)
     edf_results = [x for x in edf_results if filter_condition(x)]
     edf_result_paths = [os.path.join(results_dir, x) for x in edf_results]
     return edf_result_paths
Beispiel #4
0
 def _get_burst_ranges_files_for_edf(self, edf_name):
     # returns list of files that contain burst range info for an edf
     patient = utils.get_pt_from_edf_name(edf_name)
     edf_no_ext = edf_name.split('.')[0]
     patient_files = os.listdir(os.path.join(self.output_dir, patient, edf_no_ext))
     edf_files = [f for f in patient_files if edf_name in f]
     burst_ranges_files = [f for f in edf_files if 'burst_ranges' in f and f[-3:]=='csv']
     return burst_ranges_files
Beispiel #5
0
 def _get_similarity_files_for_edf(self, edf_name):
     # returns dictionary of similarity_fn to list of filenames of results
     # list will contain > 1 element when the results are in parts
     # eg, given 'CA_MGH_sid141_01_20140218', returns 
     # {'dtw':['CA_MGH_sid141_01_20140218_142742_dtw_part1_episode_idx_1_13.mat'], 'xcorr':['CA_MGH_sid141_01_20140218_142742_xcorr_part1_episode_idx_1_13.mat']}
     patient = utils.get_pt_from_edf_name(edf_name)
     edf_no_ext = edf_name.split('.')[0]
     patient_files = os.listdir(os.path.join(self.output_dir, patient, edf_no_ext))
     edf_files = [f for f in patient_files if edf_name in f and '.mat' in f]
    
     similarity_files = {'dtw':[], 'xcorr':[]}
     for f in edf_files:
         if 'dtw' in f:
             similarity_files['dtw'].append(f)
         elif 'xcorr' in f:
             similarity_files['xcorr'].append(f)
         else:
             print('File {} with unknown similarity function'.format(f))
     return similarity_files
Beispiel #6
0
    '/afs/csail.mit.edu/u/t/tzhan/eeg/coma_EEG_alice_zhan/patient_outcome_info/exclude_patient_sids.txt'
)

# # All_all.txt

# ### Create list of all our patients, and {patient:[edfs]}

# In[13]:

our_patients = set([])
all_edfs = read_list(
    '/afs/csail.mit.edu/u/t/tzhan/eeg/coma_EEG_alice_zhan/patient_outcome_info/all_all.txt'
)
patient_to_edfs = defaultdict(list)
for edf in all_edfs:
    patient = utils.get_pt_from_edf_name(edf)
    our_patients.add(patient)
    edf_fn = edf.split('/')[-1]
    patient_to_edfs[patient].append(edf_fn)
our_patients = list(our_patients)
our_patients.sort(key=utils.parse_patient_name)
patient_to_edfs = dict(patient_to_edfs)

# In[14]:

#write_list(our_patients, '/afs/csail.mit.edu/u/t/tzhan/eeg/coma_EEG_alice_zhan/patient_outcome_info/all_patient_names.txt')

# # Master Lookup

# ### List of all sids