Skip to content

Commit d83d81c

Browse files
committed
RF: refactoring to account for pydicom 1 changes.
See also: * pydicom/pydicom#553 * pydicom/pydicom#554 * pydicom/pydicom#555
1 parent 6eacaf5 commit d83d81c

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

nibabel/nicom/dicomwrappers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .dwiparams import B2q, nearest_pos_semi_def, q2bg
2222
from ..openers import ImageOpener
2323
from ..onetime import setattr_on_read as one_time
24-
from ..pydicom_compat import pydicom
24+
from ..pydicom_compat import tag_for_keyword
2525

2626

2727
class WrapperError(Exception):
@@ -517,7 +517,7 @@ def image_shape(self):
517517
# Determine if one of the dimension indices refers to the stack id
518518
dim_seq = [dim.DimensionIndexPointer
519519
for dim in self.get('DimensionIndexSequence')]
520-
stackid_tag = pydicom.datadict.tag_for_name('StackID')
520+
stackid_tag = tag_for_keyword('StackID')
521521
# remove the stack id axis if present
522522
if stackid_tag in dim_seq:
523523
stackid_dim_idx = dim_seq.index(stackid_tag)

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
import numpy as np
1111

12-
from nibabel.pydicom_compat import have_dicom, pydicom, read_file, dicom_test
12+
from nibabel.pydicom_compat import (have_dicom, pydicom, read_file, dicom_test,
13+
tag_for_keyword)
1314

1415
from .. import dicomwrappers as didw
1516
from .. import dicomreaders as didr
@@ -416,8 +417,8 @@ def __init__(self, div, sid):
416417
dim_idx_seq = [DimIdxSeqElem()] * num_of_frames
417418
# add an entry for StackID into the DimensionIndexSequence
418419
if sid_dim is not None:
419-
sid_tag = pydicom.datadict.tag_for_name('StackID')
420-
fcs_tag = pydicom.datadict.tag_for_name('FrameContentSequence')
420+
sid_tag = tag_for_keyword('StackID')
421+
fcs_tag = tag_for_keyword('FrameContentSequence')
421422
dim_idx_seq[sid_dim] = DimIdxSeqElem(sid_tag, fcs_tag)
422423
# create the PerFrameFunctionalGroupsSequence
423424
frames = [PerFrmFuncGrpSeqElem(div, sid)

nibabel/pydicom_compat.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
* pydicom : pydicom module or dicom module or None of not importable;
1111
* read_file : ``read_file`` function if pydicom or dicom module is importable
1212
else None;
13+
* tag_for_keyword : ``tag_for_keyword`` function if pydicom or dicom module
14+
is importable else None;
1315
* dicom_test : test decorator that skips test if dicom not available.
1416
"""
1517

16-
# Module does (apparently) unused imports; stop flake8 complaining
18+
# Module has (apparently) unused imports; stop flake8 complaining
1719
# flake8: noqa
1820

1921
import numpy as np
2022

2123
have_dicom = True
22-
read_file = None
23-
pydicom = None
24+
pydicom = read_file = tag_for_keyword = None
2425

2526
try:
2627
import dicom as pydicom
@@ -38,6 +39,14 @@
3839
else: # dicom module available
3940
read_file = pydicom.read_file
4041

42+
if have_dicom:
43+
try:
44+
# Versions >= 1.0
45+
tag_for_keyword = pydicom.datadict.tag_for_keyword
46+
except AttributeError:
47+
# Versions < 1.0 - also has more search options.
48+
tag_for_keyword = pydicom.datadict.tag_for_name
49+
4150

4251
# test decorator that skips test if dicom not available.
4352
dicom_test = np.testing.dec.skipif(not have_dicom,

0 commit comments

Comments
 (0)