4242 },
4343 "pd" : {"rule" : "acq" , "iso" : "PD_FS_SPC_COR" },
4444}
45- # [
46- #
47- #
48- #
49- # "PD_FS_SPC_COR",
50- # "3D_GRE_TRA_F",
51- #
52- #
53- #
54- # ]
55-
56-
57- def test_nii (path : Path | str | BIDS_FILE ):
45+
46+
47+ def __test_nii (path : Path | str | BIDS_FILE ):
5848 if isinstance (path , str ):
5949 path = Path (path )
6050 if path .exists ():
@@ -82,7 +72,7 @@ def find_all_broken(path: str = "/DATA/NAS/datasets_processed/NAKO/dataset-nako/
8272 q = subj .new_query (flatten = True )
8373 q .filter_filetype ("nii.gz" )
8474 for f in q .loop_list ():
85- if not test_nii (f ):
75+ if not __test_nii (f ):
8676 print ("BROKEN:" , f )
8777 brocken .append (f )
8878 with open ("broken.pkl" , "wb" ) as w :
@@ -97,8 +87,8 @@ def find_all_broken(path: str = "/DATA/NAS/datasets_processed/NAKO/dataset-nako/
9787)
9888
9989
100- def test_and_replace (out_folder = "/media/data/NAKO/dataset-nako2" ):
101- from TPTBox .core .dicom .dicom_extract import extract_folder
90+ def __test_and_replace (out_folder = "/media/data/NAKO/dataset-nako2" ):
91+ from TPTBox .core .dicom .dicom_extract import extract_dicom_folder
10292
10393 with open ("/run/user/1000/gvfs/smb-share:server=172.21.251.64,share=nas/tools/TPTBox/broken.pkl" , "rb" ) as w :
10494 brocken = pickle .load (w )
@@ -127,7 +117,7 @@ def test_and_replace(out_folder="/media/data/NAKO/dataset-nako2"):
127117 except StopIteration :
128118 continue
129119 if f2 .exists ():
130- out_files .update (extract_folder (f2 , Path (out_folder ), make_subject_chunks = 3 , verbose = False ))
120+ out_files .update (extract_dicom_folder (f2 , Path (out_folder ), make_subject_chunks = 3 , verbose = False ))
131121 else :
132122 print (f , f .exists ())
133123 else :
@@ -140,11 +130,11 @@ def test_and_replace(out_folder="/media/data/NAKO/dataset-nako2"):
140130 print ((source_folder_encrypted / source_folders [mod ][sub_key ]) / (f"{ subj } *.zip" ))
141131 continue
142132 ## Call the extraction
143- out_files = extract_folder (zip_file , Path (out_folder ), make_subject_chunks = 3 , verbose = False )
133+ out_files = extract_dicom_folder (zip_file , Path (out_folder ), make_subject_chunks = 3 , verbose = False )
144134 ## -- Testing ---
145135 # Save over brocken...
146136 for o in out_files .values ():
147- if o is not None and not test_nii (o ):
137+ if o is not None and not __test_nii (o ):
148138 Print_Logger ().on_fail ("Still Broken " , out_files )
149139
150140
@@ -156,7 +146,6 @@ def clean_dicom_data(dcm_data) -> dict:
156146 # raise NoImageError()
157147 else :
158148 del py_dataset .PixelData
159- print (type (py_dataset ))
160149 py_dict = py_dataset .to_json_dict (suppress_invalid_tags = True )
161150 for tag in ["00291010" , "00291020" ]:
162151 if tag in py_dict and "InlineBinary" in py_dict [tag ]:
@@ -204,7 +193,7 @@ def test_name_conflict(json_ob, file):
204193 return False
205194
206195
207- def save_json (json_ob , file ):
196+ def save_json (json_ob , file , check_exist = False ):
208197 """
209198 recieves a json object and a path and saves the object as a json file
210199 """
@@ -214,7 +203,7 @@ def convert(obj):
214203 return int (obj )
215204 raise TypeError
216205
217- if test_name_conflict (json_ob , file ):
206+ if check_exist and test_name_conflict (json_ob , file ):
218207 raise FileExistsError (file )
219208 if Path (file ).exists ():
220209 return True
@@ -229,7 +218,7 @@ def load_json(file):
229218
230219
231220if __name__ == "__main__" :
232- test_and_replace ()
221+ __test_and_replace ()
233222 # find_all_broken()
234223 # test_and_replace(
235224 # "/DATA/NAS/datasets_processed/NAKO/dataset-nako/rawdata/101/101776/mevibe/sub-101776_sequ-94_acq-ax_part-eco0-opp1_mevibe.nii.gz",
0 commit comments