Skip to content

Commit 13ae9ff

Browse files
committed
Import and doc cleanup
1 parent d897a62 commit 13ae9ff

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

doc/source/dicom/dicom_niftiheader.rst

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
DICOM Tags in the NIfTI Header
55
##############################
66

7-
NIfTI images include an extended header (see the `NIfTI Extensions Standard`_) to store, amongst others, DICOM tags and attributes. When NiBabel loads a NIfTI file containing DICOM information (a NIfTI extension with ``ecode == 2``), it parses it and returns a pydicom dataset as the content of the NIfTI extension. This can be read and written to in order to facilitate communication with software that uses specific DICOM codes found in the NIfTI header.
7+
NIfTI images include an extended header (see the `NIfTI Extensions Standard`_)
8+
to store, amongst others, DICOM tags and attributes. When NiBabel loads a NIfTI
9+
file containing DICOM information (a NIfTI extension with ``ecode == 2``), it
10+
parses it and returns a pydicom dataset as the content of the NIfTI extension.
11+
This can be read and written to in order to facilitate communication with
12+
software that uses specific DICOM codes found in the NIfTI header.
813

9-
For example, the commercial PMOD software stores the Frame Start and Duration times of images using the DICOM tags (0055, 1001) and (0055, 1004). Here's an example of an image created in PMOD with those stored times accessed through nibabel.
14+
For example, the commercial PMOD software stores the Frame Start and Duration
15+
times of images using the DICOM tags (0055, 1001) and (0055, 1004). Here's an
16+
example of an image created in PMOD with those stored times accessed through
17+
nibabel.
1018

1119
.. code:: python
1220
@@ -30,7 +38,7 @@ For example, the commercial PMOD software stores the Frame Start and Duration ti
3038
+-------------+--------------------------------+---------------------------------------------------------+
3139
|(0055, 1004) | [Frame Durations (ms) Vector] | FD: [30000.0, 30000.0, 30000.0, ..., 600000.0, 600000.0 |
3240
+-------------+--------------------------------+---------------------------------------------------------+
33-
41+
3442
Access each value as you would with pydicom::
3543
3644
>> ds = dcmext.get_content()
@@ -57,6 +65,9 @@ header, so it's possible [likely] that this information may be lost during
5765
routine use. You'll have to keep track, and re-write the information if
5866
required.
5967
68+
Optional Dependency Note: If pydicom is not installed, nibabel uses a generic
69+
:class:`nibabel.nifti1.Nifti1Extension` header instead of parsing DICOM data.
70+
6071
.. _`NIfTI Extensions Standard`: http://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields/nifti1fields_pages/extension.html
6172
6273
.. include:: links_names.txt

nibabel/tests/test_nifti1.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .. import nifti1 as nifti1
2323
from ..nifti1 import (load, Nifti1Header, Nifti1PairHeader, Nifti1Image,
2424
Nifti1Pair, Nifti1Extension, Nifti1DicomExtension,
25-
Nifti1Extensions, data_type_codes, extension_codes,
25+
Nifti1Extensions, data_type_codes, extension_codes,
2626
slice_order_codes)
2727

2828
from .test_arraywriters import rt_err_estimate, IUINT_TYPES
@@ -41,14 +41,10 @@
4141
header_file = os.path.join(data_path, 'nifti1.hdr')
4242
image_file = os.path.join(data_path, 'example4d.nii.gz')
4343

44-
try:
45-
import dicom
46-
import struct
47-
from io import BytesIO
48-
except ImportError:
49-
have_dicom = False
50-
else:
51-
have_dicom = True
44+
from nibabel.optpkg import optional_package
45+
dicom, have_dicom, _ = optional_package('dicom')
46+
import struct
47+
5248
dicom_test = np.testing.dec.skipif(not have_dicom,
5349
'could not import pydicom')
5450

@@ -1111,7 +1107,7 @@ def test_nifti_dicom_extension():
11111107
assert_equal(len(dcmext.get_content().values()), 1)
11121108
assert_equal(dcmext._mangle(dcmext.get_content()),dcmbytes_explicit)
11131109
assert_equal(dcmext.get_sizeondisk() % 16, 0)
1114-
1110+
11151111
# create a single dicom tag (Patient ID, [0010,0020]) with Implicit VR
11161112
dcmbytes_implicit = struct.pack('<HHL4s',0x10,0x20,4,'NiPy'.encode('utf-8'))
11171113
dcmext = Nifti1DicomExtension(2,dcmbytes_implicit)

0 commit comments

Comments
 (0)