From 7894042b6320d9c05054ff5ad12820f9a383ce09 Mon Sep 17 00:00:00 2001 From: Thomas BAUDIER Date: Thu, 31 Oct 2024 15:58:48 +0100 Subject: [PATCH] Pydicom change dcm_read to dcmread --- bin/gt_dicom_rt_struct_to_image | 2 +- gatetools/dvh.py | 8 ++++---- gatetools/image_convert.py | 20 ++++++++++---------- gatetools/roi_utils.py | 2 +- setup.py | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/bin/gt_dicom_rt_struct_to_image b/bin/gt_dicom_rt_struct_to_image index d23b0b2..9977789 100755 --- a/bin/gt_dicom_rt_struct_to_image +++ b/bin/gt_dicom_rt_struct_to_image @@ -40,7 +40,7 @@ def gt_dicom_rt_struct_to_image(list_roi, filename_struct, filename_img, roi, cr gt.logging_conf(verbose=(verbose or list_roi),logfile=logfile) # read dicom struct - structset = pydicom.read_file(filename_struct, force=True) + structset = pydicom.dcmread(filename_struct, force=True) # print roi names roi_names = gt.list_roinames(structset) diff --git a/gatetools/dvh.py b/gatetools/dvh.py index 30d5a5e..268e365 100644 --- a/gatetools/dvh.py +++ b/gatetools/dvh.py @@ -104,7 +104,7 @@ def test_dvh(self): logger.info('Test_DVH test_dvh') tmpdirpath = tempfile.mkdtemp() filenameStruct = wget.download("https://gitlab.in2p3.fr/opengate/gatetools_data/-/raw/master/rtstruct.dcm?inline=false", out=tmpdirpath, bar=None) - structset = pydicom.read_file(os.path.join(tmpdirpath, filenameStruct)) + structset = pydicom.dcmread(os.path.join(tmpdirpath, filenameStruct)) filenameDose = wget.download("https://gitlab.in2p3.fr/opengate/gatetools_data/-/raw/master/rtdose.dcm?inline=false", out=tmpdirpath, bar=None) doseImage = gt.read_3d_dicom([os.path.join(tmpdirpath, filenameDose)]) transformImage = gt.applyTransformation(input=doseImage, neworigin=[-176, -320, -235]) @@ -123,7 +123,7 @@ def test_dvh_volume(self): logger.info('Test_DVH test_dvh_volume') tmpdirpath = tempfile.mkdtemp() filenameStruct = wget.download("https://gitlab.in2p3.fr/opengate/gatetools_data/-/raw/master/rtstruct.dcm?inline=false", out=tmpdirpath, bar=None) - structset = pydicom.read_file(os.path.join(tmpdirpath, filenameStruct)) + structset = pydicom.dcmread(os.path.join(tmpdirpath, filenameStruct)) filenameDose = wget.download("https://gitlab.in2p3.fr/opengate/gatetools_data/-/raw/master/rtdose.dcm?inline=false", out=tmpdirpath, bar=None) doseImage = gt.read_3d_dicom([os.path.join(tmpdirpath, filenameDose)]) transformImage = gt.applyTransformation(input=doseImage, neworigin=[-176, -320, -235]) @@ -141,7 +141,7 @@ def test_dvh_compute_v(self): logger.info('Test_DVH test_dvh_compute_v') tmpdirpath = tempfile.mkdtemp() filenameStruct = wget.download("https://gitlab.in2p3.fr/opengate/gatetools_data/-/raw/master/rtstruct.dcm?inline=false", out=tmpdirpath, bar=None) - structset = pydicom.read_file(os.path.join(tmpdirpath, filenameStruct)) + structset = pydicom.dcmread(os.path.join(tmpdirpath, filenameStruct)) filenameDose = wget.download("https://gitlab.in2p3.fr/opengate/gatetools_data/-/raw/master/rtdose.dcm?inline=false", out=tmpdirpath, bar=None) doseImage = gt.read_3d_dicom([os.path.join(tmpdirpath, filenameDose)]) transformImage = gt.applyTransformation(input=doseImage, neworigin=[-176, -320, -235]) @@ -156,7 +156,7 @@ def test_dvh_compute_d(self): logger.info('Test_DVH test_dvh_compute_d') tmpdirpath = tempfile.mkdtemp() filenameStruct = wget.download("https://gitlab.in2p3.fr/opengate/gatetools_data/-/raw/master/rtstruct.dcm?inline=false", out=tmpdirpath, bar=None) - structset = pydicom.read_file(os.path.join(tmpdirpath, filenameStruct)) + structset = pydicom.dcmread(os.path.join(tmpdirpath, filenameStruct)) filenameDose = wget.download("https://gitlab.in2p3.fr/opengate/gatetools_data/-/raw/master/rtdose.dcm?inline=false", out=tmpdirpath, bar=None) doseImage = gt.read_3d_dicom([os.path.join(tmpdirpath, filenameDose)]) transformImage = gt.applyTransformation(input=doseImage, neworigin=[-176, -320, -235]) diff --git a/gatetools/image_convert.py b/gatetools/image_convert.py index 37ca38a..5e2dafa 100644 --- a/gatetools/image_convert.py +++ b/gatetools/image_convert.py @@ -105,9 +105,9 @@ def separate_series(dicomFiles): #Load dicom files for file in dicomFiles: try: - seriesInstanceUID = pydicom.read_file(file)[0x0020, 0x000e].value + seriesInstanceUID = pydicom.dcmread(file)[0x0020, 0x000e].value except pydicom.errors.InvalidDicomError: - ds = pydicom.read_file(file, force=True) + ds = pydicom.dcmread(file, force=True) ds.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian seriesInstanceUID = ds[0x0020, 0x000e].value print(seriesInstanceUID) @@ -125,9 +125,9 @@ def separate_accessionNumber_series(series): for serie in series.keys(): for file in series[serie]: try: - accessionNumber = pydicom.read_file(file)[0x0020, 0x0012].value + accessionNumber = pydicom.dcmread(file)[0x0020, 0x0012].value except pydicom.errors.InvalidDicomError: - ds = pydicom.read_file(file, force=True) + ds = pydicom.dcmread(file, force=True) ds.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian accessionNumber = ds[0x0020, 0x0012].value new_key = str(serie) + "_" + str(accessionNumber) @@ -145,9 +145,9 @@ def separate_sequenceName_series(series): for serie in series.keys(): for file in series[serie]: try: - sequenceName = pydicom.read_file(file)[0x0018, 0x0024].value + sequenceName = pydicom.dcmread(file)[0x0018, 0x0024].value except pydicom.errors.InvalidDicomError: - ds = pydicom.read_file(file, force=True) + ds = pydicom.dcmread(file, force=True) ds.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian sequenceName = ds[0x0018, 0x0024].value new_key = str(serie) + "_" + str(sequenceName) @@ -165,9 +165,9 @@ def read_dicom(dicomFiles): #Load dicom files for file in dicomFiles: try: - files.append(pydicom.read_file(file)) + files.append(pydicom.dcmread(file)) except pydicom.errors.InvalidDicomError: - ds = pydicom.read_file(file, force=True) + ds = pydicom.dcmread(file, force=True) ds.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian files.append(ds) @@ -242,9 +242,9 @@ def read_3d_dicom(dicomFile, flip=False): """ files = [] try: - files.append(pydicom.read_file(dicomFile[0])) + files.append(pydicom.dcmread(dicomFile[0])) except pydicom.errors.InvalidDicomError: - ds = pydicom.read_file(dicomFile[0], force=True) + ds = pydicom.dcmread(dicomFile[0], force=True) ds.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian files.append(ds) diff --git a/gatetools/roi_utils.py b/gatetools/roi_utils.py index 9669a03..c6ce62b 100644 --- a/gatetools/roi_utils.py +++ b/gatetools/roi_utils.py @@ -783,7 +783,7 @@ class Test_ROI(LoggedTestCase): def test_roi(self): tmpdirpath = tempfile.mkdtemp() filenameStruct = wget.download("https://gitlab.in2p3.fr/opengate/gatetools_data/-/raw/master/rtstruct.dcm?inline=false", out=tmpdirpath, bar=None) - structset = pydicom.read_file(os.path.join(tmpdirpath, filenameStruct)) + structset = pydicom.dcmread(os.path.join(tmpdirpath, filenameStruct)) # roi names roi_names = list_roinames(structset) diff --git a/setup.py b/setup.py index 40b3ada..633129f 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ 'click', 'numpy', 'scipy', - 'pydicom', + 'pydicom>=3.0.0', 'tqdm', 'colored', 'itk>=5.2.0',