Commit afffad8e authored by Andrei Roibu's avatar Andrei Roibu
Browse files

corrected code bugs preventing database creation

parent 019ecb82
......@@ -24,6 +24,7 @@ from datetime import datetime
import pandas as pd
import os
def stats_calc(array):
""" Statistics calculator
......@@ -76,14 +77,15 @@ def stats_calc(array):
def database_generator(data_directory, train_inputs, train_targets, rsfMRI_mean_mask_path, dMRI_mean_mask_path):
subDirectoryList, number_of_subjects = directory_reader(folder_location=os.path.join(os.path.expanduser("~"),data_directory), subject_number=None, write_txt=False)
subDirectoryList, _ = directory_reader(folder_location=os.path.join(
os.path.expanduser("~"), data_directory), subject_number=None, write_txt=False)
dmri_imaging_dictionary = {}
rsfmri_imaging_dictionary = {}
dictionary_labels = ['w_reg', 'min', 'max', 'mean', 'med', 'std', '1p', '25p', '75p', '99p',
'0.1p', '0.2p', '0.3p', '0.4p', '0.5p', '0.6p', '0.7p', '0.8p', '0.9p',
'99.1p', '99.2p', '99.3p', '99.4p', '99.5p', '99.6p', '99.7p', '99.8p', '99.9p'
'99.1p', '99.2p', '99.3p', '99.4p', '99.5p', '99.6p', '99.7p', '99.8p', '99.9p',
'2p', '3p', '4p', '5p', '95p', '96p', '97p', '98p']
dmri_mean_volume = Image(dMRI_mean_mask_path).data
......@@ -95,40 +97,49 @@ def database_generator(data_directory, train_inputs, train_targets, rsfMRI_mean_
index += 1
subject_t0 = datetime.now()
w_dMRI, w_rsfMRI = regression_weight_calculator(data_directory, subject, train_inputs, train_targets, rsfMRI_mean_mask_path, dMRI_mean_mask_path)
w_dMRI, w_rsfMRI = regression_weight_calculator(
data_directory, subject, train_inputs, train_targets, rsfMRI_mean_mask_path, dMRI_mean_mask_path)
# ------------------
# ------------------ BOanaPelea626273532!C
dmri_path = os.path.join(os.path.expanduser("~"), data_directory, subject, train_inputs)
dmri_path = os.path.join(os.path.expanduser(
"~"), data_directory, subject, train_inputs)
dmri_volume, _ = resampleToPixdims(Image(dmri_path), (2, 2, 2))
dmri_volume = np.subtract(dmri_volume, np.multiply(w_dMRI, dmri_mean_volume))
min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6, perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98 = stats_calc(dmri_volume)
dmri_volume = np.subtract(
dmri_volume, np.multiply(w_dMRI, dmri_mean_volume))
min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6, perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98 = stats_calc(
dmri_volume)
dmri_imaging_dictionary[subject] = [w_dMRI, min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6, perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98]
dmri_imaging_dictionary[subject] = [w_dMRI, min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6,
perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98]
del dmri_path, dmri_volume, w_dMRI, min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6, perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98
# ------------------
rsfmri_path = os.path.join(os.path.expanduser("~"), data_directory, subject, train_targets)
rsfmri_path = os.path.join(os.path.expanduser(
"~"), data_directory, subject, train_targets)
rsfmri_volume = Image(rsfmri_path).data[:, :, :, 0]
rsfmri_volume = np.subtract(rsfmri_volume, np.multiply(w_rsfMRI, rsfmri_mean_volume))
rsfmri_volume = np.subtract(
rsfmri_volume, np.multiply(w_rsfMRI, rsfmri_mean_volume))
min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6, perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98 = stats_calc(rsfmri_volume)
min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6, perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98 = stats_calc(
rsfmri_volume)
rsfmri_imaging_dictionary[subject] = [w_rsfMRI, min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6, perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98]
rsfmri_imaging_dictionary[subject] = [w_rsfMRI, min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6,
perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98]
del rsfmri_path, rsfmri_volume, w_rsfMRI, min_val, max_val, mean_val, med_val, std_val, perc1, perc25, perc75, perc99, perc0_1, perc0_2, perc0_3, perc0_4, perc0_5, perc0_6, perc0_7, perc0_8, perc0_9, perc99_1, perc99_2, perc99_3, perc99_4, perc99_5, perc99_6, perc99_7, perc99_8, perc99_9, perc2, perc3, perc4, perc5, perc95, perc96, perc97, perc98
# ------------------
dmri_imaging_df = pd.DataFrame.from_dict(dmri_imaging_dictionary, orient="index", columns = dictionary_labels)
dmri_imaging_df = pd.DataFrame.from_dict(
dmri_imaging_dictionary, orient="index", columns=dictionary_labels)
dmri_imaging_df.to_pickle('utils/dmri_stats.pkl')
rsfmri_imaging_df = pd.DataFrame.from_dict(rsfmri_imaging_dictionary, orient="index", columns = dictionary_labels)
rsfmri_imaging_df = pd.DataFrame.from_dict(
rsfmri_imaging_dictionary, orient="index", columns=dictionary_labels)
rsfmri_imaging_df.to_pickle('utils/rsfmri_stats.pkl')
......@@ -143,6 +154,7 @@ if __name__ == '__main__':
train_inputs = "dMRI/autoptx_preproc/tractsNormSummed.nii.gz"
train_targets = "fMRI/rfMRI_25.dr/dr_stage2.nii.gz"
database_generator(data_directory, train_inputs, train_targets, rsfmri_mean_mask_path, dmri_mean_mask_path)
database_generator(data_directory, train_inputs, train_targets,
rsfmri_mean_mask_path, dmri_mean_mask_path)
print('---> Finished!')
\ No newline at end of file
print('---> Finished!')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment