Skip to content

Commit 8e81d32

Browse files
committed
Merge remote-tracking branch 'upstream/master' into rel/2.4.0
2 parents 42f3c9b + a59f3b0 commit 8e81d32

19 files changed

+2410
-53
lines changed

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ matrix:
3333
# Absolute minimum dependencies
3434
- python: 2.7
3535
env:
36-
- DEPENDS="numpy==1.7.1"
36+
- DEPENDS="numpy==1.8"
3737
# Absolute minimum dependencies
3838
- python: 2.7
3939
env:
40-
- DEPENDS="numpy==1.7.1"
40+
- DEPENDS="numpy==1.8"
4141
- CHECK_TYPE="import"
4242
# Absolute minimum dependencies plus oldest MPL
4343
# Check these against:
@@ -46,11 +46,11 @@ matrix:
4646
# requirements.txt
4747
- python: 2.7
4848
env:
49-
- DEPENDS="numpy==1.7.1 matplotlib==1.3.1"
49+
- DEPENDS="numpy==1.8 matplotlib==1.3.1"
5050
# Minimum pydicom dependency
5151
- python: 2.7
5252
env:
53-
- DEPENDS="numpy==1.7.1 pydicom==0.9.9 pillow==2.6"
53+
- DEPENDS="numpy==1.8 pydicom==0.9.9 pillow==2.6"
5454
# pydicom master branch
5555
- python: 3.5
5656
env:

appveyor.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ install:
2121
# the parent CMD process).
2222
- SET PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%
2323

24+
- python -m pip install --upgrade pip virtualenv
25+
- virtualenv --python=python venv
26+
- venv\Scripts\activate
27+
- python --version
28+
2429
# Install the dependencies of the project.
25-
- python -m pip install --upgrade pip setuptools wheel
30+
- pip install --upgrade pip setuptools>=27.0 wheel
2631
- pip install numpy scipy matplotlib h5py pydicom
2732
- pip install nose mock coverage codecov
2833
- pip install .

doc/source/api.rst

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ File Formats
2323
analyze
2424
spm2analyze
2525
spm99analyze
26+
cifti2
2627
gifti
2728
freesurfer
2829
minc1

doc/source/installation.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Requirements
8787
.travis.yml
8888
8989
* Python_ 2.7, or >= 3.4
90-
* NumPy_ 1.7.1 or greater
90+
* NumPy_ 1.8 or greater
9191
* Six_ 1.3 or greater
9292
* SciPy_ (optional, for full SPM-ANALYZE support)
9393
* PyDICOM_ 0.9.9 or greater (optional, for DICOM support)

nibabel/cifti2/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
# copyright and license terms.
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9-
"""CIfTI format IO
9+
"""CIFTI-2 format IO
1010
1111
.. currentmodule:: nibabel.cifti2
1212
1313
.. autosummary::
1414
:toctree: ../generated
1515
1616
cifti2
17+
cifti2_axes
1718
"""
1819

1920
from .parse_cifti2 import Cifti2Extension
@@ -25,3 +26,4 @@
2526
Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ,
2627
Cifti2Vertices, Cifti2Volume, CIFTI_BRAIN_STRUCTURES,
2728
Cifti2HeaderError, CIFTI_MODEL_TYPES, load, save)
29+
from .cifti2_axes import (Axis, BrainModelAxis, ParcelsAxis, SeriesAxis, LabelAxis, ScalarAxis)

nibabel/cifti2/cifti2.py

+58-23
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66
# copyright and license terms.
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9-
''' Read / write access to CIfTI2 image format
9+
''' Read / write access to CIFTI-2 image format
1010
1111
Format of the NIFTI2 container format described here:
1212
1313
http://www.nitrc.org/forum/message.php?msg_id=3738
1414
15-
Definition of the CIFTI2 header format and file extensions attached to this
16-
email:
15+
Definition of the CIFTI-2 header format and file extensions can be found at:
1716
18-
http://www.nitrc.org/forum/forum.php?thread_id=4380&forum_id=1955
19-
20-
Filename is ``CIFTI-2_Main_FINAL_1March2014.pdf``.
17+
http://www.nitrc.org/projects/cifti
2118
'''
2219
from __future__ import division, print_function, absolute_import
2320
import re
@@ -42,7 +39,7 @@ def _float_01(val):
4239

4340

4441
class Cifti2HeaderError(Exception):
45-
""" Error in CIFTI2 header
42+
""" Error in CIFTI-2 header
4643
"""
4744

