From 5966d662f2e1cf8bb3c280fd6520a3a477dd4426 Mon Sep 17 00:00:00 2001 From: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> Date: Mon, 4 Mar 2024 11:17:11 -0500 Subject: [PATCH 1/3] update error messages --- pypet2bids/pypet2bids/dcm2niix4pet.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pypet2bids/pypet2bids/dcm2niix4pet.py b/pypet2bids/pypet2bids/dcm2niix4pet.py index e65a01e1..2ac275df 100644 --- a/pypet2bids/pypet2bids/dcm2niix4pet.py +++ b/pypet2bids/pypet2bids/dcm2niix4pet.py @@ -173,7 +173,8 @@ def __init__(self, image_folder, destination_path=None, metadata_path=None, self.dcm2niix_path = self.check_for_dcm2niix() if not self.dcm2niix_path: - raise FileNotFoundError("dcm2niix not found, this module depends on it for conversions, exiting.") + logger.error("dcm2niix not found, this module depends on it for conversions, exiting.") + sys.exit(1) # check for the version of dcm2niix minimum_version = 'v1.0.20220720' @@ -263,7 +264,7 @@ def __init__(self, image_folder, destination_path=None, metadata_path=None, load_spreadsheet_data = get_metadata_from_spreadsheet(metadata_path=metadata_path, image_folder=self.image_folder, image_header_dict=self.dicom_headers[ - next(iter(self.dicom_headers))], + next(iter(self.dicom_headers))], **self.additional_arguments) self.spreadsheet_metadata['nifti_json'].update(load_spreadsheet_data['nifti_json']) @@ -286,11 +287,25 @@ def check_posix(): dcm2niix_path = subprocess.run('which dcm2niix', shell=True, capture_output=True).stdout.decode('utf-8').strip() + # check to see if dcm2niix is set in the config file, default to that if it's the case and alert user + set_in_config = helper_functions.check_pet2bids_config() + if set_in_config: + logger.warning(f"dcm2niix found on system path, but dcm2niix path is also set in ~/.pet2bidsconfig." + f" Defaulting to dcm2niix path set in config at {set_in_config}") + else: + dcm2niix_path = helper_functions.check_pet2bids_config() + + if not dcm2niix_path: pkged = "https://github.com/rordenlab/dcm2niix/releases" instructions = "https://github.com/rordenlab/dcm2niix#install" - no_dcm2niix = f"""Dcm2niix does not appear to be installed. Installation instructions can be found here - {instructions} and packaged versions can be found at {pkged}""" + no_dcm2niix = f"""Unable to locate Dcm2niix on your system $PATH or using the path specified in + $HOME/.pypet2bidsconfig. Installation instructions for dcm2niix can be found here + {instructions} + and packaged versions can be found at + {pkged} + Alternatively, you can set the path to dcm2niix in the config file at $HOME/.pet2bidsconfig + using the command dcm2niix4pet --set-dcm2niix-path.""" logger.error(no_dcm2niix) dcm2niix_path = None From 1f71e90285c9aa807ecabc7ccfe76f9d97804ff2 Mon Sep 17 00:00:00 2001 From: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> Date: Mon, 4 Mar 2024 13:06:38 -0500 Subject: [PATCH 2/3] Update pypet2bids/pypet2bids/dcm2niix4pet.py remove spaces --- pypet2bids/pypet2bids/dcm2niix4pet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypet2bids/pypet2bids/dcm2niix4pet.py b/pypet2bids/pypet2bids/dcm2niix4pet.py index 2ac275df..596d735d 100644 --- a/pypet2bids/pypet2bids/dcm2niix4pet.py +++ b/pypet2bids/pypet2bids/dcm2niix4pet.py @@ -264,7 +264,7 @@ def __init__(self, image_folder, destination_path=None, metadata_path=None, load_spreadsheet_data = get_metadata_from_spreadsheet(metadata_path=metadata_path, image_folder=self.image_folder, image_header_dict=self.dicom_headers[ - next(iter(self.dicom_headers))], + next(iter(self.dicom_headers))], **self.additional_arguments) self.spreadsheet_metadata['nifti_json'].update(load_spreadsheet_data['nifti_json']) From 4f6f4ba1508ece8a82d6e76d452ca4502d1b1e4d Mon Sep 17 00:00:00 2001 From: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> Date: Mon, 4 Mar 2024 13:10:48 -0500 Subject: [PATCH 3/3] actually using the one in the config if it's present --- pypet2bids/pypet2bids/dcm2niix4pet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pypet2bids/pypet2bids/dcm2niix4pet.py b/pypet2bids/pypet2bids/dcm2niix4pet.py index 2ac275df..0d35f24b 100644 --- a/pypet2bids/pypet2bids/dcm2niix4pet.py +++ b/pypet2bids/pypet2bids/dcm2niix4pet.py @@ -292,6 +292,7 @@ def check_posix(): if set_in_config: logger.warning(f"dcm2niix found on system path, but dcm2niix path is also set in ~/.pet2bidsconfig." f" Defaulting to dcm2niix path set in config at {set_in_config}") + dcm2niix_path = set_in_config else: dcm2niix_path = helper_functions.check_pet2bids_config()