Exemplo n.º 1
0
def prepare_GSC (control_file, num_days_list):
    print ('start prepare_GSC')
    for num_days in num_days_list:
        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=data_dir + 'mimic_gsc_score.csv',
                        lab_parameter_name='gsc', num_days=num_days,
                        output_dir_in_func=output_dir)
Exemplo n.º 2
0
def prepare_breathing (control_file,num_days_list):

    blood_file = data_dir+ 'blood_data_for_modeling_clean.csv'
    print ('start prepare_breathing')
    num_days = 100 # this is used also for apache - first day in icu so we need all the data
    # -------10/01/2019 - no need - data in mimic is in the same hours
    #todo- delete comment
    fio2_joined_file = join_fio2_sources(control_file,blood_file=blood_file,respiratory_file=data_dir + 'Respiratory_data_for_modeling.csv')
    fio2_joined_file = output_dir + 'fio2_both_sources.csv'
    create_fio2_pio2_ratio(control_file,
                           pio2_file=blood_file,
                           fio2_file=fio2_joined_file,
                           num_days=num_days,
                           new_param_name='FIO2',default_val=30)

    handle_signal_data_new.create_A_aPO2(paco2_file=blood_file,
                                         paco2_param_name = 'pCO2',
                  fio2_file = output_dir+'FIO2_calculated.csv', fio2_param_name = 'FIO2',
                  pao2_file=blood_file,pao2_param_name = 'pO2')
    # ---------end no need
    #todo - delete comment
    df_to_add = handle_signal_data_new.create_signal_combination(blood_file,
                                          'pO2', 'FIO2', 'divide', fio2_joined_file,min_val_feature2=21)

    for num_days in num_days_list:
        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=output_dir + 'pO2_divide_FIO2.csv',
                        lab_parameter_name='pO2_divide_FIO2', num_days=num_days,
                        output_dir_in_func=output_dir)

        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=output_dir + 'A_aPO2.csv',
                        lab_parameter_name='A_aPO2', num_days=num_days, output_dir_in_func=output_dir,
                        complete_0_values=True, complete_hours=True)
Exemplo n.º 3
0
def prepare_blood(control_file, blood_lab_file = data_dir+'blood_data_for_modeling.csv',num_days_list=[5]):

    blood_lab_file_clean = data_dir+'blood_data_for_modeling_clean.csv'

    blood_df = pd.read_csv(blood_lab_file, encoding="ISO-8859-1")
    blood_df = blood_df[blood_df['value'].str.contains('>|<|GREATER|ERROR|UNABLE|LESS|VOIDED|-') == False]
    blood_df['value'] = blood_df['value'].str.replace('+','')
    blood_df = blood_df[blood_df['value'].apply(lambda x: x[0].isdigit())]
    blood_df.to_csv(blood_lab_file_clean)


    group_functions = {'patient_id' : {'patient_id_nunique': 'nunique', 'rows_cnt' :'count'}}
    blood_df_grp = blood_df.groupby(['parameter_name']).agg(group_functions)
    blood_df_grp.columns = blood_df_grp.columns.droplevel(0)
    blood_df_grp.reset_index(level=0, inplace=True)
    # print (blood_df_grp)

    blood_df_grp_filter = blood_df_grp[blood_df_grp.patient_id_nunique>200]
    #take only numeric values

    for param_name in blood_df_grp_filter.parameter_name :
        if param_name in ['Ventilation Rate','Anisocytosis','Fibrin Degradation Products']:
            continue
        # if param_name < 'Hypochromia':
        #     print ('skip '+param_name)
        #     continue
        for num_days in num_days_list:
            handle_signal_data_new.create_lab_data(control_file,
                                                   lab_df=blood_df,
                                                   lab_parameter_name=param_name,
                                                   num_days=num_days, output_dir_in_func=output_dir)
Exemplo n.º 4
0
def prepare_signals(control_file, data_file = data_dir+'Respiratory_data_for_modeling.csv',num_days_list=[5]):

    print ('start prepare_signals - '+data_file)
    data_df = pd.read_csv(data_file, encoding="ISO-8859-1")
    data_df = data_df.rename(columns = {'SUBJECT_ID':'patient_id','VALUE':'value','CHARTTIME':'time','LABEL':'parameter_name'})
    # data_df.to_csv(data_file)

    group_functions = {'patient_id' : {'patient_id_nunique': 'nunique', 'rows_cnt' :'count'}}
    data_df_grp = data_df.groupby(['parameter_name']).agg(group_functions)
    data_df_grp.columns = data_df_grp.columns.droplevel(0)
    data_df_grp.reset_index(level=0, inplace=True)
    print (data_df_grp)

    blood_df_grp_filter = data_df_grp[data_df_grp.patient_id_nunique>200]
    #take only numeric values

    for param_name in blood_df_grp_filter.parameter_name :

        calc_std_flag = True
        smooth_signal = True
        use_fft_feature = True
        if param_name=='Heart Rate':
            min_value = 35
            max_value = 210
        elif param_name == 'Temperature Fahrenheit':
            min_value = 93.2
            max_value = 113
        elif param_name=='Temperature Celsius':
            min_value = 34.5
            max_value = 45
        elif param_name in ['Arterial Blood Pressure mean','ART BP mean','Non Invasive Blood Pressure mean']:
            min_value = 25
            max_value = 330
        elif param_name in ['Arterial Blood Pressure diastolic','ART BP Diastolic','Non Invasive Blood Pressure diastolic',
                            'Manual Blood Pressure Diastolic Right']:
            min_value = 20
            max_value = 310
        elif param_name in  ['ART BP Systolic','Arterial Blood Pressure systolic','Non Invasive Blood Pressure systolic',
                             'Manual Blood Pressure Systolic Right','Manual Blood Pressure Systolic Left']:
            min_value = 30
            max_value = 350
        elif param_name=='Respiratory Rate':
            min_value = 4
            max_value = 80


        else:
            min_value = -99999
            max_value = 99999
            calc_std_flag = False
            smooth_signal = False
            use_fft_feature = False
        for num_days in num_days_list:

            try:
                handle_signal_data_new.create_lab_data(control_file,
                                                       lab_df=data_df,
                                                       lab_parameter_name=param_name,min_value=min_value,
                                                       max_value=max_value,
                                                       smooth_signal=smooth_signal,use_fft_feature=use_fft_feature
                                                       ,calc_std_flag=calc_std_flag,
                                                       num_days=num_days, output_dir_in_func=output_dir)
            except Exception:
                print(param_name + ' - create_lab_data failed')
                pass
