@@ -111,17 +111,21 @@ def batch_proc(study_img_dir: str,
111111 * Corresponding list of bval files.
112112 * Corresponding list of bvec files.
113113 '''
114+ study_img_dir : str = os .path .abspath (study_img_dir )
115+
114116 # Check dependencies
115117 dcm2niix_cmd : Command = Command ("dcm2niix" )
116118 dcm2niix_cmd .check_dependency (path_envs = path_envs )
117119
118120 # Write logs
119121 misc_dir : str = os .path .join (out_dir ,'.misc' )
120122 if os .path .exists (misc_dir ):
123+ out_dir : str = os .path .abspath (out_dir )
121124 misc_dir : str = os .path .abspath (misc_dir )
122125 else :
123126 os .makedirs (misc_dir )
124127 misc_dir : str = os .path .abspath (misc_dir )
128+ out_dir : str = os .path .abspath (out_dir )
125129
126130 now = datetime .now ()
127131 dt_string : str = str (now .strftime ("%m_%d_%Y_%H_%M" ))
@@ -786,7 +790,7 @@ def source_to_bids(sub_data: SubDataInfo,
786790 # Using TmpDir and TmpFile context managers
787791 with TmpDir (tmp_dir = sub_tmp ,use_cwd = False ) as tmp :
788792 with TmpDir .TmpFile (tmp_dir = tmp .tmp_dir ) as f :
789- _ = tmp .mk_tmp_dir ()
793+ tmp .mk_tmp_dir ()
790794 [_path , basename , _ext ] = f .file_parts ()
791795 try :
792796 img_data = convert_image_data (file = data ,
@@ -904,7 +908,7 @@ def source_to_bids(sub_data: SubDataInfo,
904908 append_dwi_info = append_dwi_info ,
905909 zero_pad = zero_pad ,
906910 cprss_lvl = cprss_lvl )
907- _ = tmp .rm_tmp_dir ()
911+ tmp .rm_tmp_dir ()
908912 return (imgs ,
909913 jsons ,
910914 bvals ,
@@ -929,7 +933,7 @@ def source_to_bids(sub_data: SubDataInfo,
929933 append_dwi_info = append_dwi_info ,
930934 zero_pad = zero_pad ,
931935 cprss_lvl = cprss_lvl )
932- _ = tmp .rm_tmp_dir ()
936+ tmp .rm_tmp_dir ()
933937 return (imgs ,
934938 jsons ,
935939 bvals ,
@@ -991,13 +995,13 @@ def source_to_bids(sub_data: SubDataInfo,
991995 else :
992996 bvecs .append ("" )
993997 # Clean-up
994- _ = tmp .rm_tmp_dir ()
998+ tmp .rm_tmp_dir ()
995999 return (imgs ,
9961000 jsons ,
9971001 bvals ,
9981002 bvecs )
9991003 except ConversionError :
1000- _ = tmp .rm_tmp_dir ()
1004+ tmp .rm_tmp_dir ()
10011005 return ["" ],["" ],["" ],["" ]
10021006
10031007def nifti_to_bids (sub_data : SubDataInfo ,
@@ -1075,7 +1079,7 @@ def nifti_to_bids(sub_data: SubDataInfo,
10751079
10761080 # Use TmpDir and NiiFile class context managers
10771081 with TmpDir (tmp_dir = sub_tmp , use_cwd = False ) as tmp :
1078- _ = tmp .mk_tmp_dir ()
1082+ tmp .mk_tmp_dir ()
10791083 with NiiFile (data ) as n :
10801084 [path , basename , ext ] = n .file_parts ()
10811085 img_files : List [str ] = glob .glob (os .path .join (path ,basename + "*" + ext ))
@@ -1270,7 +1274,7 @@ def nifti_to_bids(sub_data: SubDataInfo,
12701274 bvals .append ("" )
12711275 bvecs .append ("" )
12721276 # Clean-up
1273- _ = tmp .rm_tmp_dir ()
1277+ tmp .rm_tmp_dir ()
12741278
12751279 return (imgs ,
12761280 jsons ,
@@ -1401,7 +1405,7 @@ def bids_ignore(out_dir: str) -> str:
14011405
14021406 # Write to file using File class context manager
14031407 with File (new_file ) as f :
1404- f .write_txt (".misc \n " )
1408+ f .write_txt (".misc/* \n " )
14051409 f .write_txt ("unknown/* \n " )
14061410
14071411 return new_file
@@ -1426,9 +1430,68 @@ def log_file(log: str) -> LogFile:
14261430 log : LogFile = LogFile (log_file = log )
14271431
14281432 now = datetime .now ()
1429- dt_string = now .strftime ("%A %B %d, %Y %H:%M% :%S" )
1433+ dt_string = now .strftime ("%A %B %d, %Y %H:%M:%S" )
14301434
14311435 log .info (dt_string )
14321436 log .info (f"convert_source v{ __version__ } " )
14331437
14341438 return log
1439+
1440+ # This function was added for the Mac OS X case in which hidden
1441+ # temporary indexing files are present throughout a given directory.
1442+ #
1443+ # This function was designed to handle that use case, however:
1444+ #
1445+ # * Implementation methods are currently unclear
1446+ # * This approach is VERY SLOW as each parent directory is recursively searched.
1447+ #
1448+ # Moreover, this should be included in a later release should this continue to be an
1449+ # issue moving forward.
1450+ #
1451+ # Adebayo Braimah - 12 March 2021
1452+ #
1453+ # def dir_clean_up(directory: str) -> str:
1454+ # '''Removes temporary indexing files (commonly found on
1455+ # Mac OS X).
1456+ #
1457+ # These files are generally problematic as they cause several of
1458+ # ``convert_source``'s core functions to behave unpredictably.
1459+ #
1460+ # Any identified tempoary indexing files are removed.
1461+ #
1462+ # NOTE: The implementation here does work, but is VERY SLOW as the number of
1463+ # files and directories is assumed to be large.
1464+ #
1465+ # Usage example:
1466+ # >>> directory = dir_clean_up(directory)
1467+ # >>>
1468+ #
1469+ # Arguments:
1470+ # directory: Input parent directory to recursively search (for hidden files in).
1471+ #
1472+ # Returns:
1473+ # Absolute path to directory as a string.
1474+ # '''
1475+ # from shutil import rmtree
1476+ #
1477+ # if os.path.exists(directory):
1478+ # directory = os.path.abspath(directory)
1479+ # else:
1480+ # raise FileNotFoundError("Input directory does not appear to exist.")
1481+ #
1482+ # # This works - but is slow | O(n) space and time
1483+ # for root,dirnames,filenames in os.walk(directory):
1484+ # if len(dirnames) > 0:
1485+ # for dirname in dirnames:
1486+ # if '._' in dirname:
1487+ # hd_name: str = os.path.join(root,dirname)
1488+ # rmtree(hd_name)
1489+ # print(hd_name)
1490+ # if len(filenames) > 0:
1491+ # for file in filenames:
1492+ # if '._' in file:
1493+ # hf_name: str = os.path.join(root,file)
1494+ # # hf_list.append(hf_name)
1495+ # os.remove(hf_name)
1496+ # print(hf_name)
1497+ # return directory
0 commit comments