Skip to content

Commit

Permalink
update error messages (#282)
Browse files Browse the repository at this point in the history
* update error messages
* Update pypet2bids/pypet2bids/dcm2niix4pet.py
* Use dcm2niix specified in pet2bidsconfig file instead of dcm2niix found on path
  • Loading branch information
bendhouseart authored Mar 5, 2024
1 parent d6762b6 commit 272dc58
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pypet2bids/pypet2bids/dcm2niix4pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -286,11 +287,26 @@ 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}")
dcm2niix_path = 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

Expand Down

0 comments on commit 272dc58

Please sign in to comment.