nipreps / sdcflows

Susceptibility Distortion Correction (SDC) workflows for EPI MR schemes
https://www.nipreps.org/sdcflows
Apache License 2.0
32 stars 26 forks source link

Draft MEDIC dynamic distortion correction method (second attempt) #438

Open tsalo opened 6 months ago

tsalo commented 6 months ago

Closes #36. An alternative to #435 that installs MEDIC as a dependency instead of implementing the whole tool as a series of interfaces and workflows.

Changes proposed:

tsalo commented 6 months ago

I cannot figure out how to get the FieldmapWrangler to find MEDIC-style setups (i.e., complex-valued, multi-echo BOLD scans). 😕

effigies commented 1 month ago

@tsalo Around L508 in your current wrangler.py, I think you want to do something like:

        medic_entities = {**base_entities, **{'part': 'mag'}}
        has_magnitude = tuple()
        with suppress(ValueError):
            has_magnitude = layout.get(
                suffix='bold',
                **medic_entities,
            )
        for mag_img in has_magnitude:
            phase_img = layout.get(**{**mag_img.get_entities(), **{'part': 'phase'}})
            if not phase_img:
                continue
            phase_img = phase_img[
            try:
                e = fm.FieldmapEstimation(
                    [
                        fm.FieldmapFile(mag_img.path, metadata=mag_img.get_metadata()),
                        fm.FieldmapFile(phase_img.path, metadata=phase_img.get_metadata()),
                    ]
                )
            except (ValueError, TypeError) as err:
                _log_debug_estimator_fail(
                    logger, "potential MEDIC fieldmap", [mag_img, phase_img], layout.root, str(err)
                )
            else:
                _log_debug_estimation(logger, e, layout.root)
                estimators.append(e)
codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 60.17699% with 45 lines in your changes missing coverage. Please review.

Project coverage is 78.25%. Comparing base (656a51d) to head (1ba3e94).

Files with missing lines Patch % Lines
sdcflows/workflows/fit/medic.py 28.00% 18 Missing :warning:
sdcflows/utils/phasemanip.py 6.66% 14 Missing :warning:
sdcflows/interfaces/fmap.py 74.28% 9 Missing :warning:
sdcflows/fieldmaps.py 90.47% 1 Missing and 1 partial :warning:
sdcflows/utils/wrangler.py 88.23% 2 Missing :warning:

:exclamation: There is a different number of reports uploaded between BASE (656a51d) and HEAD (1ba3e94). Click for more details.

HEAD has 18 uploads less than BASE | Flag | BASE (656a51d) | HEAD (1ba3e94) | |------|------|------| ||24|6|
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #438 +/- ## ========================================== - Coverage 83.75% 78.25% -5.50% ========================================== Files 32 33 +1 Lines 2831 2943 +112 Branches 381 294 -87 ========================================== - Hits 2371 2303 -68 - Misses 390 582 +192 + Partials 70 58 -12 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tsalo commented 1 month ago

Thanks @effigies!

tsalo commented 1 month ago

I created a MEDIC-compliant test dataset (dsD), but it seems like the tests in test_wrangler use skeletons. Should I drop the test dataset and just generate a skeleton in the test file?

effigies commented 1 month ago

Should I drop the test dataset and just generate a skeleton in the test file?

Yeah, seems like a good idea.

tsalo commented 1 month ago

@effigies I finally got the tests passing. Do you know what my next steps should be?