Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Retain sub-second resolution in scans files #451

Merged
merged 9 commits into from
May 28, 2020
6 changes: 3 additions & 3 deletions heudiconv/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ def get_formatted_scans_key_row(dcm_fn):
# parse date and time and get it into isoformat
try:
date = dcm_data.ContentDate
time = dcm_data.ContentTime.split('.')[0]
td = time + date
acq_time = datetime.strptime(td, '%H%M%S%Y%m%d').isoformat()
time = dcm_data.ContentTime
td = time + ':' + date
acq_time = datetime.strptime(td, '%H%M%S.%f:%Y%m%d').isoformat()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is .%f guaranteed to be present (above code would work without)? I wonder if there should be a check for '.' to be found in td?
If you could while at it place it into an auxiliary function and give it a dedicated tiny unittest - would be awesome... but if not -- that is ok ;) just feels like worthwhile

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Just added a new function in utils, as well as a test for it.

except (AttributeError, ValueError) as exc:
lgr.warning("Failed to get date/time for the content: %s", str(exc))
acq_time = ''
Expand Down
2 changes: 1 addition & 1 deletion heudiconv/tests/test_heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_scans_keys_reproin(tmpdir, invocation):
if i != 0:
assert(os.path.exists(pjoin(dirname(scans_keys[0]), row[0])))
assert(re.match(
'^[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}:[\d]{2}:[\d]{2}$',
'^[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}:[\d]{2}:[\d]{2}.\d]{6}$',
row[1]))


Expand Down
2 changes: 1 addition & 1 deletion heudiconv/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_get_formatted_scans_key_row():

row1 = get_formatted_scans_key_row(dcm_fn)
assert len(row1) == 3
assert row1[0] == '2016-10-14T09:26:36'
assert row1[0] == '2016-10-14T09:26:36.693000'
assert row1[1] == 'n/a'
prandstr1 = row1[2]

Expand Down