Skip to content

Commit ab58494

Browse files
committed
Merge remote-tracking branch 'origin/master' into enh-citation
* origin/master: (40 commits) Replace ContentDate with AcquisitionDate ENH: seed datalad RNGs in "compare-versions" run to get the same UUIDs BF+RF: centralize min datalad version specification within info.py RF: DataLad 0.13 compat fixes - use .save instead of .add for datalad; do not use .repo.repo Fix test truth. Small commit to trigger CI. Use AcquisitionTime instead of ContentTime. RF: do not sys.exit(0) - just return from main upon queueing up conversion BF: do interpolate the string msg in the exception Remove datalad comment. Try a different approach for the circularity issue. Drop circularity fix to test CI. Revert 59430c0. Drop kwarg-only to test CI. Add docstrings. RF: centralize definition of columns in the _scans files Fix circular variable assignment. Disable positional arguments in workflow. ENH: make get_datetime accept microseconds kwarg to not provide microseconds RF(TST): remove one-time use variables - oneliner is much easier to grasp in such tests IMHO ...
2 parents 259b529 + d855f64 commit ab58494

File tree

11 files changed

+595
-393
lines changed

11 files changed

+595
-393
lines changed

heudiconv/bids.py

Lines changed: 20 additions & 20 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
@@ -403,12 +404,11 @@ def get_formatted_scans_key_row(dcm_fn):
403404
"""
404405
dcm_data = dcm.read_file(dcm_fn, stop_before_pixels=True, force=True)
405406
# 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
407408
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)
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)