4845

@@ -178,7 +175,7 @@ def _to_xml_element(self):
178175

179176

180177
class Cifti2LabelTable(xml.XmlSerializable, MutableMapping):
181-
""" CIFTI2 label table: a sequence of ``Cifti2Label``s
178+
""" CIFTI-2 label table: a sequence of ``Cifti2Label``s
182179
183180
* Description - Used by NamedMap when IndicesMapToDataType is
184181
"CIFTI_INDEX_TYPE_LABELS" in order to associate names and display colors
@@ -236,7 +233,7 @@ def _to_xml_element(self):
236233

237234

238235
class Cifti2Label(xml.XmlSerializable):
239-
""" CIFTI2 label: association of integer key with a name and RGBA values
236+
""" CIFTI-2 label: association of integer key with a name and RGBA values
240237
241238
For all color components, value is floating point with range 0.0 to 1.0.
242239
@@ -314,7 +311,7 @@ def _to_xml_element(self):
314311

315312

316313
class Cifti2NamedMap(xml.XmlSerializable):
317-
"""CIFTI2 named map: association of name and optional data with a map index
314+
"""CIFTI-2 named map: association of name and optional data with a map index
318315
319316
Associates a name, optional metadata, and possibly a LabelTable with an
320317
index in a map.
@@ -432,7 +429,7 @@ def _to_xml_element(self):
432429

433430

434431
class Cifti2VoxelIndicesIJK(xml.XmlSerializable, MutableSequence):
435-
"""CIFTI2 VoxelIndicesIJK: Set of voxel indices contained in a structure
432+
"""CIFTI-2 VoxelIndicesIJK: Set of voxel indices contained in a structure
436433
437434
* Description - Identifies the voxels that model a brain structure, or
438435
participate in a parcel. Note that when this is a child of BrainModel,
@@ -514,7 +511,7 @@ def _to_xml_element(self):
514511

515512

516513
class Cifti2Vertices(xml.XmlSerializable, MutableSequence):
517-
"""CIFTI2 vertices - association of brain structure and a list of vertices
514+
"""CIFTI-2 vertices - association of brain structure and a list of vertices
518515
519516
* Description - Contains a BrainStructure type and a list of vertex indices
520517
within a Parcel.
@@ -580,7 +577,7 @@ def _to_xml_element(self):
580577

581578

582579
class Cifti2Parcel(xml.XmlSerializable):
583-
"""CIFTI2 parcel: association of a name with vertices and/or voxels
580+
"""CIFTI-2 parcel: association of a name with vertices and/or voxels
584581
585582
* Description - Associates a name, plus vertices and/or voxels, with an
586583
index.
@@ -695,7 +692,7 @@ def _to_xml_element(self):
695692

696693

697694
class Cifti2Volume(xml.XmlSerializable):
698-
"""CIFTI2 volume: information about a volume for mappings that use voxels
695+
"""CIFTI-2 volume: information about a volume for mappings that use voxels
699696
700697
* Description - Provides information about the volume for any mappings that
701698
use voxels.
@@ -738,7 +735,7 @@ def _to_xml_element(self):
738735

739736

740737
class Cifti2VertexIndices(xml.XmlSerializable, MutableSequence):
741-
"""CIFTI2 vertex indices: vertex indices for an associated brain model
738+
"""CIFTI-2 vertex indices: vertex indices for an associated brain model
742739
743740
The vertex indices (which are independent for each surface, and
744741
zero-based) that are used in this brain model[.] The parent
@@ -1081,7 +1078,7 @@ def _to_xml_element(self):
10811078

10821079

10831080
class Cifti2Matrix(xml.XmlSerializable, MutableSequence):
1084-
""" CIFTI2 Matrix object
1081+
""" CIFTI-2 Matrix object
10851082
10861083
This is a list-like container where the elements are instances of
10871084
:class:`Cifti2MatrixIndicesMap`.
@@ -1213,7 +1210,7 @@ def _to_xml_element(self):
12131210

12141211

