def max_add_feat(active_chl,rng,pf): rng = rng min_per=1 addfeat_data = 0 header = preproc.get_header(pf) header_non_act = np.copy(header).tolist() header_non_act.remove(active_chl) header_non_act.remove('Elapsed time') for chl in header_non_act: sig_add = preproc.get_column(chl,pf)[2:] sig_add = preproc.check(sig_add,return_series=1)[0] chl_add = sig_add[rng[0]:rng[-1]] if not discard_add_feat(sig_add,rng): idx_isnan = np.isnan(chl_add) idx = np.arange(len(chl_add)) idx_nan = idx[idx_isnan] percent = len(idx_nan)/float(len(idx)) if min_per ==1: min_per=percent min_chl = sig_add elif percent<=min_per: min_per = percent min_chl = sig_add if min_per==0: break addfeat_data = min_chl[rng[0]-50000:rng[0]] if addfeat_data!=0: if np.isnan(addfeat_data).any(): idx = np.arange(len(addfeat_data)) idx_isnan = np.isnan(addfeat_data) idx = idx[idx_isnan].tolist() idx_start = idx[-1] addfeat_data = addfeat_data[idx_start:] return chl_add, addfeat_data
__author__ = 'aubrey9012' import numpy as np import pandas as pd import pickle import sys sys.path.append('/Users/aubrey9012/Desktop') import preproc import interpolator file_name = '3270954' pf = '/Users/aubrey9012/Downloads/medical_ICU-features/data/mimic/'+str(file_name)+'.csv' header = preproc.get_header(pf) header.remove('Elapsed time') for col in header: if col != 'ICP': si = interpolator.SignalInterpolator(col,pf,40,0) else: si = interpolator.SignalInterpolator(col,pf,40,1) si_ = si.interpolate() if si_!=0: cpi = interpolator.CopyPasteInterpolator(si_) si_full = cpi.interpolate() dump_name= str(col)+'.p' pickle.dump(si_,open(dump_name, "wb" )) if si_==0: pickle.dump(si_,open(dump_name,"wb"))