/usr/lib/python3/dist-packages/nibabel/imageclasses.py is in python3-nibabel 2.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | # emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
# See COPYING file distributed along with the NiBabel package for the
# copyright and license terms.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
''' Define supported image classes and names '''
from .analyze import AnalyzeImage
from .cifti2 import Cifti2Image
from .freesurfer import MGHImage
from .gifti import GiftiImage
from .minc1 import Minc1Image
from .minc2 import Minc2Image
from .nifti1 import Nifti1Pair, Nifti1Image
from .nifti2 import Nifti2Pair, Nifti2Image
from .parrec import PARRECImage
from .spm99analyze import Spm99AnalyzeImage
from .spm2analyze import Spm2AnalyzeImage
from .volumeutils import Recoder
from .deprecated import deprecate_with_version
from .optpkg import optional_package
_, have_scipy, _ = optional_package('scipy')
# Ordered by the load/save priority.
all_image_classes = [Nifti1Pair, Nifti1Image, Nifti2Pair,
Cifti2Image, Nifti2Image, # Cifti2 before Nifti2
Spm2AnalyzeImage, Spm99AnalyzeImage, AnalyzeImage,
Minc1Image, Minc2Image, MGHImage,
PARRECImage, GiftiImage]
# DEPRECATED: mapping of names to classes and class functionality
class ClassMapDict(dict):
@deprecate_with_version('class_map is deprecated.',
'2.1', '4.0')
def __getitem__(self, *args, **kwargs):
return super(ClassMapDict, self).__getitem__(*args, **kwargs)
class_map = ClassMapDict(
analyze={'class': AnalyzeImage, # Image class
'ext': '.img', # characteristic image extension
'has_affine': False, # class can store an affine
'makeable': True, # empty image can be easily made in memory
'rw': True}, # image can be written
spm99analyze={'class': Spm99AnalyzeImage,
'ext': '.img',
'has_affine': True,
'makeable': True,
'rw': have_scipy},
spm2analyze={'class': Spm2AnalyzeImage,
'ext': '.img',
'has_affine': True,
'makeable': True,
'rw': have_scipy},
nifti_pair={'class': Nifti1Pair,
'ext': '.img',
'has_affine': True,
'makeable': True,
'rw': True},
nifti_single={'class': Nifti1Image,
'ext': '.nii',
'has_affine': True,
'makeable': True,
'rw': True},
minc={'class': Minc1Image,
'ext': '.mnc',
'has_affine': True,
'makeable': True,
'rw': False},
mgh={'class': MGHImage,
'ext': '.mgh',
'has_affine': True,
'makeable': True,
'rw': True},
mgz={'class': MGHImage,
'ext': '.mgz',
'has_affine': True,
'makeable': True,
'rw': True},
par={'class': PARRECImage,
'ext': '.par',
'has_affine': True,
'makeable': False,
'rw': False})
class ExtMapRecoder(Recoder):
@deprecate_with_version('ext_map is deprecated.',
'2.1', '4.0')
def __getitem__(self, *args, **kwargs):
return super(ExtMapRecoder, self).__getitem__(*args, **kwargs)
# mapping of extensions to default image class names
ext_map = ExtMapRecoder((
('nifti_single', '.nii'),
('nifti_pair', '.img', '.hdr'),
('minc', '.mnc'),
('mgh', '.mgh'),
('mgz', '.mgz'),
('par', '.par'),
))
# Image classes known to require spatial axes to be first in index ordering.
# When adding an image class, consider whether the new class should be listed
# here.
KNOWN_SPATIAL_FIRST = (Nifti1Pair, Nifti1Image, Nifti2Pair, Nifti2Image,
Spm2AnalyzeImage, Spm99AnalyzeImage, AnalyzeImage,
MGHImage, PARRECImage)
def spatial_axes_first(img):
""" True if spatial image axes for `img` always preceed other axes
Parameters
----------
img : object
Image object implementing at least ``shape`` attribute.
Returns
-------
spatial_axes_first : bool
True if image only has spatial axes (number of axes < 4) or image type
known to have spatial axes preceeding other axes.
"""
if len(img.shape) < 4:
return True
return type(img) in KNOWN_SPATIAL_FIRST
|