Skip to content

Commit

Permalink
io improved (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
louisblankemeier authored Oct 3, 2023
1 parent 839d976 commit 4b17c19
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions bin/C2C-slurm
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def python_submit(command, node="amalfi"):
print(f'Submitted the command --- "{command}" --- to slurm.')
except subprocess.CalledProcessError:
if node == None:
command = f"sbatch -c 8 --gres=gpu:1 --output ./slurm/slurm-%j.out --time=100-00:00:00 slurm.sh "
command = f"sbatch -c 8 --gres=gpu:1 --output ./slurm/slurm-%j.out --mem=128000 --time=100-00:00:00 slurm.sh "
submit_command(command)
print(f'Submitted the command --- "{command}" --- to slurm.')
else:
command = f"sbatch -c 8 --gres=gpu:1 --output ./slurm/slurm-%j.out --nodelist={node} --time=100-00:00:00 slurm.sh"
command = f"sbatch -c 8 --gres=gpu:1 --output ./slurm/slurm-%j.out --nodelist={node} --mem=128000 --time=100-00:00:00 slurm.sh"
submit_command(command)
print(f'Submitted the command --- "{command}" --- to slurm.')
os.remove("./slurm.sh")
Expand Down
22 changes: 15 additions & 7 deletions comp2comp/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,25 @@ def __call__(self, inference_pipeline):
return {}


def series_selector(dicom_path):
ds = pydicom.filereader.dcmread(dicom_path)
image_type_list = list(ds.ImageType)
if not any("primary" in s.lower() for s in image_type_list):
raise ValueError("Not primary image type")
if not any("original" in s.lower() for s in image_type_list):
raise ValueError("Not original image type")
if any("gsi" in s.lower() for s in image_type_list):
raise ValueError("GSI image type")
if ds.ImageOrientationPatient != [1, 0, 0, 0, 1, 0]:
raise ValueError("Image orientation is not axial")
return ds


def dicom_series_to_nifti(input_path, output_file, reorient_nifti):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(str(input_path))
print("Reading dicoms...")
ds = pydicom.filereader.dcmread(dicom_names[0])
image_type_list = list(ds.ImageType)
if any("gsi" in s.lower() for s in image_type_list):
raise ValueError("GSI Image Type detected")
ds = series_selector(dicom_names[0])
reader.SetFileNames(dicom_names)
image = reader.Execute()
if image.GetDirection() != (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0):
raise ValueError("Image orientation is not axial")
sitk.WriteImage(image, output_file)
return ds
14 changes: 7 additions & 7 deletions comp2comp/io/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def get_dicom_or_nifti_paths_and_num(path):
dicom_nifti_paths = []
for root, dirs, files in os.walk(path):
if len(files) > 0:
if all(file.endswith(".dcm") or file.endswith(".dicom") for file in files):
dicom_nifti_paths.append((root, len(files)))
else:
for file in files:
if file.endswith(".nii") or file.endswith(".nii.gz"):
num_slices = 450
dicom_nifti_paths.append((os.path.join(root, file), num_slices))
# if all(file.endswith(".dcm") or file.endswith(".dicom") for file in files):
dicom_nifti_paths.append((root, len(files)))
# else:
# for file in files:
# if file.endswith(".nii") or file.endswith(".nii.gz"):
# num_slices = 450
# dicom_nifti_paths.append((os.path.join(root, file), num_slices))

return dicom_nifti_paths

Expand Down

0 comments on commit 4b17c19

Please sign in to comment.