Skip to content

Commit

Permalink
#148:
Browse files Browse the repository at this point in the history
Make compatible with pydicom >= 3.0.0
  • Loading branch information
abrys committed Sep 27, 2024
1 parent 1471a23 commit d8ab261
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions dicom2nifti/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import numpy
import pydicom
from pydicom import dcmread
from pydicom.tag import Tag

import dicom2nifti.settings
Expand All @@ -36,7 +37,7 @@ def read_dicom_directory(dicom_directory, stop_before_pixels=False):
for dicom_file in files:
file_path = os.path.join(root, dicom_file)
if is_dicom_file(file_path):
dicom_headers = pydicom.read_file(file_path,
dicom_headers = dcmread(file_path,
defer_size="1 KB",
stop_before_pixels=stop_before_pixels,
force=dicom2nifti.settings.pydicom_read_force)
Expand Down Expand Up @@ -1161,7 +1162,7 @@ def is_dicom_file(filename):
return True
if dicom2nifti.settings.pydicom_read_force:
try:
dicom_headers = pydicom.read_file(filename, defer_size="1 KB", stop_before_pixels=True, force=True)
dicom_headers = dcmread(filename, defer_size="1 KB", stop_before_pixels=True, force=True)
if dicom_headers is not None:
return True
except:
Expand Down
3 changes: 2 additions & 1 deletion dicom2nifti/convert_dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import tempfile

import pydicom
from pydicom import dcmread
from pydicom.tag import Tag

import dicom2nifti.common as common
Expand Down Expand Up @@ -199,7 +200,7 @@ def _get_first_header(dicom_directory):
if not common.is_dicom_file(file_path):
continue
# read the headers
return pydicom.read_file(file_path,
return dcmread(file_path,
stop_before_pixels=True,
force=dicom2nifti.settings.pydicom_read_force)
# no dicom files found
Expand Down
3 changes: 2 additions & 1 deletion dicom2nifti/convert_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import unicodedata

import pydicom
from pydicom import dcmread
from pydicom.tag import Tag

import dicom2nifti.common as common
Expand Down Expand Up @@ -41,7 +42,7 @@ def convert_directory(dicom_directory, output_folder, compression=True, reorient
# read the dicom as fast as possible
# (max length for SeriesInstanceUID is 64 so defer_size 100 should be ok)

dicom_headers = pydicom.read_file(file_path,
dicom_headers = dcmread(file_path,
defer_size="1 KB",
stop_before_pixels=False,
force=dicom2nifti.settings.pydicom_read_force)
Expand Down
3 changes: 2 additions & 1 deletion scripts/anonymize_testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pydicom
import pydicom.dataset
import pydicom.uid
from pydicom import dcmread

import common
from dicom2nifti.common import read_dicom_directory, is_philips, is_siemens, is_ge
Expand Down Expand Up @@ -132,7 +133,7 @@ def _anonymize_file(dicom_file_in, dicom_file_out, fields_to_keep):
'ImplementationClassUID']

# Load dicom_file_in
dicom_in = pydicom.read_file(dicom_file_in)
dicom_in = dcmread(dicom_file_in)

# Create new dicom file
# Set new file meta information
Expand Down
2 changes: 1 addition & 1 deletion scripts/debug_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run_convert_directory2():
tmp_output_dir = tempfile.mkdtemp()
try:
import pydicom
# headers = pydicom.read_file("/Users/abrys/Downloads/failing_cases/test.dcm")
# headers = dcmread("/Users/abrys/Downloads/failing_cases/test.dcm")
convert_directory.convert_directory("/Users/abrys/Downloads/dti",
"/Users/abrys/Downloads/dti")

Expand Down
3 changes: 2 additions & 1 deletion scripts/dicomdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys

import pydicom
from pydicom import dcmread


def dicom_diff(file1, file2):
Expand All @@ -15,7 +16,7 @@ def dicom_diff(file1, file2):
Inspired by https://code.google.com/p/pydicom/source/browse/source/dicom/examples/DicomDiff.py
"""

datasets = pydicom.read_file(file1), pydicom.read_file(file2)
datasets = dcmread(file1), dcmread(file2)

rep = []

Expand Down
3 changes: 2 additions & 1 deletion scripts/shrink_multiframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import numpy
import pydicom
from pydicom import dcmread

import dicom2nifti.common as common
from dicom2nifti.convert_philips import _is_multiframe_diffusion_imaging, _is_multiframe_4d
Expand All @@ -19,7 +20,7 @@ def shrink_multiframe(input_file, output_file=None, slice_count=8, timepoint_cou
output_file = input_file

# Load dicom_file_in
dicom_in = pydicom.read_file(input_file)
dicom_in = dcmread(input_file)

if _is_multiframe_diffusion_imaging([dicom_in]) or _is_multiframe_4d([dicom_in]):

Expand Down
3 changes: 2 additions & 1 deletion scripts/shrink_singleframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pydicom
import pydicom.dataset
from pydicom import dcmread


def _shrink_file(dicom_file_in, subsample_factor):
Expand All @@ -24,7 +25,7 @@ def _shrink_file(dicom_file_in, subsample_factor):
dicom_file_out = dicom_file_in

# Load dicom_file_in
dicom_in = pydicom.read_file(dicom_file_in)
dicom_in = dcmread(dicom_file_in)

# Create new dicom file
# Set new file meta information
Expand Down
3 changes: 2 additions & 1 deletion tests/test_siemens.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import nibabel
import numpy
import pydicom
from pydicom import dcmread

import dicom2nifti.common as common
import dicom2nifti.convert_siemens as convert_siemens
Expand Down Expand Up @@ -199,7 +200,7 @@ def test_is_siemens(self):
assert not common.is_siemens(read_dicom_directory(test_data.HITACHI_ANATOMICAL))

def test_get_asconv_headers(self):
mosaic = pydicom.read_file(os.path.join(test_data.SIEMENS_FMRI, 'IM-0001-0001.dcm'))
mosaic = dcmread(os.path.join(test_data.SIEMENS_FMRI, 'IM-0001-0001.dcm'))
asconv_headers = convert_siemens._get_asconv_headers(mosaic)
assert len(asconv_headers) == 64022

Expand Down

0 comments on commit d8ab261

Please sign in to comment.