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

[FIX] ADNI-to-BIDS fmap conversion : delete real/imaginary files properly, enable converting to the same folder for fmap #1198

Merged

Conversation

AliceJoubert
Copy link
Contributor

@AliceJoubert AliceJoubert commented Jun 3, 2024

This PR proposes small changes to allow :

  • Removing files that were invalid (real/imaginary suffix after dcm2nix conversion) for all modalities
  • Converting to the same folder with FMAP modality without deleting valid files
  • Unit tests

@AliceJoubert AliceJoubert added converter fix PR fixing a bug labels Jun 3, 2024
@AliceJoubert AliceJoubert self-assigned this Jun 3, 2024
@AliceJoubert AliceJoubert changed the title [FIX] ADNI-to-BIDS fmap conversion : delete real/imaginary files properly, enable converting to the same folder for map [FIX] ADNI-to-BIDS fmap conversion : delete real/imaginary files properly, enable converting to the same folder for fmap Jun 3, 2024
@AliceJoubert AliceJoubert marked this pull request as ready for review June 3, 2024 12:06
Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

Thanks @AliceJoubert !
Just two very small suggestions but LGTM otherwise.

clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
@AliceJoubert
Copy link
Contributor Author

AliceJoubert commented Jun 3, 2024

Thanks for the review @NicolasGensollen ! I modified the code as suggested and also added the same kind of logic to delete files with invalid suffixes. Do you see anything else that could be improved ?

Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

Thanks @AliceJoubert !
I think the PR looks good but it'd be awesome to add some unit tests covering the file filtering and removal logic. A possible approach that I'm suggesting here is to isolate the related code in one or two helper functions and add unit tests for those.
Let me know what you think !

clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

Thanks @AliceJoubert !
This is looking good ! Just a few small suggestions on the organization of these helper functions.

clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
@AliceJoubert
Copy link
Contributor Author

Thanks for the suggestions @NicolasGensollen ! I modified the code according to them. Do you see anything else ?

Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

Thanks @AliceJoubert !

I think this is almost ready. 👍
I have a small suggestion for the API of one of the helper functions (sorry for initially suggesting something different), as well as some minor suggestions to simplify the tests.

folder: Path,
suffixes: Iterable[str],
mod_to_update: bool = False,
) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I know I asked for this, but re-looking at this, I think it would be more consistent to have this function return the list of files that were removed. This would offer the same API as _remove_files_with_unsupported_suffixes and the caller code would be pretty much the same.

So it'd be something like:

...
-> Iterable[Path]:
    from clinica.utils.stream import cprint

    if images_to_remove := _get_images_with_suffix(folder, suffixes):
        if mod_to_update:
            cprint(...)
            for path_to_unlink in images_to_remove:
                (path_to_unlink).unlink()
        else:
            cprint(f"There already exist images :...")
    return images_to_remove

Copy link
Contributor Author

@AliceJoubert AliceJoubert Jun 5, 2024

Choose a reason for hiding this comment

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

No worries @NicolasGensollen ! Thanks for the comments.
The thing is, I can't use the output of that function by itself if I want to get out of the create_file function since it's totally possible for it to return either an empty or an actual list while we need the process to continue.
If we want to get the images_to_remove list we could call _get_images_with_suffix separately and keep a function returning a flag to know if we continue the process. WDYT ?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, you're totally right !
Let's forget about this comment and keep things like this.
Sorry for the noise.

Copy link
Member

Choose a reason for hiding this comment

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

Did you commit the suggestions on the tests ? I see the conversations resolved but not the commits and modifications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, I was waiting for your answer before committing the other changes. You should see them now @NicolasGensollen

Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @AliceJoubert !

@NicolasGensollen NicolasGensollen merged commit a2c7d06 into aramis-lab:dev Jun 5, 2024
13 of 15 checks passed
@AliceJoubert AliceJoubert deleted the fmap_check_existing_folders branch June 5, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
converter fix PR fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants