Skip to content

Commit 093e596

Browse files
committed
almost forgot env and config file settings
1 parent e21f96b commit 093e596

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

pypet2bids/pypet2bids/dcm2niix4pet.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,26 @@ def __init__(
381381
i += 1
382382
self.dcm2niix_options = " ".join(filtered_options)
383383
else:
384-
self.dcm2niix_options = "-b y -w 1 -z y"
384+
# Check for dcm2niix options in config file and environment variable
385+
config_options = helper_functions.check_pet2bids_config(
386+
"PET2BIDS_DCM2NIIX_OPTIONS"
387+
)
388+
env_options = environ.get("PET2BIDS_DCM2NIIX_OPTIONS")
389+
390+
# Priority: command line > environment variable > config file > default
391+
if env_options:
392+
self.dcm2niix_options = env_options
393+
logger.info(
394+
f"Using dcm2niix options from environment variable: {env_options}"
395+
)
396+
elif config_options:
397+
self.dcm2niix_options = config_options
398+
logger.info(
399+
f"Using dcm2niix options from config file: {config_options}"
400+
)
401+
else:
402+
self.dcm2niix_options = "-b y -w 1 -z y"
403+
logger.debug("Using default dcm2niix options: -b y -w 1 -z y")
385404
self.file_format = file_format
386405
# we may want to include additional information to the sidecar, tsv, or json files generated after conversion
387406
# this variable stores the mapping between output files and a single dicom header used to generate those files
@@ -1069,6 +1088,8 @@ def load_spread_sheet_data(self):
10691088
# use with an input spreadsheet
10701089
dcm2niix4pet folder_with_pet_dicoms/ --destination-path sub-ValidBidsSubject/pet --dcm2niix-options -v y -w 1 -z y \
10711090
# use with custom dcm2niix options
1091+
dcm2niix4pet --set-dcm2niix-options '-v y -w 1 -z y' \
1092+
# set default dcm2niix options in config file
10721093
10731094
"""
10741095
)
@@ -1164,6 +1185,13 @@ def cli():
11641185
f"DCM2NIIX_PATH",
11651186
type=pathlib.Path,
11661187
)
1188+
parser.add_argument(
1189+
"--set-dcm2niix-options",
1190+
help="Provide dcm2niix options to be used as defaults, writes to config "
1191+
f"file {Path.home()}/.pet2bidsconfig under the variable "
1192+
f"PET2BIDS_DCM2NIIX_OPTIONS. Example: --set-dcm2niix-options '-v y -w 1 -z y'",
1193+
type=str,
1194+
)
11671195
parser.add_argument(
11681196
"--set-default-metadata-json",
11691197
help="Provide a path to a default metadata file json file."
@@ -1225,6 +1253,7 @@ def cli():
12251253
default=[],
12261254
help="Additional dcm2niix options to pass through. Use the same format as dcm2niix command line. "
12271255
"Note: -f flag and its value will be filtered out as file format is handled separately. "
1256+
"You can also set default options using --set-dcm2niix-options or the PET2BIDS_DCM2NIIX_OPTIONS environment variable. "
12281257
"Example: --dcm2niix-options -v y -w 1 -z y",
12291258
)
12301259
return parser
@@ -1373,6 +1402,12 @@ def main():
13731402
helper_functions.modify_config_file("DCM2NIIX_PATH", cli_args.set_dcm2niix_path)
13741403
sys.exit(0)
13751404

1405+
if cli_args.set_dcm2niix_options:
1406+
helper_functions.modify_config_file(
1407+
"PET2BIDS_DCM2NIIX_OPTIONS", cli_args.set_dcm2niix_options
1408+
)
1409+
sys.exit(0)
1410+
13761411
if cli_args.set_default_metadata_json:
13771412
helper_functions.modify_config_file(
13781413
"DEFAULT_METADATA_JSON", cli_args.set_default_metadata_json

0 commit comments

Comments
 (0)