ENH: Add optional warpkit MEDIC support for multi-echo BOLD distortion correction#3645
ENH: Add optional warpkit MEDIC support for multi-echo BOLD distortion correction#3645DVSneuro wants to merge 7 commits intonipreps:masterfrom
Conversation
|
Thanks for opening this pull request! It looks like this is your first time contributing to fMRIPrep. 😄 |
=== Do not change lines below ===
{
"chain": [],
"cmd": "bash -c '! pixi lock --check || git checkout .'",
"exit": 0,
"extra_inputs": [],
"inputs": [
"pixi.lock",
"pyproject.toml"
],
"outputs": [
"pixi.lock"
],
"pwd": "."
}
^^^ Do not change lines above ^^^
|
This is extremely interesting and coincides with some work by @vanandrew in sdcflows (note to self: link PR). I've been meaning to look into how it would integrate and haven't found the time. Have you run datasets with this workflow? Do the results look good to you? Do you have comparisons with other fieldmap types? I will try to look at this in some detail soon. |
|
I've only ran a couple of subjects from our dataset (https://openneuro.org/datasets/ds005123/versions/1.1.3), and here's one example visualization for a single time point, which looks pretty good to me. I haven't compared it directly with standard fieldmaps, though we have those in the dataset above. We were drawn to warpkit/medic since some of our participants move a lot (older adults) and we had a few cases where the participant needed to get out of the scanner for a break but we forgot to get a new fieldmap when they got back in. So, the idea of making the fieldmaps for each frame using the multi-echo phase data was very appealing to us! But when we first started using medic/warpkit a year or so ago, I couldn't figure out how to get it integrated into fmriprep, so we'd generate a fieldmap for the first time point of each run and use that in the normal fmriprep workflow and the results have been good. I'm assuming the framewise implementation should be even better, especially for high-motion participants -- but hopefully I didn't break anything or do anything too silly with this PR! |
|
I got you @effigies: nipreps/sdcflows#541 :) I haven't reviewed @DVSneuro PR yet, but my vague plan was to have MEDIC be called from On the fmriprep side, the biggest changes would need to be in how the field map is applied: in MEDIC, you get a field map for every frame of your scan, so the one step resampling would need to be adjusted to account for this. Given that @DVSneuro has some results, I assume your PR already makes a change like this? Awesome job getting this working btw :). |
|
Thanks @vanandrew ! I had plenty of help from Codex. And yes, this PR does update the fMRIPrep side so a 4D MEDIC fieldmap series is applied volume-by-volume during one-step resampling. The current implementation calls MEDIC directly from fMRIPrep, but I’d be open to trying to restructure that piece if the preferred long-term architecture is to generate the MEDIC estimates in sdcflows and then consume them from fMRIPrep. I'm not seeing any other multi-echo datasets on OpenNeuro that have the phase data, so the testing here has been somewhat limited. |
|
@DVSneuro, I suggest checking https://me-ica.github.io/open-multi-echo-data/. I try to keep it up to date, and you can filter by if there's complex-valued data or not. There are nine on OpenNeuro that I'm aware of:
I think the goal should be to have MEDIC within SDCFlows so that dynamic distortion correction is treated like static distortion correction, though it would be cool if fMRIPrep could use One change that might be necessary on fMRIPrep's side is (optionally?) swapping the order of HMC and SDC when MEDIC is used, since I think dynamic distortion correction should improve motion correction. |
|
For datasets, I've mostly been using this one for my own tests: https://openneuro.org/datasets/ds006926/versions/1.0.0 (was the only public dataset I could find that has both mag/phase). Getting into some of the more technical details:
Side question: I noticed that both nipreps project currently support python version 3.10+, but I've made |
Changes proposed in this pull request
I think this is a little related to #3336 and maybe some other work from @tsalo , but this PR addresses a narrower use case than that issue: optional MEDIC-based susceptibility distortion correction for compatible multi-echo BOLD runs with
part-phasedata, usingwarpkitfollowing the logic from Andrew Van's ( @vanandrew ) preprint on bioRxiv: https://www.biorxiv.org/content/10.1101/2023.11.28.568744v1When
--me-use-warpkitis enabled, fMRIPrep will:part-phasedataMEDIC (warpkit)in the functional summaryThis path is opt-in and does not change default behavior for existing workflows.
Main changes in this PR:
--me-use-warpkitwarpkit.api.medicCurrent scope / limitations:
part-phasecompanionsValidation performed:
warpkitIn the HTML report, warpkit-enabled runs showed:
Susceptibility distortion correction: MEDIC (warpkit)This is my first contribution to fMRIPrep, so I tried to keep the scope focused and follow existing workflow patterns closely.
I used OpenAI Codex to help draft and iterate on portions of the code and tests, and I manually reviewed and tested the resulting changes as carefully as I could, but I wouldn't say I'm an expert on this (maybe a little better than vibe coding, but not by much).
Documentation that should be reviewed
This PR does not add standalone user documentation pages, but it does update user-facing/report-facing text in a few places:
--me-use-warpkit