Commit 590e1b32 authored by Andrei Roibu's avatar Andrei Roibu
Browse files

formated code

parent afffad8e
......@@ -30,9 +30,11 @@ def mean_calculator(data_directory, mean_type='dMRI'):
mean_type (str): String flag indicating which data type the algorithm should compute the mean for.
"""
subDirectoryList, number_of_subjects = directory_reader(os.path.join(os.path.expanduser("~"), data_directory))
subDirectoryList, number_of_subjects = directory_reader(
os.path.join(os.path.expanduser("~"), data_directory))
subject_number = len(os.listdir(os.path.join(os.path.expanduser("~"), data_directory)))
subject_number = len(os.listdir(os.path.join(
os.path.expanduser("~"), data_directory)))
volume_sum = None
counter = None
......@@ -46,11 +48,12 @@ def mean_calculator(data_directory, mean_type='dMRI'):
else:
raise ValueError('mean_type can be either dMRI or fMRI!')
subject_path = os.path.join(os.path.expanduser("~"), data_directory, directory, data_path)
subject_path = os.path.join(os.path.expanduser(
"~"), data_directory, directory, data_path)
if mean_type == 'dMRI':
volume = Image(subject_path).data
else:
volume = Image(subject_path).data[:,:,:,0]
volume = Image(subject_path).data[:, :, :, 0]
if volume_sum is None:
volume_sum = np.zeros(volume.shape)
......@@ -64,7 +67,8 @@ def mean_calculator(data_directory, mean_type='dMRI'):
volume_sum = np.add(volume_sum, volume)
counter += 1
print("Added volume {}/{}, --{}%".format(counter, subject_number, counter/subject_number*100))
print("Added volume {}/{}, --{}%".format(counter,
subject_number, counter/subject_number*100))
volume_mean = np.divide(volume_sum, counter)
......@@ -72,10 +76,14 @@ def mean_calculator(data_directory, mean_type='dMRI'):
if mean_type == 'dMRI':
volume_mean_image.save('utils/mean_tractsNormSummed.nii.gz')
volume_mean_donwsampled, xform = resampleToPixdims(Image('utils/mean_tractsNormSummed.nii.gz'), (2,2,2))
header_downsampled = Image(volume_mean_donwsampled, header=Image('utils/mean_tractsNormSummed.nii.gz').header, xform=xform).header
volume_mean_downsampled_image = Image(volume_mean_donwsampled, header=header_downsampled)
volume_mean_downsampled_image.save('utils/mean_tractsNormSummed_downsampled.nii.gz')
volume_mean_donwsampled, xform = resampleToPixdims(
Image('utils/mean_tractsNormSummed.nii.gz'), (2, 2, 2))
header_downsampled = Image(volume_mean_donwsampled, header=Image(
'utils/mean_tractsNormSummed.nii.gz').header, xform=xform).header
volume_mean_downsampled_image = Image(
volume_mean_donwsampled, header=header_downsampled)
volume_mean_downsampled_image.save(
'utils/mean_tractsNormSummed_downsampled.nii.gz')
else:
volume_mean_image.save('utils/mean_dr_stage2.nii.gz')
......@@ -85,4 +93,4 @@ if __name__ == '__main__':
mean_type = 'dMRI'
# mean_type = 'fMRI'
mean_calculator(data_directory, mean_type)
\ No newline at end of file
mean_calculator(data_directory, mean_type)
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