Skip to content

Commit 83a807a

Browse files
authored
Bug fixes for Requests not Found; Enhancment for Non-PET modalities (#328)
* bump version, add requests, create new lock file * added feature to ignore non-pet files
1 parent 525cf1c commit 83a807a

File tree

4 files changed

+55
-16
lines changed

4 files changed

+55
-16
lines changed

pypet2bids/poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pypet2bids/pypet2bids/dcm2niix4pet.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ def __init__(
301301
# we consider values stored in a default JSON file to be additional arguments, we load those
302302
# values first and then overwrite them with any user supplied values
303303

304+
# check to make sure the dicom is a PET dicom
305+
modalities = [dicom.Modality for dicom in self.dicom_headers.values()]
306+
non_pet_dicom = [modality for modality in modalities if modality != "PT"]
307+
308+
if len(non_pet_dicom) > 0:
309+
logger.warning(
310+
f"Non PET dicoms found in {self.image_folder}. Modalities f{non_pet_dicom} detected"
311+
)
312+
304313
# load config file
305314
default_json_path = helper_functions.check_pet2bids_config(
306315
"DEFAULT_METADATA_JSON"
@@ -500,6 +509,32 @@ def run_dcm2niix(self):
500509
join(tempdir_pathlike, file) for file in listdir(tempdir_pathlike)
501510
]
502511

512+
# check to see if there are any modalities present that aren't PET
513+
remove_these_non_pet_files = []
514+
for json_file in [f for f in files_created_by_dcm2niix if ".json" in f]:
515+
with open(json_file, "r") as infile:
516+
json_data = json.load(infile)
517+
if json_data.get("Modality") != "PT":
518+
logger.warning(
519+
f"Non PET modality found in {json_file}, skipping. Files relating to this json and it's"
520+
f"nifti will not be included at the destination folder {self.destination_folder}"
521+
)
522+
remove_these_non_pet_files.append(json_file)
523+
remove_these_non_pet_files.append(
524+
json_file.replace(".json", ".nii.gz")
525+
)
526+
remove_these_non_pet_files.append(
527+
json_file.replace(".json", ".nii")
528+
)
529+
530+
# if there are non PET files remove them from files_created_by_dcm2niix
531+
if remove_these_non_pet_files:
532+
for file in remove_these_non_pet_files:
533+
try:
534+
files_created_by_dcm2niix.remove(file)
535+
except ValueError:
536+
pass
537+
503538
# make sure destination path exists if not try creating it.
504539
try:
505540
if self.destination_path.exists():

pypet2bids/pypet2bids/helper_functions.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,22 @@ def flatten_series(series):
125125

126126
def collect_spreadsheets(folder_path: pathlib.Path):
127127
spreadsheet_files = []
128-
all_files = [
129-
folder_path / pathlib.Path(file)
130-
for file in os.listdir(folder_path)
131-
if os.path.isfile(os.path.join(folder_path, file))
132-
]
133-
for file in all_files:
134-
if (
135-
file.suffix == ".xlsx"
136-
or file.suffix == ".csv"
137-
or file.suffix == ".xls"
138-
or file.suffix == ".tsv"
139-
):
140-
spreadsheet_files.append(file)
128+
if folder_path.is_file():
129+
spreadsheet_files.append(folder_path)
130+
else:
131+
all_files = [
132+
folder_path / pathlib.Path(file)
133+
for file in os.listdir(folder_path)
134+
if os.path.isfile(os.path.join(folder_path, file))
135+
]
136+
for file in all_files:
137+
if (
138+
file.suffix == ".xlsx"
139+
or file.suffix == ".csv"
140+
or file.suffix == ".xls"
141+
or file.suffix == ".tsv"
142+
):
143+
spreadsheet_files.append(file)
141144
return spreadsheet_files
142145

143146

pypet2bids/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pypet2bids"
3-
version = "1.3.15"
3+
version = "1.3.16"
44
description = "A python library for converting PET imaging and blood data to BIDS."
55
authors = ["anthony galassi <[email protected]>"]
66
license = "MIT"
@@ -30,6 +30,7 @@ pandas = ">=1.4.4"
3030
pyxlsb = "^1.0.9"
3131
joblib = "^1.2.0"
3232
toml = ">=0.10.2"
33+
requests = "^2.32.3"
3334

3435

3536
[tool.poetry.dev-dependencies]

0 commit comments

Comments
 (0)