@@ -23,6 +23,8 @@ __version__ = '0.2'
23
23
import argparse
24
24
from glob import glob
25
25
import csv
26
+ import dicom as dcm
27
+ import dcmstack as ds
26
28
import inspect
27
29
import json
28
30
import os
@@ -944,27 +946,31 @@ def convert(items, symlink=True, converter=None,
944
946
shutil .rmtree (tmpdir )
945
947
946
948
949
+ def get_formatted_scans_key_row (item , outname_bids_files ):
950
+ dcm_fn = item [- 1 ][0 ]
951
+ mw = ds .wrapper_from_data (dcm .read_file (dcm_fn , stop_before_pixels = True ))
952
+ # we need to store filenames and acquisition times
953
+ # parse date and time and get it into isoformat
954
+ date = mw .dcm_data .AcquisitionDate
955
+ time = mw .dcm_data .AcquisitionTime .split ('.' )[0 ]
956
+ td = time + date
957
+ acq_time = datetime .strptime (td , '%H%M%S%Y%m%d' ).isoformat ()
958
+ # add random string
959
+ randstr = '' .join (map (chr , sample (k = 8 , population = range (33 , 127 ))))
960
+ row = [acq_time , mw .dcm_data .PerformingPhysicianName , randstr ]
961
+ return row
962
+
963
+
947
964
def save_scans_key (items , outname_bids_files ):
948
- import dicom as dcm
949
- import dcmstack as ds
950
965
header = ['filename' , 'acq_time' , 'operator' , 'randstr' ]
951
966
rows = []
967
+ import pdb ; pdb .set_trace ()
952
968
for item , outname_bids_file in zip (items , outname_bids_files ):
953
- dcm_fn = item [- 1 ][0 ]
954
- mw = ds .wrapper_from_data (dcm .read_file (dcm_fn , force = True ))
955
- # we need to store filenames and acquisition times
956
- # parse date and time and get it into isoformat
957
- date = mw .dcm_data .AcquisitionDate
958
- time = mw .dcm_data .AcquisitionTime .split ('.' )[0 ]
959
- td = time + date
960
- acq_time = datetime .strptime (td , '%H%M%S%Y%m%d' ).isoformat ()
961
969
# get filenames
962
970
f_name = '/' .join (outname_bids_file .split ('/' )[- 2 :])
963
971
f_name = f_name .replace ('json' , 'nii.gz' )
964
- # store it
965
- randstr = '' .join (map (chr , sample (k = 8 , population = range (33 , 127 ))))
966
972
rows .append (
967
- ( f_name , acq_time , mw . dcm_data . PerformingPhysicianName , randstr )
973
+ [ f_name ] + get_formatted_scans_key_row ( item , outname_bids_file )
968
974
)
969
975
# where should we store it?
970
976
output_dir = dirname (dirname (outname_bids_file ))
0 commit comments