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] Proposition for adni_fmap renaming function #1175

Closed
wants to merge 2 commits into from

Conversation

AliceJoubert
Copy link
Contributor

@AliceJoubert AliceJoubert commented May 7, 2024

Refactor of adni_fmap.py following issue #1174 .

It mainly tackles the renaming of the files after using dcm2nix to convert the files. I chose the easy way ie relying on what dcm2nix outputs to rename the files but that can be discussed.

@AliceJoubert AliceJoubert added enhancement New feature or request converter labels May 7, 2024
@AliceJoubert AliceJoubert self-assigned this May 7, 2024
if "fmap" in file_path.name:
with open(file_path, "r") as f:
file_json = json.load(f)
if "BidsGuess" in file_json:
Copy link
Member

Choose a reason for hiding this comment

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

We can discuss that next week, but I have some concerns with this approach.
I haven't had time to look closely at the PR, but looking at this: https://github.com/rordenlab/dcm2niix/blob/master/BidsGuess/README.md?plain=1, it seems like BidsGuess is quite recent and still experimental.

If I understand correctly, this means that users with a dcm2niix older than v1.0.20230731 (quite recent) will get an error at this point.

Also, I was a bit concerned by sections of the README linked above like "Therefore, it is unable to resolve fieldmap...". Might be outdated, but still a bit concerning...

I'm not saying that we shouldn't use this option, but I think we should have a backup way in case things go wrong or the user's version of dcm2niix is not recent enough.

WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only use 'BidsGuess' to determine what type of image I have (phase diff, magnitude, echo), without having to make the checks myself and from what I have read and tested it seems to work well !

However, I agree there should be another option if the field 'BidsGuess' does not appear in the .json files anyway. I will work on this next week, based on what was proposed by @tharpm95 and https://bids-specification.readthedocs.io/en/stable/modality-specific-files/magnetic-resonance-imaging-data.html#types-of-fieldmaps.

This way, both options will be available. What do you think ?

Copy link

@likeajumprope likeajumprope May 8, 2024

Choose a reason for hiding this comment

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

Hi all, apologies for just jumping in - I have run the dev branch with the new fieldmaps conversion feature over three subjects. We had a short discussion about the "BidsGuess" in my team as well, but eventually we are planning to use the output of the converter for fmriprep and we would need an "IntendedFor" key. Would it be possible to add that?

Copy link

@likeajumprope likeajumprope May 8, 2024

Choose a reason for hiding this comment

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

Second, I had to make some (small) adjustments to get the fieldmap conversion to run (some fieldmap file extensions were not included) - I might open a small PR --> #1177

Choose a reason for hiding this comment

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

Third, when running the new dev branch over my three tests subjects, I am left with a tmp folder (clinica, terminates, no errors):
image

any clue what that means?

I am also happy to investigate, but just wanted to let you know.

Copy link
Contributor

Choose a reason for hiding this comment

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

Commenting here to confirm I've also had the tmp_dcm issue. I had the code to remove those automatically which I think we decided to remove during the merge. It could likely be reintegrated into the more robust for loop to remove these files, or added somewhere else in adni_utils.py

Copy link
Member

Choose a reason for hiding this comment

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

Hi all,

The issue with the tmp_dcm folder which is not removed is caused by the function create_file (in adni_utils.py) returning early.

More precisely, the flag nifti_exists is very often set to False because the converted image does not have the expected name. This causes the function to warn and return early:

if not nifti_exists or not dwi_bvec_and_bval_exist:
cprint(
msg=f"Conversion with dcm2niix failed for subject {subject} and session {session}",
lvl="warning",
)
return np.nan

Such that the following line is not executed:

# Check if there is still the folder tmp_dcm_folder and remove it
remove_tmp_dmc_folder(bids_dir, image_id)

For example, the expected file

"sub-ADNI941S6471/ses-M024/fmap/sub-ADNI941S6471_ses-M024_fmap.nii.gz"

does not exist, but

"sub-ADNI941S6471/ses-M024/fmap/sub-ADNI941S6471_ses-M024_fmap_e2.nii.gz"

does.

A quick and dirty way around this, would be to modify the nifti_exists flag to take fmap specificities into account. Something like this maybe:

if modality == "fmap":
    nifti_exists = (
        nifti_exists
        or file_without_extension.with_name(f"{file_without_extension.name}_e2.nii.gz").is_file()
        or file_without_extension.with_name(f"{file_without_extension.name}_e2_ph.nii.gz").is_file()
    )

@likeajumprope the converter explicitly delete images that have "real" and "imaginary" suffixes added by dcm2niix:

# Removing images with unsupported suffixes if generated by dcm2niix
for suffix in ("ADC", "real", "imaginary"):
file_with_bad_suffix = output_path / f"{output_filename}_{suffix}"
if any(
[

I believe those are not BIDS compliant, and will definitely break any pipeline that you'd run with clinica. Is there a reason you'd need those ? (my knowledge of field maps is quite limited, so I might be missing something here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
converter enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants