Skip to content

Commit 75d87bf

Browse files
committed
raise error if missing images
1 parent 3b79435 commit 75d87bf

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

pypet2bids/pypet2bids/dcm2niix4pet.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,23 @@ def run_dcm2niix(self):
486486
}
487487
self.telemetry_data.update(count_output_files(self.tempdir_location))
488488

489-
if convert.returncode != 0:
489+
if (
490+
convert.returncode != 0
491+
or "error" in convert.stderr.decode("utf-8").lower()
492+
):
490493
print(
491494
"Check output .nii files, dcm2iix returned these errors during conversion:"
492495
)
496+
# raise error if missing images is found
497+
if "missing images" in convert.stderr.decode("utf8").lower():
498+
error_message = convert.stderr.decode("utf8").replace("Error:", "")
499+
error_message = f"{error_message}for dicoms in {image_folder}"
500+
raise FileNotFoundError(error_message)
493501
if (
494502
bytes("Skipping existing file name", "utf-8") not in convert.stdout
495503
or convert.stderr
496504
):
497-
print(convert.stderr)
505+
print(convert.stderr.decode("utf-8"))
498506
elif (
499507
convert.returncode != 0
500508
and bytes("Error: Check sorted order", "utf-8") in convert.stdout
@@ -558,6 +566,17 @@ def run_dcm2niix(self):
558566
destination_path=tempdir_pathlike
559567
)
560568

569+
# Additionally we want to check to see if the frame timing information is correct
570+
# often a series of dicoms is incomplete (missing files) but dcm2niix can still
571+
# output a nifti at the end. We can compare the outputs of dcm2niix with the
572+
# frame information in the dicom header.
573+
574+
# collect the number of frames that are present in the nifti
575+
576+
# collect the number of frames that are listed in the sidecar, duration, etc
577+
578+
# collect any frame timing info that may be contained in additional arguments or the spreadsheet metadata
579+
561580
# we check to see what's missing from our recommended and required jsons by gathering the
562581
# output of check_json silently
563582
if self.additional_arguments:

0 commit comments

Comments
 (0)