Skip to content

Commit baa5fd0

Browse files
authored
Bug Fix for sidecar flag on ecat2bids (#358)
Fixes template json and sidecar issues posted by users Specifically fixes issues #352 and #354 posted on the github Rolling into version 1.4.4
1 parent beef8eb commit baa5fd0

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

pypet2bids/pypet2bids/dcm2niix4pet.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,24 @@
8282
default_metadata_json = helper_functions.check_pet2bids_config(
8383
"DEFAULT_METADATA_JSON"
8484
)
85-
if default_metadata_json and Path(default_metadata_json).exists():
85+
if default_metadata_json and Path(str(default_metadata_json)).exists():
8686
# do nothing
8787
pass
88-
else:
88+
elif default_metadata_json and not Path(str(default_metadata_json)).exists():
89+
# Copy template to the specified path
8990
try:
91+
# Ensure the parent directory exists before copying
92+
Path(default_metadata_json).parent.mkdir(parents=True, exist_ok=True)
9093
shutil.copy(
9194
Path(metadata_folder) / "template_json.json", default_metadata_json
9295
)
9396
except FileNotFoundError:
97+
# Fallback to module folder template
98+
Path(default_metadata_json).parent.mkdir(parents=True, exist_ok=True)
9499
shutil.copy(module_folder / "template_json.json", default_metadata_json)
100+
else:
101+
# No DEFAULT_METADATA_JSON set in config, do nothing
102+
pass
95103
else:
96104
# if it doesn't exist use the default one included in this library
97105
helper_functions.modify_config_file(

pypet2bids/pypet2bids/ecat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,11 @@ def show_sidecar(self, output_path=None):
523523
)
524524
else:
525525
collection_of_fields[field] = self.sidecar_template.get(field)
526-
527-
if helper_functions.collect_bids_part("ses", self.output_path) != "":
528-
collection_of_fields["ses"] = helper_functions.collect_bids_part(
529-
"ses", self.output_path
530-
)
526+
if self.output_path:
527+
if helper_functions.collect_bids_part("ses", self.output_path) != "":
528+
collection_of_fields["ses"] = helper_functions.collect_bids_part(
529+
"ses", self.output_path
530+
)
531531

532532
if self.ezbids:
533533
hash_string = helper_functions.hash_fields(**collection_of_fields)

pypet2bids/pypet2bids/ecat_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def main():
282282
os.environ["PET2BIDS_TELEMETRY_ENABLED"] = "False"
283283

284284
collect_pixel_data = False
285-
if cli_args.convert or cli_args.update:
285+
if cli_args.convert or cli_args.update or cli_args.sidecar:
286286
collect_pixel_data = True
287287
if cli_args.scannerparams is not None:
288288
# if no args are supplied to --scannerparams/-s

0 commit comments

Comments
 (0)