Skip to content

Commit

Permalink
update to allow latest version of pydicom which changed read_file to …
Browse files Browse the repository at this point in the history
…dcmread
  • Loading branch information
brianmanderson committed Dec 3, 2024
1 parent 05781d5 commit 83f35e7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ opencv-python
openpyxl
pandas
Pillow
pydicom==2.4.4
pydicom
scikit-image
scipy
SimpleITK
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
name='DicomRTTool',
author='Brian Mark Anderson',
author_email='b5anderson@health.ucsd.edu',
version='2.1.9',
version='2.2.0',
description='Services for reading dicom files, RT structures, and dose files, as well as tools for '
'converting numpy prediction masks back to an RT structure',
long_description=long_description,
Expand Down
16 changes: 10 additions & 6 deletions src/DicomRTTool/ReaderWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import pydicom
import numpy as np
from pydicom.tag import Tag
if hasattr(pydicom, 'read_file'):
dcmread_function = pydicom.read_file
else:
dcmread_function = pydicom.dcmread
import SimpleITK as sitk
from skimage.measure import label, regionprops, find_contours
from threading import Thread
Expand Down Expand Up @@ -258,7 +262,7 @@ def add_dicom_to_dictionary_from_path(self, dicom_path, images_dictionary: Dict[
rt_files = [file for file in file_list if file not in all_names]
for i in rt_files:
lstRSFile = os.path.join(dicom_path, i)
rt = pydicom.read_file(lstRSFile)
rt = dcmread_function(lstRSFile)
modality = rt.Modality
if modality.lower().find('struct') != -1:
add_rt_to_dictionary(ds=rt, path=lstRSFile, rt_dictionary=rt_dictionary)
Expand Down Expand Up @@ -1122,7 +1126,7 @@ def get_images(self) -> None:
print('Loading images for {} at \n {}\n'.format(self.series_instances_dictionary[index].Description,
self.series_instances_dictionary[index].path))
dicom_names = self.series_instances_dictionary[index].files
self.ds = pydicom.read_file(dicom_names[0])
self.ds = dcmread_function(dicom_names[0])
self.reader.SetFileNames(dicom_names)
self.dicom_handle = self.reader.Execute()
if self.verbose:
Expand Down Expand Up @@ -1194,7 +1198,7 @@ def get_dose(self, dose_type="PLAN") -> None:
def __characterize_RT__(self, RT: RTBase):
if self.RS_struct_uid != RT.SeriesInstanceUID:
self.structure_references = {}
self.RS_struct = pydicom.read_file(RT.path)
self.RS_struct = dcmread_function(RT.path)
self.RS_struct_uid = RT.SeriesInstanceUID
for contour_number in range(len(self.RS_struct.ROIContourSequence)):
self.structure_references[
Expand Down Expand Up @@ -1348,7 +1352,7 @@ def use_template(self) -> None:
if not os.path.exists(self.template_dir):
self.template_dir = os.path.join('..', '..', 'Shared_Drive', 'Auto_Contour_Sites', 'template_RS.dcm')
self.key_list = self.template_dir.replace('template_RS.dcm', 'key_list.txt')
self.RS_struct = pydicom.read_file(self.template_dir)
self.RS_struct = dcmread_function(self.template_dir)
print('Running off a template')
self.change_template()

Expand Down Expand Up @@ -1401,7 +1405,7 @@ def prediction_array_to_RT(self, prediction_array: np.array, output_dir: typing.
elif self.RS_struct_uid != self.series_instances_dictionary[index].SeriesInstanceUID:
rt_structures = self.series_instances_dictionary[index].RTs
for uid_key in rt_structures:
self.RS_struct = pydicom.read_file(rt_structures[uid_key].path)
self.RS_struct = dcmread_function(rt_structures[uid_key].path)
self.RS_struct_uid = self.series_instances_dictionary[index].SeriesInstanceUID
break

Expand Down Expand Up @@ -1607,7 +1611,7 @@ def change_template(self):

def rewrite_RT(self, lstRSFile: typing.Union[str, bytes, os.PathLike] = None):
if lstRSFile is not None:
self.RS_struct = pydicom.read_file(lstRSFile)
self.RS_struct = dcmread_function(lstRSFile)
if Tag((0x3006, 0x020)) in self.RS_struct.keys():
self.ROI_Structure = self.RS_struct.StructureSetROISequence
else:
Expand Down
8 changes: 6 additions & 2 deletions src/DicomRTTool/Services/DicomBases.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import typing
import pydicom
if hasattr(pydicom, 'read_file'):
dcmread_function = pydicom.read_file
else:
dcmread_function = pydicom.dcmread
from pydicom.tag import Tag, BaseTag
import SimpleITK as sitk
from typing import List, Dict
Expand Down Expand Up @@ -41,7 +45,7 @@ def __init__(self):

def load_info(self, sitk_dicom_reader, sitk_string_keys: SitkDicomKeys = None):
file_name = sitk_dicom_reader.GetFileName()
ds = pydicom.read_file(file_name)
ds = dcmread_function(file_name)
self.SeriesInstanceUID = ds.SeriesInstanceUID
self.DoseType = ds.DoseType
self.DoseUnits = ds.DoseUnits
Expand All @@ -68,7 +72,7 @@ def load_info(self, sitk_dicom_reader, sitk_string_keys: SitkDicomKeys = None):

def add_beam(self, sitk_dicom_reader):
file_name = sitk_dicom_reader.GetFileName()
ds = pydicom.read_file(file_name)
ds = dcmread_function(file_name)
if self.SeriesInstanceUID == ds.SeriesInstanceUID:
"""
Means these are compatible beams
Expand Down

0 comments on commit 83f35e7

Please sign in to comment.