BUG: Use manager to set title
1 |
""" Adapter module for working with pydicom < 1.0 and >= 1.0
|
|
2 |
|
|
3 |
In what follows, "dicom is available" means we can import either a) ``dicom``
|
|
4 |
(pydicom < 1.0) or or b) ``pydicom`` (pydicom >= 1.0).
|
|
5 |
|
|
6 |
Regardless of whether dicom is available this module should be importable
|
|
7 |
without error, and always defines:
|
|
8 |
|
|
9 |
* have_dicom : True if we can import pydicom or dicom;
|
|
10 |
* pydicom : pydicom module or dicom module or None of not importable;
|
|
11 |
* read_file : ``read_file`` function if pydicom or dicom module is importable
|
|
12 |
else None;
|
|
13 |
* tag_for_keyword : ``tag_for_keyword`` function if pydicom or dicom module
|
|
14 |
is importable else None;
|
|
15 |
|
|
16 |
A test decorator is available in nibabel.nicom.tests:
|
|
17 |
|
|
18 |
* dicom_test : test decorator that skips test if dicom not available.
|
|
19 |
|
|
20 |
A deprecated copy is available here for backward compatibility.
|
|
21 |
"""
|
|
22 |
|
|
23 |
# Module has (apparently) unused imports; stop flake8 complaining
|
|
24 |
# flake8: noqa
|
|
25 |
|
|
26 | 33 |
import numpy as np |
27 | 33 |
from .deprecated import deprecate_with_version |
28 |
|
|
29 | 33 |
have_dicom = True |
30 | 33 |
pydicom = read_file = tag_for_keyword = Sequence = None |
31 |
|
|
32 | 33 |
try: |
33 | 33 |
import dicom as pydicom |
34 | 31 |
except ImportError: |
35 | 31 |
try: |
36 | 31 |
import pydicom |
37 | 8 |
except ImportError: |
38 | 8 |
have_dicom = False |
39 |
else: # pydicom module available |
|
40 | 23 |
from pydicom.dicomio import read_file |
41 | 23 |
from pydicom.sequence import Sequence |
42 |
# Values not imported by default
|
|
43 | 23 |
import pydicom.values |
44 |
else: # dicom module available |
|
45 |
# Values not imported by default
|
|
46 | 2 |
import dicom.values |
47 | 2 |
from dicom.sequence import Sequence |
48 | 2 |
read_file = pydicom.read_file |
49 |
|
|
50 |
if have_dicom: |
|
51 | 25 |
try: |
52 |
# Versions >= 1.0
|
|
53 | 25 |
tag_for_keyword = pydicom.datadict.tag_for_keyword |
54 | 2 |
except AttributeError: |
55 |
# Versions < 1.0 - also has more search options.
|
|
56 | 2 |
tag_for_keyword = pydicom.datadict.tag_for_name |
57 |
|
|
58 |
|
|
59 | 33 |
@deprecate_with_version("dicom_test has been moved to nibabel.nicom.tests", |
60 |
since="3.1", until="5.0") |
|
61 | 5 |
def dicom_test(func): |
62 |
# Import locally to avoid circular dependency
|
|
63 |
from .nicom.tests import dicom_test |
|
64 |
return dicom_test(func) |
Read our documentation on viewing source code .