Skip to content

Commit cc5bf29

Browse files
Merge pull request #599 from matthew-brett/pydicom-compatibility
MRG: refactoring for pydicom 1.0 Make tests pass against pydicom 1.0. Refactor CI to test pydicom master, as suggested by pydicom folks. Update minimum pydicom dependency to 0.9.9 (previous versions no longer install).
2 parents 6eacaf5 + 618d02a commit cc5bf29

File tree

6 files changed

+29
-28
lines changed

6 files changed

+29
-28
lines changed

.travis.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ cache:
1414
- $HOME/.cache/pip
1515
env:
1616
global:
17-
- DEPENDS="six numpy scipy matplotlib h5py pillow"
17+
- DEPENDS="six numpy scipy matplotlib h5py pillow pydicom"
1818
- OPTIONAL_DEPENDS=""
19-
- PYDICOM=1
2019
- INSTALL_TYPE="setup"
2120
- EXTRA_WHEELS="https://5cf40426d9f06eb7461d-6fe47d9331aba7cd62fc36c7196769e4.ssl.cf2.rackcdn.com"
2221
- PRE_WHEELS="https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com"
@@ -34,29 +33,29 @@ matrix:
3433
# Absolute minimum dependencies
3534
- python: 2.7
3635
env:
37-
- DEPENDS="numpy==1.7.1" PYDICOM=0
36+
- DEPENDS="numpy==1.7.1"
3837
# Absolute minimum dependencies plus oldest MPL
3938
# Check these against:
4039
# nibabel/info.py
4140
# doc/source/installation.rst
4241
# requirements.txt
4342
- python: 2.7
4443
env:
45-
- DEPENDS="numpy==1.7.1 matplotlib==1.3.1" PYDICOM=0
44+
- DEPENDS="numpy==1.7.1 matplotlib==1.3.1"
4645
# Minimum pydicom dependency
4746
- python: 2.7
4847
env:
49-
- DEPENDS="numpy==1.7.1 pydicom==0.9.7 pillow==2.6"
48+
- DEPENDS="numpy==1.7.1 pydicom==0.9.9 pillow==2.6"
5049
# test against numpy 1.7
5150
- python: 2.7
5251
env:
5352
- DEPENDS="numpy==1.7.1"
54-
# pydicom 1.0 (currently unreleased)
55-
- python: 2.7
53+
# pydicom master branch
54+
- python: 3.5
5655
env:
57-
- PYDICOM="v1.0"
58-
# test 2.7 against pre-release builds of everything
59-
- python: 2.7
56+
- DEPENDS="numpy git+https://github.com/pydicom/pydicom.git@master"
57+
# test 3.5 against pre-release builds of everything
58+
- python: 3.5
6059
env:
6160
- EXTRA_PIP_FLAGS="$PRE_PIP_FLAGS"
6261
# test 3.5 against pre-release builds of everything
@@ -102,14 +101,6 @@ before_install:
102101
- pip install -U pip wheel # needed at one point
103102
- retry pip install nose flake8 mock # always
104103
- pip install $EXTRA_PIP_FLAGS $DEPENDS $OPTIONAL_DEPENDS
105-
# pydicom <= 0.9.8 doesn't install on python 3
106-
- if [ "${TRAVIS_PYTHON_VERSION:0:1}" == "2" ]; then
107-
if [ "$PYDICOM" == "1" ]; then
108-
pip install pydicom;
109-
elif [ "$PYDICOM" == "v1.0" ]; then
110-
pip install git+https://github.com/darcymason/pydicom.git@43f278444d5cb2e4648135d3edcd430c363c6975;
111-
fi
112-
fi
113104
- if [ "${COVERAGE}" == "1" ]; then
114105
pip install coverage;
115106
pip install coveralls;

doc/source/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Requirements
9090
* NumPy_ 1.7.1 or greater
9191
* Six_ 1.3 or greater
9292
* SciPy_ (optional, for full SPM-ANALYZE support)
93-
* PyDICOM_ 0.9.7 or greater (optional, for DICOM support)
93+
* PyDICOM_ 0.9.9 or greater (optional, for DICOM support)
9494
* `Python Imaging Library`_ (optional, for PNG conversion in DICOMFS)
9595
* nose_ 0.11 or greater (optional, to run the tests)
9696
* mock_ (optional, to run the tests)

nibabel/info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def cmp_pkg_version(version_str, pkg_version_str=__version__):
187187
# requirements.txt
188188
# .travis.yml
189189
NUMPY_MIN_VERSION = '1.7.1'
190-
PYDICOM_MIN_VERSION = '0.9.7'
190+
PYDICOM_MIN_VERSION = '0.9.9'
191191
SIX_MIN_VERSION = '1.3'
192192

193193
# Main setup parameters

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)