Exemplo n.º 5
0
def prepare_medicine (control_file, num_days_list):
    print ('start prepare_medicine')

    #---vasoactive-------------
    org_file = data_dir+'mimic_medications_data_for_modeling.csv'
    new_file_name = output_dir+'mimic_medications_data_with_dummy.csv'

    updated_vasoactive_file = handle_signal_data_new.add_dummy_rows_for_control_set(control_file,
                                                             org_file,
                                                             'Norepinephrine',
                                                             output_file=new_file_name)
    updated_vasoactive_file = handle_signal_data_new.add_dummy_rows_for_control_set(control_file,
                                                             updated_vasoactive_file,
                                                             'Phenylephrine',
                                                             output_file=new_file_name)
    updated_vasoactive_file = handle_signal_data_new.add_dummy_rows_for_control_set(control_file,
                                                             updated_vasoactive_file,
                                                             'Epinephrine',
                                                             output_file=new_file_name)
    updated_vasoactive_file = handle_signal_data_new.add_dummy_rows_for_control_set(control_file,
                                                             updated_vasoactive_file,
                                                             'Dopamine',
                                                             output_file=new_file_name)
    updated_vasoactive_file = handle_signal_data_new.add_dummy_rows_for_control_set(control_file,
                                                             updated_vasoactive_file,
                                                             'Vasopressin',
                                                             output_file=new_file_name)
    for num_days in num_days_list:
        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=updated_vasoactive_file,
                        lab_parameter_name='Norepinephrine', num_days=num_days, complete_0_values=True, complete_hours=True, output_dir_in_func=output_dir)

        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=updated_vasoactive_file,
                        lab_parameter_name='Phenylephrine', num_days=num_days, complete_0_values=True, complete_hours=True, output_dir_in_func=output_dir)

        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=updated_vasoactive_file,
                        lab_parameter_name='Epinephrine', num_days=num_days, complete_0_values=True, complete_hours=True, output_dir_in_func=output_dir)

        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=updated_vasoactive_file,
                        lab_parameter_name='Dopamine', num_days=num_days, complete_0_values=True, complete_hours=True, output_dir_in_func=output_dir)
        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=updated_vasoactive_file,
                        lab_parameter_name='Vasopressin', num_days=num_days, complete_0_values=True, complete_hours=True, output_dir_in_func=output_dir)


    #------------Morphine/Fentanyl/Propofol 2% ( Diprivan )' (only 1 patient with 1%), 'Dormicum'

    updated_vasoactive_file = handle_signal_data_new.add_dummy_rows_for_control_set(control_file,
                                                             org_file,
                                                             'Midazolam(Versed)',
                                                             output_file=new_file_name)
    updated_vasoactive_file = handle_signal_data_new.add_dummy_rows_for_control_set(control_file,
                                                            updated_vasoactive_file,
                                                             'Fentanyl',
                                                             output_file=new_file_name)
    updated_vasoactive_file = handle_signal_data_new.add_dummy_rows_for_control_set(control_file,
                                                             updated_vasoactive_file,
                                                             'Morphine Sulfate',
                                                             output_file=new_file_name)
    updated_vasoactive_file = handle_signal_data_new.add_dummy_rows_for_control_set(control_file,
                                                             updated_vasoactive_file,
                                                             'Propofol',
                                                             output_file=new_file_name)


    for num_days in num_days_list:
        # todo - delete  comment
        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=updated_vasoactive_file,
                        lab_parameter_name='Fentanyl', num_days=num_days, complete_0_values=True, complete_hours=True, output_dir_in_func=output_dir)

        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=updated_vasoactive_file,
                        lab_parameter_name='Morphine Sulfate', num_days=num_days, complete_0_values=True, complete_hours=True, output_dir_in_func=output_dir)

        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=updated_vasoactive_file,
                        lab_parameter_name='Propofol', num_days=num_days, complete_0_values=True, complete_hours=True, output_dir_in_func=output_dir)

        handle_signal_data_new.create_lab_data(control_file,
                        lab_file=updated_vasoactive_file,
                        lab_parameter_name='Midazolam(Versed)', num_days=num_days, complete_0_values=True, complete_hours=True, output_dir_in_func=output_dir)