Skip to content

Commit

Permalink
warnings for missing patients
Browse files Browse the repository at this point in the history
Former-commit-id: abc0428
  • Loading branch information
fishingguy456 committed Jun 22, 2022
1 parent fdc146b commit f8e64da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions examples/autotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ def run(self):
for subject_id in subject_ids:
self._process_wrapper(subject_id)
self.save_data()
all_patient_names = glob.glob(pathlib.Path(self.input_directory, "*"," ").as_posix()[0:-1])
all_patient_names = [os.path.split(os.path.split(x)[0])[1] for x in all_patient_names]
for e in all_patient_names:
if e not in patient_ids:
warnings.warn(f"Patient {e} does not have proper DICOM references")


if __name__ == "__main__":
Expand Down
30 changes: 15 additions & 15 deletions imgtools/autopipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from aifc import Error
from distutils.log import warn
import os, pathlib
import shutil
import glob
Expand Down Expand Up @@ -107,14 +106,11 @@ def __init__(self,
self.label_names = {}
self.ignore_missing_regex = ignore_missing_regex

roi_path = pathlib.Path(self.input_directory, "roi_names.yaml").as_posix()

if os.path.exists(roi_path):
with open(roi_path, "r") as f:
try:
self.label_names = yaml.safe_load(f)
except yaml.YAMLError as exc:
print(exc)
with open(pathlib.Path(self.input_directory, "roi_names.yaml").as_posix(), "r") as f:
try:
self.label_names = yaml.safe_load(f)
except yaml.YAMLError as exc:
print(exc)

if not isinstance(self.label_names, dict):
raise ValueError("roi_names.yaml must parse as a dictionary")
Expand Down Expand Up @@ -194,7 +190,6 @@ def process_one_subject(self, subject_id):
subject_id : str
The ID of subject to process
"""
# if we want overwriting or if we don't want it and the file doesn't exist, we can process
if self.overwrite or (not self.overwrite and not (os.path.exists(pathlib.Path(self.output_directory, subject_id).as_posix()) or self.glob_checker_nnunet(subject_id))):
#Check if the subject_id has already been processed
if os.path.exists(pathlib.Path(self.output_directory,".temp",f'temp_{subject_id}.pkl').as_posix()):
Expand Down Expand Up @@ -412,15 +407,20 @@ def run(self):
self.train, self.test = [], []
# Note that returning any SimpleITK object in process_one_subject is
# not supported yet, since they cannot be pickled
if os.path.exists(self.output_df_path):
if os.path.exists(self.output_df_path) and not self.overwrite:
print("Dataset already processed...")
shutil.rmtree(pathlib.Path(self.output_directory, ".temp").as_posix())
else:
Parallel(n_jobs=self.n_jobs, verbose=verbose)(
delayed(self._process_wrapper)(subject_id) for subject_id in subject_ids)
# for subject_id in subject_ids:
# self._process_wrapper(subject_id)
# Parallel(n_jobs=self.n_jobs, verbose=verbose)(
# delayed(self._process_wrapper)(subject_id) for subject_id in subject_ids)
for subject_id in subject_ids:
self._process_wrapper(subject_id)
self.save_data()
all_patient_names = glob.glob(pathlib.Path(self.input_directory, "*"," ").as_posix()[0:-1])
all_patient_names = [os.path.split(os.path.split(x)[0])[1] for x in all_patient_names]
for e in all_patient_names:
if e not in patient_ids:
warnings.warn(f"Patient {e} does not have proper DICOM references")

def main():
args = parser()
Expand Down

0 comments on commit f8e64da

Please sign in to comment.