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

Conversation

tsalo
Copy link
Member

@tsalo tsalo commented May 12, 2020

Closes #447.

Changes proposed:

  • Keep sub-second timing information in ContentTime when compiling acq_time for scans.tsv files.

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.

@codecov
Copy link

codecov bot commented May 12, 2020

Codecov Report

Merging #451 into master will increase coverage by 1.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #451      +/-   ##
==========================================
+ Coverage   74.99%   76.14%   +1.14%     
==========================================
  Files          35       36       +1     
  Lines        2863     2959      +96     
==========================================
+ Hits         2147     2253     +106     
+ Misses        716      706      -10     
Impacted Files Coverage Δ
heudiconv/tests/test_heuristics.py 100.00% <ø> (ø)
heudiconv/bids.py 82.97% <100.00%> (ø)
heudiconv/tests/test_main.py 100.00% <100.00%> (ø)
heudiconv/tests/test_utils.py 100.00% <100.00%> (ø)
heudiconv/utils.py 90.45% <100.00%> (+0.37%) ⬆️
heudiconv/tests/test_convert.py 100.00% <0.00%> (ø)
heudiconv/convert.py 84.90% <0.00%> (+5.47%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75f2850...c5fe64f. Read the comment docs.

tsalo and others added 3 commits May 12, 2020 16:26
@yarikoptic
Copy link
Member

pushed a little tune up and then decided to check BIDS... heh heh

https://bids-specification.readthedocs.io/en/stable/03-modality-agnostic-files.html#scans-file

Datetime should be expressed in the following format 2009-06-15T13:45:30 (year, month, day, hour 
(24h), minute, second; this is equivalent to the RFC3339 "date-time" format, time zone is always 
assumed as local time). 

and according to https://tools.ietf.org/html/rfc3339 and https://en.wikipedia.org/wiki/ISO_8601 seems sub-second is allowed (phew) BUT also wikipedia says However, the number of decimal places needs to be agreed to by the communicating parties. For example, in Microsoft SQL Server, the precision of a decimal fraction is 3, i.e., "yyyy-mm-ddThh:mm:ss[.mmm]".

So I am afraid that

  • we need to submit a PR to bids-specification suggesting allowing .[mmmmmm] before we could change this column formatting. (takers?)
  • but meanwhile we could just add a new one, e.g. acq_time_precise or alike. (I will push a commit or two for that here now while at it)

@yarikoptic
Copy link
Member

I am not yet sure if I like it but here it was pushed. @tsalo could you please raise a question or a PR with bids-specification about .microseconds? ;)

@tsalo
Copy link
Member Author

tsalo commented May 13, 2020

@yarikoptic My bad, I should have reviewed the specification before opening the issue/PR. I've opened bids-standard/bids-specification#469, so we'll see if we can get microseconds supported.

That allows to remove code duplication of header column names
@yarikoptic
Copy link
Member

Since BIDS community is so receptive to the change, may be we could just proceed with subsecond in acq_time (and later update BIDSVersion we claim to be compatible with whenever that gets released) ! Meanwhile I had paid tribute to my laziness in the last commit I did last night -- and split it now into two, so we could just drop the last one which introduces acq_time_precise if we decide to go that route ;)

@yarikoptic
Copy link
Member

So, @tsalo -- should I just drop the last commit and let's proceed with new improved acq_time? ;-)

@tsalo
Copy link
Member Author

tsalo commented May 19, 2020

@yarikoptic That sounds good to me!

@yarikoptic
Copy link
Member

ok, done. For the record -- pushed _abandoned_acq_time_precise tag with that abandoned now commit into our fork on https://github.com/dbic/heudiconv

@tsalo
Copy link
Member Author

tsalo commented May 27, 2020

Now that bids-standard/bids-specification#470 is merged, can we merge this or should we wait for the validator (https://github.com/bids-standard/bids-validator/issues/957)?

@yarikoptic
Copy link
Member

oh, we definitely should merge ;)

@yarikoptic yarikoptic merged commit ec53e59 into nipy:master May 28, 2020
@tsalo tsalo deleted the enh/retain-subsecond branch October 26, 2020 18:04
@yarikoptic yarikoptic added this to the 0.9.0 milestone Dec 23, 2020
yarikoptic added a commit that referenced this pull request Dec 23, 2020
Various improvements and compatibility/support (dcm2niix, datalad,
duecredit) changes.  Major change is placement of output files to the
target output directory during conversion.

- #454 zenodo referencing in README.rst and support for ducredit for
  heudiconv and reproin heuristic
- #445 more tutorial references in README.md

- [#485][] placed files during conversion right away into the target
  directory (with a `_heudiconv???` suffix, renamed into ultimate target
  name later on), which avoids hitting file size limits of /tmp ([#481][]) and
  helped to avoid a regression in dcm2nixx 1.0.20201102
- #477 replaced `rec-<magnitude|phase>` with `part-<mag|phase>` now
  that BIDS supports the part entity
- #473 made default for CogAtlasID to be a TODO URL
- #459 made AcquisitionTime used for acq_time scans file field
- #451 retained sub-second resolution in scans files
- #442 refactored code so there is now heudiconv.main.workflow for
  more convenient use as a Python module

- minimal version of nipype set to 1.2.3 to guarantee correct handling
  of DWI files ([#480][])
- `heudiconvDCM*` temporary directories are removed now ([#462][])
- compatibility with DataLad 0.13 ([#464][])

- #443 pathlib as a dependency (we are Python3 only now)

* tag 'v0.9.0':
  Add a helper rule to upload to pypi
  update changelog reference as part of prep release
  [DATALAD RUNCMD] prepare the release
  CHANGELOG entry for 0.9.0
yarikoptic added a commit that referenced this pull request Dec 23, 2020
Various improvements and compatibility/support (dcm2niix, datalad,
duecredit) changes.  Major change is placement of output files to the
target output directory during conversion.

- #454 zenodo referencing in README.rst and support for ducredit for
  heudiconv and reproin heuristic
- #445 more tutorial references in README.md

- [#485][] placed files during conversion right away into the target
  directory (with a `_heudiconv???` suffix, renamed into ultimate target
  name later on), which avoids hitting file size limits of /tmp ([#481][]) and
  helped to avoid a regression in dcm2nixx 1.0.20201102
- #477 replaced `rec-<magnitude|phase>` with `part-<mag|phase>` now
  that BIDS supports the part entity
- #473 made default for CogAtlasID to be a TODO URL
- #459 made AcquisitionTime used for acq_time scans file field
- #451 retained sub-second resolution in scans files
- #442 refactored code so there is now heudiconv.main.workflow for
  more convenient use as a Python module

- minimal version of nipype set to 1.2.3 to guarantee correct handling
  of DWI files ([#480][])
- `heudiconvDCM*` temporary directories are removed now ([#462][])
- compatibility with DataLad 0.13 ([#464][])

- #443 pathlib as a dependency (we are Python3 only now)

* tag 'v0.9.0':
  Do no bother ensuring that version changed - should be no changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Retain sub-second resolution in acq_time column of scans tsv files
2 participants