Skip to content

Commit 14d1e4e

Browse files
authored
update: pydicom v3 (#273)
Signed-off-by: vsoch <[email protected]> Co-authored-by: vsoch <[email protected]>
1 parent 830966d commit 14d1e4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+227
-356
lines changed

.github/workflows/main.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
formatting:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515

1616
- name: Setup black environment
1717
run: conda create --quiet --name black black
@@ -26,14 +26,13 @@ jobs:
2626
testing:
2727
runs-on: ubuntu-latest
2828
steps:
29-
- uses: actions/checkout@v3
29+
- uses: actions/checkout@v4
3030

3131
- name: Setup conda environment
3232
run: |
3333
conda create --quiet --name testing
3434
export PATH="/usr/share/miniconda/bin:$PATH"
3535
source activate testing
36-
pip install matplotlib
3736
pip install .
3837
3938
- name: Test deid

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
Referenced versions in headers are tagged on Github, in parentheses are for pypi.
1515

1616
## [vxx](https://github.com/pydicom/deid/tree/master) (master)
17+
- Update to use pydicom 3 [#267](https://github.com/pydicom/deid/pull/267) (0.4.0)
1718
- Refactor INCLUDE_REQUIRES and provide max pydicom version [#267](https://github.com/pydicom/deid/pull/267) (0.3.25)
1819
- Support pydicom.Dataset objects created from BytesIO [#265](https://github.com/pydicom/deid/pull/265) (0.3.24)
1920
- Exception with missing filters for non-string VR [#256](https://github.com/pydicom/deid/issues/256) (0.3.23)

deid/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
from deid.config.standards import actions, formats, sections

deid/config/standards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
# Supported formats

deid/config/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
# pylint: skip-file

deid/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
import os

deid/dicom/actions/jitter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
from deid.logger import bot

deid/dicom/actions/uids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
import uuid

deid/dicom/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
import re

deid/dicom/filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
import re
@@ -23,7 +23,7 @@ def apply_filter(dicom, field, filter_name, value):
2323
2424
Parameters
2525
==========
26-
dicom: the pydicom.dataset Dataset (pydicom.read_file)
26+
dicom: the pydicom.dataset Dataset
2727
field: the name of the field to apply the filter to,
2828
or the tag number as a string '0xGGGGEEEE'
2929
filer_name: the name of the filter to apply (e.g., contains)

deid/dicom/groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55

deid/dicom/header.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55

66
import os
77

8-
from pydicom import read_file
9-
8+
import deid.dicom.utils as utils
109
from deid.dicom.parser import DicomParser
1110
from deid.dicom.utils import save_dicom
1211
from deid.logger import bot
@@ -68,7 +67,7 @@ def remove_private_identifiers(
6867
dicom_files = [dicom_files]
6968

7069
for dicom_file in dicom_files:
71-
dicom = read_file(dicom_file, force=force)
70+
dicom = utils.dcmread(dicom_file, force=force)
7271
dicom.remove_private_tags()
7372
dicom_name = os.path.basename(dicom_file)
7473
bot.debug("Removed private identifiers for %s" % dicom_name)

deid/dicom/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
import os
66
import re
77
from copy import deepcopy
88
from io import BytesIO
99

10-
from pydicom import read_file
1110
from pydicom.dataelem import DataElement
1211
from pydicom.dataset import Dataset
1312
from pydicom.tag import Tag
1413

14+
import deid.dicom.utils as utils
1515
from deid.config import DeidRecipe
1616
from deid.config.standards import actions as valid_actions
1717
from deid.dicom.actions import deid_funcs, jitter_timestamp
@@ -99,7 +99,7 @@ def load(self, dicom_file, force=True):
9999
# If we must read the file, the path must exist
100100
if not os.path.exists(dicom_file):
101101
bot.exit("%s does not exist." % dicom_file)
102-
self.dicom = read_file(dicom_file, force=force)
102+
self.dicom = utils.dcmread(dicom_file, force=force)
103103

104104
# Set class variables that might be helpful later
105105
df = self.dicom.get("filename")

deid/dicom/pixels/clean.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55

@@ -13,7 +13,6 @@
1313
import matplotlib
1414
import numpy
1515
from numpy.typing import NDArray
16-
from pydicom import read_file
1716
from pydicom.pixel_data_handlers.util import get_expected_length
1817

1918
from deid.config import DeidRecipe
@@ -245,7 +244,7 @@ def save_dicom(self, output_folder=None, image_type="cleaned"):
245244
# Having clean also means has dicom image
246245
if hasattr(self, image_type):
247246
dicom_name = self._get_clean_name(output_folder)
248-
dicom = read_file(self.dicom_file, force=True)
247+
dicom = utils.dcmread(self.dicom_file, force=True)
249248
# If going from compressed, change TransferSyntax
250249
if dicom.file_meta.TransferSyntaxUID.is_compressed is True:
251250
dicom.decompress()

deid/dicom/pixels/detect.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55

66
from typing import List, Optional, Union
77

8-
from pydicom import FileDataset, read_file
8+
from pydicom import FileDataset
99
from pydicom.sequence import Sequence
1010

11+
import deid.dicom.utils as utils
1112
from deid.config import DeidRecipe
1213
from deid.dicom.filter import apply_filter
1314
from deid.logger import bot
@@ -111,10 +112,7 @@ def _has_burned_pixels_single(dicom_file, force: bool, deid):
111112
]
112113
}
113114
"""
114-
if isinstance(dicom_file, FileDataset):
115-
dicom = dicom_file
116-
else:
117-
dicom = read_file(dicom_file, force=force)
115+
dicom = utils.load_dicom(dicom_file, force=force)
118116

119117
# Return list with lookup as dicom_file
120118
results = []

deid/dicom/tags.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
import re
@@ -123,7 +123,7 @@ def update_tag(dicom, field, value):
123123
124124
Parameters
125125
==========
126-
dicom: the pydicom.dataset Dataset (pydicom.read_file)
126+
dicom: the pydicom.dataset Dataset
127127
field: the name of the field to update
128128
value: the value to set, if name is a valid tag
129129
@@ -157,7 +157,7 @@ def get_private(dicom):
157157
158158
Parameters
159159
==========
160-
dicom: the pydicom.dataset Dataset (pydicom.read_file)
160+
dicom: the pydicom.dataset Dataset
161161
"""
162162
datasets = [dicom]
163163
private_tags = []
@@ -188,7 +188,7 @@ def has_private(dicom):
188188
189189
Parameters
190190
==========
191-
dicom: the pydicom.dataset Dataset (pydicom.read_file)
191+
dicom: the pydicom.dataset Dataset
192192
193193
"""
194194
private_tags = len(get_private(dicom))

deid/dicom/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55
import os
@@ -106,8 +106,12 @@ def save_dicom(dicom, dicom_file, output_folder=None, overwrite=False):
106106
return output_dicom
107107

108108

109-
def load_dicom(dcm_file):
109+
def load_dicom(dcm_file, force=True):
110110
if isinstance(dcm_file, FileDataset):
111111
return dcm_file
112112
else:
113-
return pydicom.read_file(dcm_file, force=True)
113+
return pydicom.dcmread(dcm_file, force=force)
114+
115+
116+
def dcmread(filename, **kwargs):
117+
return pydicom.dcmread(filename, **kwargs)

deid/dicom/validate.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

5-
from pydicom import read_file
6-
5+
import deid.dicom.utils as utils
76
from deid.logger import bot
87

98

@@ -28,7 +27,7 @@ def validate_dicoms(dcm_files, force=False):
2827
for dcm_file in dcm_files:
2928
try:
3029
with open(dcm_file, "rb") as filey:
31-
read_file(filey, force=force)
30+
utils.dcmread(filey, force=force)
3231
valids.append(dcm_file)
3332
except Exception:
3433
bot.warning("Cannot read input file {0!s}, skipping.".format(dcm_file))

deid/logger/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Vanessa Sochat"
2-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
2+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

55

deid/main/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

33
__author__ = "Vanessa Sochat"
4-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
4+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
55
__license__ = "MIT"
66

77
import argparse

deid/main/identifiers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

33
__author__ = "Vanessa Sochat"
4-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
4+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
55
__license__ = "MIT"
66

77

deid/main/inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

33
__author__ = "Vanessa Sochat"
4-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
4+
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
55
__license__ = "MIT"
66

77
import datetime

deid/tests/Xtest_dicom_header.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
#!/usr/bin/env python
22

3-
__author__ = "Vanessa Sochat"
4-
__copyright__ = "Copyright 2016-2023, Vanessa Sochat"
5-
__license__ = "MIT"
6-
7-
83
import os
94
import shutil
105
import tempfile
116
import unittest
127

138
from deid.data import get_dataset
9+
from deid.dicom import utils
1410
from deid.utils import get_installdir
1511

1612

@@ -47,15 +43,14 @@ def test_get_identifiers(self):
4743

4844
def test_replace_identifiers(self):
4945
print("Testing deid.dicom replace_identifiers")
50-
from pydicom import read_file
5146

5247
from deid.dicom import get_identifiers, replace_identifiers
5348

5449
dicom_files = get_dicom(self.dataset, return_dir=True)
5550
ids = get_identifiers(dicom_files)
5651

5752
# Before blanking, 28 fields don't have blanks
58-
notblanked = read_file(dicom_files[0])
53+
notblanked = utils.dcmread(dicom_files[0])
5954
notblanked_fields = [
6055
x for x in notblanked.dir() if notblanked.get(x) != ""
6156
] # 28
@@ -64,21 +59,20 @@ def test_replace_identifiers(self):
6459
updated_files = replace_identifiers(dicom_files, ids, output_folder=self.tmpdir)
6560

6661
# After replacing only 9 don't have blanks
67-
blanked = read_file(updated_files[0])
62+
blanked = utils.dcmread(updated_files[0])
6863
blanked_fields = [x for x in blanked.dir() if blanked.get(x) != ""]
6964
self.assertTrue(len(blanked_fields) == 9)
7065

7166

7267
def get_dicom(dataset, return_dir=False):
7368
"""helper function to load a dicom"""
74-
from pydicom import read_file
7569

7670
from deid.dicom import get_files
7771

7872
dicom_files = get_files(dataset)
7973
if return_dir:
8074
return list(dicom_files)
81-
return read_file(next(dicom_files))
75+
return utils.dcmread(next(dicom_files))
8276

8377

8478
if __name__ == "__main__":

0 commit comments

Comments
 (0)