From 999cd3df306b36ad248b60f59cdcbad9cb7f7b7e Mon Sep 17 00:00:00 2001 From: AliceJoubert <158147135+AliceJoubert@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:14:15 +0200 Subject: [PATCH] [FIX] Fix logging in OASIS and AIBL converters (#1340) --- clinica/iotools/converters/aibl_to_bids/utils/bids.py | 8 ++++++++ clinica/iotools/converters/oasis_to_bids/oasis_to_bids.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/clinica/iotools/converters/aibl_to_bids/utils/bids.py b/clinica/iotools/converters/aibl_to_bids/utils/bids.py index 88cfc4327..15a12f21b 100644 --- a/clinica/iotools/converters/aibl_to_bids/utils/bids.py +++ b/clinica/iotools/converters/aibl_to_bids/utils/bids.py @@ -630,11 +630,19 @@ def _create_file( Path or None : Path to file """ + from clinica.cmdline import setup_clinica_logging from clinica.iotools.bids_utils import StudyName, bids_id_factory, json_from_dcm from clinica.iotools.converter_utils import viscode_to_session from clinica.iotools.utils.data_handling import center_nifti_origin from clinica.utils.stream import cprint + # This function is executed in a multiprocessing context + # such that we need to re-configure the clinica logger in the child processes. + # Note that logging messages could easily be lost (for example when logging + # to a file from two different processes). A better solution would be to + # implement a logging process consuming logging messages from a multiprocessing.Queue... + setup_clinica_logging("INFO") + participant_id = bids_id_factory(StudyName.AIBL).from_original_study_id( image.Subjects_ID ) diff --git a/clinica/iotools/converters/oasis_to_bids/oasis_to_bids.py b/clinica/iotools/converters/oasis_to_bids/oasis_to_bids.py index 9f0a1808d..d57ea0e8c 100644 --- a/clinica/iotools/converters/oasis_to_bids/oasis_to_bids.py +++ b/clinica/iotools/converters/oasis_to_bids/oasis_to_bids.py @@ -172,9 +172,17 @@ def _create_modality_agnostic_files(self, bids_dir: Path): @staticmethod def convert_single_subject(subj_folder: Path, dest_dir: Path): + from clinica.cmdline import setup_clinica_logging from clinica.iotools.bids_utils import StudyName, bids_id_factory from clinica.utils.stream import cprint + # This function is executed in a multiprocessing context + # such that we need to re-configure the clinica logger in the child processes. + # Note that logging messages could easily be lost (for example when logging + # to a file from two different processes). A better solution would be to + # implement a logging process consuming logging messages from a multiprocessing.Queue... + setup_clinica_logging("INFO") + t1_folder = subj_folder / "PROCESSED" / "MPRAGE" / "SUBJ_111" cprint(f"Converting {subj_folder.name}", lvl="info") participant_id = bids_id_factory(StudyName.OASIS).from_original_study_id(