Skip to content

Commit 54d8672

Browse files
committed
Merge remote-tracking branch 'nipy/master' into enh/acqtime
# Conflicts: # heudiconv/bids.py
2 parents e3868e5 + f4c2dd2 commit 54d8672

File tree

7 files changed

+574
-376
lines changed

7 files changed

+574
-376
lines changed

heudiconv/bids.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,24 @@
2121
json_dumps_pretty,
2222
set_readonly,
2323
is_readonly,
24+
get_datetime,
2425
)
2526

2627
lgr = logging.getLogger(__name__)
2728

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+
])
2842

2943
class BIDSError(Exception):
3044
pass
@@ -359,22 +373,9 @@ def add_rows_to_scans_keys_file(fn, newrows):
359373
# _scans.tsv). This auto generation will make BIDS-validator happy.
360374
scans_json = '.'.join(fn.split('.')[:-1] + ['json'])
361375
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)
376377

377-
header = ['filename', 'acq_time', 'operator', 'randstr']
378+
header = SCANS_FILE_FIELDS
378379
# prepare all the data rows
379380
data_rows = [[k] + v for k, v in fnames2info.items()]
380381
# sort by the date/filename
@@ -406,9 +407,8 @@ def get_formatted_scans_key_row(dcm_fn):
406407
# parse date and time and get it into isoformat
407408
try:
408409
date = dcm_data.ContentDate
409-
time = dcm_data.AcquisitionTime.split('.')[0]
410-
td = time + date
411-
acq_time = datetime.strptime(td, '%H%M%S%Y%m%d').isoformat()
410+
time = dcm_data.AcquisitionTime
411+
acq_time = get_datetime(date, time)
412412
except (AttributeError, ValueError) as exc:
413413
lgr.warning("Failed to get date/time for the content: %s", str(exc))
414414
acq_time = ''

0 commit comments

Comments
 (0)