|
21 | 21 | json_dumps_pretty,
|
22 | 22 | set_readonly,
|
23 | 23 | is_readonly,
|
| 24 | + get_datetime, |
24 | 25 | )
|
25 | 26 |
|
26 | 27 | lgr = logging.getLogger(__name__)
|
27 | 28 |
|
| 29 | +# Fields to be populated in _scans files. Order matters |
| 30 | +SCANS_FILE_FIELDS = OrderedDict([ |
| 31 | + ("filename", OrderedDict([ |
| 32 | + ("Description", "Name of the nifti file")])), |
| 33 | + ("acq_time", OrderedDict([ |
| 34 | + ("LongName", "Acquisition time"), |
| 35 | + ("Description", "Acquisition time of the particular scan")])), |
| 36 | + ("operator", OrderedDict([ |
| 37 | + ("Description", "Name of the operator")])), |
| 38 | + ("randstr", OrderedDict([ |
| 39 | + ("LongName", "Random string"), |
| 40 | + ("Description", "md5 hash of UIDs")])), |
| 41 | +]) |
28 | 42 |
|
29 | 43 | class BIDSError(Exception):
|
30 | 44 | pass
|
@@ -359,22 +373,9 @@ def add_rows_to_scans_keys_file(fn, newrows):
|
359 | 373 | # _scans.tsv). This auto generation will make BIDS-validator happy.
|
360 | 374 | scans_json = '.'.join(fn.split('.')[:-1] + ['json'])
|
361 | 375 | if not op.lexists(scans_json):
|
362 |
| - save_json(scans_json, |
363 |
| - OrderedDict([ |
364 |
| - ("filename", OrderedDict([ |
365 |
| - ("Description", "Name of the nifti file")])), |
366 |
| - ("acq_time", OrderedDict([ |
367 |
| - ("LongName", "Acquisition time"), |
368 |
| - ("Description", "Acquisition time of the particular scan")])), |
369 |
| - ("operator", OrderedDict([ |
370 |
| - ("Description", "Name of the operator")])), |
371 |
| - ("randstr", OrderedDict([ |
372 |
| - ("LongName", "Random string"), |
373 |
| - ("Description", "md5 hash of UIDs")])), |
374 |
| - ]), |
375 |
| - sort_keys=False) |
| 376 | + save_json(scans_json, SCANS_FILE_FIELDS, sort_keys=False) |
376 | 377 |
|
377 |
| - header = ['filename', 'acq_time', 'operator', 'randstr'] |
| 378 | + header = SCANS_FILE_FIELDS |
378 | 379 | # prepare all the data rows
|
379 | 380 | data_rows = [[k] + v for k, v in fnames2info.items()]
|
380 | 381 | # sort by the date/filename
|
@@ -403,12 +404,11 @@ def get_formatted_scans_key_row(dcm_fn):
|
403 | 404 | """
|
404 | 405 | dcm_data = dcm.read_file(dcm_fn, stop_before_pixels=True, force=True)
|
405 | 406 | # we need to store filenames and acquisition times
|
406 |
| - # parse date and time and get it into isoformat |
| 407 | + # parse date and time of start of run acquisition and get it into isoformat |
407 | 408 | try:
|
408 |
| - date = dcm_data.ContentDate |
409 |
| - time = dcm_data.ContentTime.split('.')[0] |
410 |
| - td = time + date |
411 |
| - acq_time = datetime.strptime(td, '%H%M%S%Y%m%d').isoformat() |
| 409 | + date = dcm_data.AcquisitionDate |
| 410 | + time = dcm_data.AcquisitionTime |
| 411 | + acq_time = get_datetime(date, time) |
412 | 412 | except (AttributeError, ValueError) as exc:
|
413 | 413 | lgr.warning("Failed to get date/time for the content: %s", str(exc))
|
414 | 414 | acq_time = ''
|
|
0 commit comments