changeset 28:6e7ed2b633dc draft

Uploaded
author greg
date Thu, 30 Nov 2017 08:10:10 -0500
parents c1fba91da909
children da507620bd74
files dmri.py
diffstat 1 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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)