Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes for Requests not Found; Enhancment for Non-PET modalities #328

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <28850131+bendhouseart@users.noreply.github.com>"]
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
Loading