Skip to content

Commit

Permalink
Merge pull request #89 from OpenGATE/pydicom
Browse files Browse the repository at this point in the history
Pydicom change dcm_read to dcmread
  • Loading branch information
tbaudier authored Oct 31, 2024
2 parents 9381cea + ed6adb2 commit 2e2141c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9, '3.10', '3.11']
ITK_VERSION: [5.3.0, pre]

steps:
- name: Checkout github repo
Expand All @@ -33,10 +32,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ ${{ matrix.ITK_VERSION }} == 'pre' ];
then pip install itk --pre;
else pip install itk==${{ matrix.ITK_VERSION }};
fi
pip install itk
pip install -e .
pip install uproot3
pip freeze
Expand Down
2 changes: 1 addition & 1 deletion bin/gt_dicom_rt_struct_to_image
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions gatetools/dvh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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])
Expand All @@ -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])
Expand All @@ -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])
Expand Down
20 changes: 10 additions & 10 deletions gatetools/image_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
14 changes: 7 additions & 7 deletions gatetools/image_uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,28 @@ def test_image_uncertainty(self):
xx, yy, zz = np.meshgrid(x, y, z)
npImage = 10*xx+4.5
npsImage = 10*xx**2+9*xx+2.85
image = itk.image_from_array(np.float32(npImage))
image = itk.image_from_array(np.float64(npImage))
images = [image]
simage = itk.image_from_array(np.float32(npsImage))
simage = itk.image_from_array(np.float64(npsImage))
simages = [simage]
uncertainty = image_uncertainty(images, simages, N=1000000000000)
tmpdirpath = tempfile.mkdtemp()
itk.imwrite(uncertainty, os.path.join(tmpdirpath, "uncertainty.mha"))
with open(os.path.join(tmpdirpath, "uncertainty.mha"),"rb") as fnew:
bytesNew = fnew.read()
new_hash = hashlib.sha256(bytesNew).hexdigest()
self.assertTrue("0a2dc7a0e28509c569cecde6b6252507936b29365cb4db0c75ab3c0fab3b2bc4" == new_hash)
shutil.rmtree(tmpdirpath)
self.assertTrue("0e1f8e0f0d7d7d3921c726dc33409345e6d9b8bfcc53b797d67f8b48997fa1a5" == new_hash)
print(tmpdirpath)
def test_image_uncertainty_by_slice(self):
x = np.arange(0, 1, 0.01)
y = np.arange(0, 1, 0.01)
z = np.arange(0, 1, 0.01)
xx, yy, zz = np.meshgrid(x, y, z)
npImage = 10*xx+4.5
npsImage = 10*xx**2+9*xx+2.85
image = itk.image_from_array(np.float32(npImage))
image = itk.image_from_array(np.float64(npImage))
images = [image]
simage = itk.image_from_array(np.float32(npsImage))
simage = itk.image_from_array(np.float64(npsImage))
simages = [simage]
uncertainty, mean, nb = image_uncertainty_by_slice(images, simages, N=1000000000000)
tmpdirpath = tempfile.mkdtemp()
Expand All @@ -234,7 +234,7 @@ def test_image_uncertainty_by_slice(self):
with open(os.path.join(tmpdirpath, "uncertainty.mha"),"rb") as fnew:
bytesNew = fnew.read()
new_hash = hashlib.sha256(bytesNew).hexdigest()
self.assertTrue("0a2dc7a0e28509c569cecde6b6252507936b29365cb4db0c75ab3c0fab3b2bc4" == new_hash)
self.assertTrue("0e1f8e0f0d7d7d3921c726dc33409345e6d9b8bfcc53b797d67f8b48997fa1a5" == new_hash)
shutil.rmtree(tmpdirpath)
def test_image_uncertainty_Poisson(self):
x = np.arange(0, 1, 0.01)
Expand Down
2 changes: 1 addition & 1 deletion gatetools/roi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2e2141c

Please sign in to comment.