Skip to content

Commit

Permalink
Bug fixes for Requests not Found; Enhancment for Non-PET modalities (#…
Browse files Browse the repository at this point in the history
…328)

* bump version, add requests, create new lock file
* added feature to ignore non-pet files
  • Loading branch information
bendhouseart authored Dec 20, 2024
1 parent 525cf1c commit 83a807a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pypet2bids/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions pypet2bids/pypet2bids/dcm2niix4pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ def __init__(
# we consider values stored in a default JSON file to be additional arguments, we load those
# values first and then overwrite them with any user supplied values

# check to make sure the dicom is a PET dicom
modalities = [dicom.Modality for dicom in self.dicom_headers.values()]
non_pet_dicom = [modality for modality in modalities if modality != "PT"]

if len(non_pet_dicom) > 0:
logger.warning(
f"Non PET dicoms found in {self.image_folder}. Modalities f{non_pet_dicom} detected"
)

# load config file
default_json_path = helper_functions.check_pet2bids_config(
"DEFAULT_METADATA_JSON"
Expand Down Expand Up @@ -500,6 +509,32 @@ def run_dcm2niix(self):
join(tempdir_pathlike, file) for file in listdir(tempdir_pathlike)
]

# check to see if there are any modalities present that aren't PET
remove_these_non_pet_files = []
for json_file in [f for f in files_created_by_dcm2niix if ".json" in f]:
with open(json_file, "r") as infile:
json_data = json.load(infile)
if json_data.get("Modality") != "PT":
logger.warning(
f"Non PET modality found in {json_file}, skipping. Files relating to this json and it's"
f"nifti will not be included at the destination folder {self.destination_folder}"
)
remove_these_non_pet_files.append(json_file)
remove_these_non_pet_files.append(
json_file.replace(".json", ".nii.gz")
)
remove_these_non_pet_files.append(
json_file.replace(".json", ".nii")
)

# if there are non PET files remove them from files_created_by_dcm2niix
if remove_these_non_pet_files:
for file in remove_these_non_pet_files:
try:
files_created_by_dcm2niix.remove(file)
except ValueError:
pass

# make sure destination path exists if not try creating it.
try:
if self.destination_path.exists():
Expand Down
29 changes: 16 additions & 13 deletions pypet2bids/pypet2bids/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,22 @@ def flatten_series(series):

def collect_spreadsheets(folder_path: pathlib.Path):
spreadsheet_files = []
all_files = [
folder_path / pathlib.Path(file)
for file in os.listdir(folder_path)
if os.path.isfile(os.path.join(folder_path, file))
]
for file in all_files:
if (
file.suffix == ".xlsx"
or file.suffix == ".csv"
or file.suffix == ".xls"
or file.suffix == ".tsv"
):
spreadsheet_files.append(file)
if folder_path.is_file():
spreadsheet_files.append(folder_path)
else:
all_files = [
folder_path / pathlib.Path(file)
for file in os.listdir(folder_path)
if os.path.isfile(os.path.join(folder_path, file))
]
for file in all_files:
if (
file.suffix == ".xlsx"
or file.suffix == ".csv"
or file.suffix == ".xls"
or file.suffix == ".tsv"
):
spreadsheet_files.append(file)
return spreadsheet_files


Expand Down
3 changes: 2 additions & 1 deletion pypet2bids/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pypet2bids"
version = "1.3.15"
version = "1.3.16"
description = "A python library for converting PET imaging and blood data to BIDS."
authors = ["anthony galassi <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -30,6 +30,7 @@ pandas = ">=1.4.4"
pyxlsb = "^1.0.9"
joblib = "^1.2.0"
toml = ">=0.10.2"
requests = "^2.32.3"


[tool.poetry.dev-dependencies]
Expand Down

0 comments on commit 83a807a

Please sign in to comment.