# HG changeset patch # User greg # Date 1512047410 18000 # Node ID 6e7ed2b633dccc79609b48ff12953e6892125f52 # Parent c1fba91da909e8e202247f8c8d64fdc5681e3799 Uploaded diff -r c1fba91da909 -r 6e7ed2b633dc dmri.py --- a/dmri.py Thu Nov 30 08:10:04 2017 -0500 +++ b/dmri.py Thu Nov 30 08:10:10 2017 -0500 @@ -13,22 +13,37 @@ parser = argparse.ArgumentParser() parser.add_argument('--drmi_dataset', dest='drmi_dataset', help='Input dataset') parser.add_argument('--output_nifti1', dest='output_nifti1', help='Output Nifti1 dataset') +parser.add_argument('--output_nifti1_extra_files', dest='output_nifti1_extra_files', help='Output Nifti1 extra files') parser.add_argument('--output_png', dest='output_png', help='Output dataset') args = parser.parse_args() +def move_directory_files(source_dir, destination_dir, copy=False, remove_source_dir=False): + source_directory = os.path.abspath(source_dir) + destination_directory = os.path.abspath(destination_dir) + if not os.path.isdir(destination_directory): + os.makedirs(destination_directory) + for dir_entry in os.listdir(source_directory): + source_entry = os.path.join(source_directory, dir_entry) + if copy: + shutil.copy(source_entry, destination_directory) + else: + shutil.move(source_entry, destination_directory) + if remove_source_dir: + os.rmdir(source_directory) + # Get input data. input_dir = args.drmi_dataset -if input_dir == 'sherbrooke_3shell': +if input_dir == 'stanford_hardi': + fetch_stanford_hardi() + fdwi = os.path.join(input_dir, 'HARDI150.nii.gz') + fbval = os.path.join(input_dir, 'HARDI150.bval') + fbvec = os.path.join(input_dir, 'HARDI150.bvec') +elif input_dir == 'sherbrooke_3shell': fetch_sherbrooke_3shell() fdwi = os.path.join(input_dir, 'HARDI193.nii.gz') fbval = os.path.join(input_dir, 'HARDI193.bval') fbvec = os.path.join(input_dir, 'HARDI193.bvec') -elif input_dir == 'stanford_hardi': - fetch_stanford_hardi() - fdwi = os.path.join(input_dir, 'HARDI150.nii.gz') - fbval = os.path.join(input_dir, 'HARDI150.bval') - fbvec = os.path.join(input_dir, 'HARDI150.bvec') # Load the dMRI datasets. img = nibabel.load(fdwi) data = img.get_data() @@ -52,3 +67,5 @@ # Save this in a new Nifti file. nibabel.save(nibabel.Nifti1Image(S0s, img.affine), 'output.nii') shutil.move('output.nii', args.output_nifti1) +# Move the entire contents of input_dir to output_nifti1_extra_files. +move_directory_files(input_dir, args.output_nifti1_extra_files)