comparison dmri.py @ 9:cf847e9f1a3a draft

Uploaded
author greg
date Fri, 03 Nov 2017 13:42:38 -0400
parents a0d57df923d2
children 5014ba48e15e
comparison
equal deleted inserted replaced
8:a0d57df923d2 9:cf847e9f1a3a
10 parser.add_argument('--input', dest='input', help='Input dataset') 10 parser.add_argument('--input', dest='input', help='Input dataset')
11 parser.add_argument('--output', dest='output', help='Output dataset') 11 parser.add_argument('--output', dest='output', help='Output dataset')
12 12
13 args = parser.parse_args() 13 args = parser.parse_args()
14 14
15 def move_directory_files(source_dir, destination_dir, copy=False, remove_source_dir=False): 15 input_dir = os.path.join('.dipy', 'sherbrooke_3shell')
16 source_directory = os.path.abspath(source_dir) 16 # Get input data.
17 destination_directory = os.path.abspath(destination_dir) 17 fetch_sherbrooke_3shell()
18 if not os.path.isdir(destination_directory): 18 fdwi = os.path.join(input_dir, 'HARDI193.nii.gz')
19 os.makedirs(destination_directory) 19 fbval = os.path.join(input_dir, 'HARDI193.bval')
20 for dir_entry in os.listdir(source_directory): 20 fbvec = os.path.join(input_dir, 'HARDI193.bvec')
21 source_entry = os.path.join(source_directory, dir_entry)
22 if copy:
23 shutil.copy(source_entry, destination_directory)
24 else:
25 shutil.move(source_entry, destination_directory)
26 if remove_source_dir:
27 os.rmdir(source_directory)
28 source_dir = os.path.abspath(os.path.join('home', 'greg', '.dipy', 'sherbrooke_3shell'))
29 dest_dir = 'input_dir'
30 if not os.path.exists(source_dir):
31 # Get input data.
32 fetch_sherbrooke_3shell()
33 # Move inputs to working directory.
34 move_directory_files(source_dir, dest_dir, copy=True)
35 fdwi = os.path.join(dest_dir, 'HARDI193.nii.gz')
36 fbval = os.path.join(dest_dir, 'HARDI193.bval')
37 fbvec = os.path.join(dest_dir, 'HARDI193.bvec')
38 # Load the dMRI datasets. 21 # Load the dMRI datasets.
39 img = nibabel.load(fdwi) 22 img = nibabel.load(fdwi)
40 data = img.get_data() 23 data = img.get_data()
41 # data is a 4D array where the first 3 dimensions are the i, j, 24 # data is a 4D array where the first 3 dimensions are the i, j,
42 # k voxel coordinates and the last dimension is the number of 25 # k voxel coordinates and the last dimension is the number of