12151212
class Cifti2Header(FileBasedHeader, xml.XmlSerializable):
1216-
''' Class for CIFTI2 header extension '''
1213+
''' Class for CIFTI-2 header extension '''
12171214

12181215
def __init__(self, matrix=None, version="2.0"):
12191216
FileBasedHeader.__init__(self)
@@ -1268,9 +1265,43 @@ def get_index_map(self, index):
12681265
'''
12691266
return self.matrix.get_index_map(index)
12701267

1268+
def get_axis(self, index):
1269+
'''
1270+
Generates the Cifti2 axis for a given dimension
1271+
1272+
Parameters
1273+
----------
1274+
index : int
1275+
Dimension for which we want to obtain the mapping.
1276+
1277+
Returns
1278+
-------
1279+
axis : :class:`.cifti2_axes.Axis`
1280+
'''
1281+
from . import cifti2_axes
1282+
return cifti2_axes.from_index_mapping(self.matrix.get_index_map(index))
1283+
1284+
@classmethod
1285+
def from_axes(cls, axes):
1286+
'''
1287+
Creates a new Cifti2 header based on the Cifti2 axes
1288+
1289+
Parameters
1290+
----------
1291+
axes : tuple of :class`.cifti2_axes.Axis`
1292+
sequence of Cifti2 axes describing each row/column of the matrix to be stored
1293+
1294+
Returns
1295+
-------
1296+
header : Cifti2Header
1297+
new header describing the rows/columns in a format consistent with Cifti2
1298+
'''
1299+
from . import cifti2_axes
1300+
return cifti2_axes.to_header(axes)
1301+
12711302

12721303
class Cifti2Image(DataobjImage):
1273-
""" Class for single file CIFTI2 format image
1304+
""" Class for single file CIFTI-2 format image
12741305
"""
12751306
header_class = Cifti2Header
12761307
valid_exts = Nifti2Image.valid_exts
@@ -1297,15 +1328,19 @@ def __init__(self,
12971328
Object containing image data. It should be some object that
12981329
returns an array from ``np.asanyarray``. It should have a
12991330
``shape`` attribute or property.
1300-
header : Cifti2Header instance
1301-
Header with data for / from XML part of CIFTI2 format.
1331+
header : Cifti2Header instance or sequence of :class:`cifti2_axes.Axis`
1332+
Header with data for / from XML part of CIFTI-2 format.
1333+
Alternatively a sequence of cifti2_axes.Axis objects can be provided
1334+
describing each dimension of the array.
13021335
nifti_header : None or mapping or NIfTI2 header instance, optional
13031336
Metadata for NIfTI2 component of this format.
13041337
extra : None or mapping
13051338
Extra metadata not captured by `header` or `nifti_header`.
13061339
file_map : mapping, optional
13071340
Mapping giving file information for this image format.
13081341
'''
1342+
if not isinstance(header, Cifti2Header) and header:
1343+
header = Cifti2Header.from_axes(header)
13091344
super(Cifti2Image, self).__init__(dataobj, header=header,
13101345
extra=extra, file_map=file_map)
13111346
self._nifti_header = Nifti2Header.from_header(nifti_header)
@@ -1321,7 +1356,7 @@ def nifti_header(self):
13211356

13221357
@classmethod
13231358
def from_file_map(klass, file_map):
1324-
""" Load a CIFTI2 image from a file_map
1359+
""" Load a CIFTI-2 image from a file_map
13251360
13261361
Parameters
13271362
----------
@@ -1341,7 +1376,7 @@ def from_file_map(klass, file_map):
13411376
cifti_header = item.get_content()
13421377
break
13431378
else:
1344-
raise ValueError('NIfTI2 header does not contain a CIFTI2 '
1379+
raise ValueError('NIfTI2 header does not contain a CIFTI-2 '
13451380
'extension')
13461381

13471382
# Construct cifti image.
@@ -1400,7 +1435,7 @@ def to_file_map(self, file_map=None):
14001435
img.to_file_map(file_map or self.file_map)
14011436

14021437
def update_headers(self):
1403-
''' Harmonize CIFTI2 and NIfTI headers with image data
1438+
''' Harmonize CIFTI-2 and NIfTI headers with image data
14041439
14051440
>>> import numpy as np
14061441
>>> data = np.zeros((2,3,4))

0 commit comments

Comments
 (0)