-
Notifications
You must be signed in to change notification settings - Fork 126
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
Add support for a custom seqinfo to extract from DICOMs any additional metadata desired for a heuristic #581
Conversation
That's way better than what I had PR-ed years back and should perfectly fit our needs. |
This will also work for me. Thanks for the PR! |
I finally tested the PR. I think that |
@yarikoptic - perhaps the return from i would suggest decoupling anonymity from this though, since any custom return could potentially return things that are identifiable. i would leave that part to heuristic developers. |
ATM it indeed can be anything (e.g. that tuple in the convertall example. But indeed it would then be a single field Indeed we could make it return a dict to formalize such extension, but I don't think we would be able to "dynamically" expand that seqinfo_fields list of fields defined at the module level https://github.com/nipy/heudiconv/pull/581/files#diff-2aa4d95adec423a8c619a45d9676cb573bfdcbdb53d84af3d815ec34aee99d75R27 . Pairing with aforementioned round trip we might though consider it to be limited to a data structure serializable through
as far as I see it -- it is "decoupled" in a sense "it doesn't care". What did you have in mind? |
c939bf8
to
00f8b56
Compare
00f8b56
to
de1a470
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #581 +/- ##
==========================================
- Coverage 82.05% 82.04% -0.01%
==========================================
Files 41 42 +1
Lines 4173 4205 +32
==========================================
+ Hits 3424 3450 +26
- Misses 749 755 +6 ☔ View full report in Codecov by Sentry. |
heudiconv/dicoms.py
Outdated
hash(custom_seqinfo_data) | ||
except TypeError: | ||
raise RuntimeError("Data returned by the heuristics custom_seqinfo is not hashable. " | ||
"See https://heudiconv.readthedocs.io/en/latest/heuristics.html#custom_seqinfo for more details.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bpinsard so WDYT about adding some check for roundtrip serialization into/from .tsv? a "weaker" alternative could be to test for presence of \t
or \n
symbols which might break it, or they wouldn't ?
apparently we did not add any test yet here, should have that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any part of heudiconv that might load the dicominfo*.tsv
that get written in .heudiconv
, in a second run with overwrite for instance?
For now it convert custom
values to a str, eg. when using frozendict for hashable dict:
frozendict.frozendict({'patient_name': 'p02_ana012', 'pe_dir': 'ROW', 'pe_dir_pos': 1, 'body_part': 'BRAIN', 'scan_options': "['IR', 'WE']", 'image_comments': '', 'slice_orient': 'Sag', 'echo_number': 'None', 'rescale_slope': None, 'receive_coil': 'HC1-7;NC1,2', 'image_history': 'ChannelMixing:ND=true_CMM=1_CDM=1;ACCAlgo:9', 'ice_dims': 'X_1_1_1_1_1_4_1_1_1_1_1_35'})
So not necessarily easily unserializable depending on what the custom_seqinfo is returning.
the main intent is to give access to other fields in the dicom file as part of the heuristic. the only reason the tsv file existed is because that was produced by one of the early conversion tools we used, and acted as a cache between having to read all the dicom files and the heuristic. it is also the reason it had weird unused fields. one could read a lot of dicom files very quickly now, much quicker than the original dicomconvert.py script :)
you could add |
0557786
to
0eb836c
Compare
Happy new year! |
eh, we need to update (resolve conflicts) and follow original description to add tests |
7d3b287
to
df4e0bf
Compare
44f1339
to
3cc6fd3
Compare
…itrary value Just a draft implementation
…itrary value Just a draft implementation
…c with custom_seqinfo
…t -- I think mypy has deficiency since we do use kwargs and thus should be ok
f245f64
to
41b22d7
Compare
🚀 PR was released in |
🚀 PR was released in |
Fantastic ! Many thanks ! |
Getting back to #333 (attn @bpinsard ) and recent #580 (attn @kcho) decided may be to add to the army of custom ad-hoc callbacks etc heuristics could provide. So, WDYT if heuristic could provide
custom_seqinfo
callable (crude example is below in PR) where any information could be extracted from already loaded nibabel's dicom wrapper or just a full list of files for that sequence. I think it would be a slightly better solution to #333 since would not always store potentially sensitive path in the extracted metadata record and potentially could operate on already loaded DICOM metadata thus making it faster to extract extra metadata.@bpinsard @kcho -- would smth like that work for your cases?
TODOs
replacecompliment hashing check with some more adequate, may be round trip check through json + verification that no\t
is present. if\t
-- kaboom. Add to documentation that\t
must be sanitized, or add such sanitization (and document it)convertall
already got that custom field filled, test should just check if it is there.