Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: CIFTI2 spec reader and writer #249

Merged
merged 189 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from 183 commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
6fa78bc
enh: first pass at the cifti2 reader
satra Aug 1, 2014
e80b4bc
fix: remove cifti element spec
satra Aug 1, 2014
2262b73
enh: cifti writer enabled
satra Aug 2, 2014
db0d2af
ref: initial refactor towards cifti datatypes
satra Aug 4, 2014
c862285
fix: updated to reflect latest CIFTI-2 spec and nifti extensions
satra Aug 4, 2014
645edaa
tst: added test data
satra Aug 4, 2014
3d19b50
fix: voxelindicesijk initialization, header version check, typo in er…
satra Aug 4, 2014
e1ab596
fix: version number for looseversion
satra Aug 4, 2014
8b0feb6
tst: added basic io tests
satra Aug 4, 2014
75a2906
fix: removed redundant file writing
satra Aug 4, 2014
cc72b49
fix: unicode in docstring
satra Aug 4, 2014
9a092d5
fix: py3k bytes reading for numpy
satra Aug 4, 2014
dffd0fb
fix: move cifti to check to top level function
satra Aug 4, 2014
4592905
fix: started cleaning up classes - removing prints and adding tests
satra Aug 4, 2014
501c352
adding some cifti properties
satra Apr 29, 2015
503875e
fix: conflict with cifti additions
satra Apr 29, 2015
dbd7bfc
Merge remote-tracking branch 'upstream/master' into enh/cifti2
satra Jun 2, 2015
b6fcb50
fix: resolved conflict
satra Jul 8, 2015
a55e92f
Merge remote-tracking branch 'upstream/master' into enh/cifti2
satra Jul 30, 2015
ec031a0
BUG: Fixed string encoding for python 3
MichielCottaar Aug 28, 2015
ecc4892
Merge pull request #1 from MichielCottaar/enh/cifti_python3
satra Aug 31, 2015
4668e26
fix: resolved conflicts
satra Oct 20, 2015
3c9918a
Merge remote-tracking branch 'origin/enh/cifti2' into enh/cifti2
satra Oct 20, 2015
d03f68d
Merge remote-tracking branch 'upstream/master' into c2
Oct 27, 2015
5f2afe2
Merge remote-tracking branch 'upstream/master' into enh/cifti2
satra Nov 14, 2015
71e2e1b
BF: files must be makeable (they're made!) for this test.
Oct 27, 2015
9eb7ae8
save conversion logic is not as strong as needed (should really use m…
Oct 27, 2015
419da77
Localize Cifti to /cifti; use nib.load/save
Feb 7, 2016
4d65a82
ENH: add xmlutils.XmlParser
Feb 7, 2016
0ca2ef8
Use _to_xml_element, snake_case properties, remove numXXX props, neve…
Oct 28, 2015
7fa2e62
Use assert_equal(a,b) instead of assert_true(a==b)
Oct 28, 2015
3dd6ddd
fix: move intent_codes.
Feb 7, 2016
d94260a
fix: no xmlimage
Feb 7, 2016
a044a1f
Merge branch 'flake8-in-travis' into satra/enh/cifti2
Feb 7, 2016
03b60d9
STY: pep8 updates
Feb 7, 2016
1c4591b
Add a write_morph_data function.
Jun 13, 2015
86f44f8
Add a write_morph_data function.
Jul 7, 2015
060dcec
cifti=>cifti2, Cifti=>Cifti2
Sep 12, 2015
8b5ac2e
FIX: Take care of byte vs. string / BytesIO vs. StringIO encodings fo…
Sep 12, 2015
ea30b03
Merge pull request #3 from bcipolli/satra/enh/cifti2
bcipolli Feb 7, 2016
9a3fb6f
Merge remote-tracking branch 'upstream/master' into enh/cifti2
Feb 7, 2016
5354bd0
FIX: import reduce for python3
MichielCottaar Feb 15, 2016
4a7ef3a
FIX: removed encode on a bytes object
MichielCottaar Feb 15, 2016
5be1144
Merge pull request #4 from MichielCottaar/enh/cifti2-python3
satra Feb 15, 2016
ceb0900
FIX: allow applies_to_matrix_dimension to be a comma-seperate list
MichielCottaar Feb 15, 2016
9f22915
Merge pull request #5 from MichielCottaar/enh/cifti2-dconn
satra Feb 16, 2016
8f7297f
RF: Switch to locally-defined underscore function
effigies Feb 19, 2016
b95ce80
BF: Update Cifti2Label._to_xml_element
effigies Feb 29, 2016
e5d6443
TST: Exercise Cifti2 classes more thoroughly
effigies Feb 29, 2016
3ef28f5
BF: Add label_table to named_map structure
effigies Feb 29, 2016
f5de829
Merge pull request #6 from effigies/enh/cifti2
satra Mar 1, 2016
ca37d4c
fix: resolved conflict
satra Mar 2, 2016
2e4a483
DOC: Update docstrings
effigies Mar 4, 2016
7ad3133
Merge pull request #7 from effigies/cifti2_docstrings
satra Apr 10, 2016
dcb3c0c
Merge remote-tracking branch 'upstream/master' into enh/cifti2
satra Jun 3, 2016
474d331
Merge remote-tracking branch 'origin/enh/cifti2' into enh/cifti2
satra Jun 3, 2016
97942fa
fix: resolved conflict
satra Jun 11, 2016
9caabb9
Merge remote-tracking branch 'upstream/master' into enh/cifti2
satra Jul 20, 2016
c1eb9bc
enh: first pass at the cifti2 reader
satra Aug 1, 2014
ca66f5e
fix: remove cifti element spec
satra Aug 1, 2014
8482495
enh: cifti writer enabled
satra Aug 2, 2014
3d73dff
ref: initial refactor towards cifti datatypes
satra Aug 4, 2014
7551209
fix: updated to reflect latest CIFTI-2 spec and nifti extensions
satra Aug 4, 2014
cad2032
tst: added test data
satra Aug 4, 2014
9c7dd28
fix: voxelindicesijk initialization, header version check, typo in er…
satra Aug 4, 2014
fdec65b
fix: version number for looseversion
satra Aug 4, 2014
7d0a80e
tst: added basic io tests
satra Aug 4, 2014
0c06213
fix: removed redundant file writing
satra Aug 4, 2014
ab34b94
fix: unicode in docstring
satra Aug 4, 2014
20d6a54
fix: py3k bytes reading for numpy
satra Aug 4, 2014
ca47113
fix: move cifti to check to top level function
satra Aug 4, 2014
f9a694f
fix: started cleaning up classes - removing prints and adding tests
satra Aug 4, 2014
73ba2f6
adding some cifti properties
satra Apr 29, 2015
ba174f9
BUG: Fixed string encoding for python 3
MichielCottaar Aug 28, 2015
5289189
BF: files must be makeable (they're made!) for this test.
Oct 27, 2015
d9476b2
save conversion logic is not as strong as needed (should really use m…
Oct 27, 2015
dd0f897
Localize Cifti to /cifti; use nib.load/save
Feb 7, 2016
f199da5
Use _to_xml_element, snake_case properties, remove numXXX props, neve…
Oct 28, 2015
5106a5a
Use assert_equal(a,b) instead of assert_true(a==b)
Oct 28, 2015
67abcaf
fix: move intent_codes.
Feb 7, 2016
044a62a
fix: no xmlimage
Feb 7, 2016
54cc1b8
STY: pep8 updates
Feb 7, 2016
d980dab
cifti=>cifti2, Cifti=>Cifti2
Sep 12, 2015
c2486c5
FIX: Take care of byte vs. string / BytesIO vs. StringIO encodings fo…
Sep 12, 2015
41c8d9a
FIX: import reduce for python3
MichielCottaar Feb 15, 2016
0d0dee4
FIX: removed encode on a bytes object
MichielCottaar Feb 15, 2016
36e4c84
FIX: allow applies_to_matrix_dimension to be a comma-seperate list
MichielCottaar Feb 15, 2016
13f156d
RF: Switch to locally-defined underscore function
effigies Feb 19, 2016
805455f
BF: Update Cifti2Label._to_xml_element
effigies Feb 29, 2016
33cd7c9
TST: Exercise Cifti2 classes more thoroughly
effigies Feb 29, 2016
ecd2267
BF: Add label_table to named_map structure
effigies Feb 29, 2016
42f8075
DOC: Update docstrings
effigies Mar 4, 2016
57cdf36
Fix Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ to_xml method
demianw Aug 3, 2016
31a3434
Changed the cifti2.py assertions for exceptions
demianw Aug 3, 2016
23487f3
Changed the parse_cifti2_fast.py assertions for exceptions
demianw Aug 3, 2016
b156f73
Fixed MetaData and its testing
demianw Aug 4, 2016
7980b13
Exporting the CIFTIHeaderException to the cifti2 namespace
demianw Aug 4, 2016
6082c4c
Improved verification/compatibility of the label object with the stan…
demianw Aug 9, 2016
db55bdc
All elements below MatrixIndicesMap fixed and tested
demianw Aug 9, 2016
90c4aae
Newline homogeneization
demianw Aug 9, 2016
b11aec3
Fixed header information
demianw Aug 10, 2016
c9452b1
Cleaned the metaclass helpers
demianw Aug 10, 2016
1246310
Fixed docstring
demianw Aug 10, 2016
9207cff
Fixed style and function of MetaData
demianw Aug 10, 2016
1565f3b
MetaData now behaves like a mapping
demianw Aug 10, 2016
81727ad
Interface of LabelTable closer to that of Sequence
demianw Aug 10, 2016
e7272df
Better agreement between the Label element and its specification
demianw Aug 10, 2016
b305826
Several docstring fixes as well as removed the squeeze
demianw Aug 10, 2016
04a961b
Code cleaned
demianw Aug 10, 2016
6cc4c1b
Code cleanup
demianw Aug 10, 2016
2bd867e
Fixed docstring
demianw Aug 10, 2016
20a67b4
Removed comments
demianw Aug 10, 2016
d34edb1
Added submodule for CIFTI2 testing
demianw Aug 10, 2016
9388fe4
Added test data as submodule
demianw Aug 10, 2016
c23bee7
Added more I/O tests fixed load/save functions:
demianw Aug 10, 2016
6865feb
CIFTI2: MetaData and LabelTable now behave like MutableMapping
demianw Aug 10, 2016
ba09103
CIFTI2: MatrixIndicesMap has a MutableSequence behavior
demianw Aug 10, 2016
7751664
Simplified testing by assuming that the parsed header is correct
demianw Aug 10, 2016
aa7191d
CIFTI2 Improved MatrixIndecesMap interface
demianw Aug 10, 2016
4a9131e
CIFTI2 Cleanup
demianw Aug 10, 2016
27d069a
CIFTI2 simplifications in implementation and testing due to the new i…
demianw Aug 10, 2016
9a2d7be
Compatibility with new/future nifti interface
demianw Aug 10, 2016
db6a468
Fix testing dependency on lxml
demianw Aug 10, 2016
739e00f
RF+BF: refactor error checking for CIFTI2 headers
matthew-brett Aug 10, 2016
0e8c4a8
RF: set CIFTI2 pixdims to 1 when qform code 0
matthew-brett Aug 10, 2016
f95cb5b
VertexIndices and VoxelIndicesIJK now have a MutableSequence interface
demianw Aug 10, 2016
41875ad
Improved testing coverage
demianw Aug 10, 2016
f73dcf4
RF: avoid deprecated `getchildren` Element method
matthew-brett Aug 10, 2016
aeb66db
RF: use image.header instead of image.get_header()
matthew-brett Aug 10, 2016
4e1f7d6
Better handling of volumes in the MatrixIndicesMap
demianw Aug 11, 2016
5e0ee6e
Deleted intent_code restriction
demianw Aug 11, 2016
361f953
Removed lxml dependency
demianw Aug 11, 2016
c8bd752
Increased testing coverage and removed residual methods
demianw Aug 11, 2016
45cc854
Clarified code in _Cifti2AsNiftiImage __init__
demianw Aug 11, 2016
3bac385
Changed Cifti2Vertices such that it behaves like a sequence. Added co…
demianw Aug 11, 2016
0ba811c
Address comments
effigies Aug 11, 2016
c2dbd16
Icreased testing coverage. Cleaned up code
demianw Aug 11, 2016
fef51b8
Corrected problem in new nifti header checks
demianw Aug 12, 2016
58fae01
Increased testing coverage and code cleanup
demianw Aug 12, 2016
06313c9
Fixed python 2.7 incompatibility in tests
demianw Aug 12, 2016
a042e27
MAINT: PEP8 and import cleanup for cifti2 tests
matthew-brett Aug 12, 2016
c6193e9
RF+DOC: refactor log_chk into own function
matthew-brett Aug 13, 2016
a5cd5db
RF+TST: refactor various analyze / nifti checks
matthew-brett Aug 13, 2016
f5866a9
Removed commented code
demianw Aug 13, 2016
bcbfb78
RF: refactor labeltable checking
matthew-brett Aug 13, 2016
b7a3326
Remove affine attribute from CIFTI2 image __init__
demianw Aug 13, 2016
90f2a4c
CIFTI2 reading now is performed without loaading all file from disk
demianw Aug 13, 2016
fecd0f2
MetaData can be built from a mapping
demianw Aug 13, 2016
61fc9a7
Improved docstring of Cifti2BrainModel
demianw Aug 13, 2016
33ed37a
Improved docstring of Cifti2MatrixIndicesMap
demianw Aug 13, 2016
ac3f0a6
Code clean
demianw Aug 13, 2016
bd94e5b
Code clean
demianw Aug 13, 2016
c90a7b5
Renamed parse_cifti2_fast to parse_cifti2
demianw Aug 13, 2016
c3ec7f0
RF: refactor array proxy generator for indentation
matthew-brett Aug 13, 2016
3d21376
NF: add reshape_dataobj function
matthew-brett Aug 13, 2016
df47554
NF+TST: add dtype attribute to Analyze arrayproxy
matthew-brett Aug 13, 2016
97405ad
RF: split up image API tester into mixins
matthew-brett Aug 13, 2016
42501a5
RF+TST: refactor dataobj attribute into own class
matthew-brett Aug 13, 2016
2dffa52
TST: add tests for FileBasedHeader objects
matthew-brett Aug 14, 2016
9af9f4f
RF: refactor Cifti2Image API
matthew-brett Aug 14, 2016
4a33af1
RF+TST: drop CIFTI Matrix check, add tests
matthew-brett Aug 14, 2016
7ca5338
DOC: add text from CIFTI2 specification
matthew-brett Aug 14, 2016
aeb7f80
RF+DOC: more cleanup of docs, some refactoring
matthew-brett Aug 14, 2016
068d9ac
Renamed CIFTI2HeaderError to Cifti2HeaderError
demianw Aug 14, 2016
ef57b77
Unified the CIFTI2 spelling in the documentation
demianw Aug 14, 2016
a83b523
Fixed documentation typo
demianw Aug 15, 2016
0c429fe
TEST: Move shape API tests into DataInterfaceMixin
effigies Aug 15, 2016
2b1dd2f
fix: resolved conflicts
satra Aug 24, 2016
c0edd58
fix: Brainstructures import name
satra Aug 24, 2016
ed28056
removed accidentally introduced parse cifti2 fast
satra Aug 26, 2016
fe36d47
removed data folder
satra Aug 26, 2016
060e65a
added extra line
satra Aug 26, 2016
2a2ad9c
Added convenience functions
demianw Aug 26, 2016
a4a6c8e
Merge remote-tracking branch 'upstream/master' into enh/cifti2
satra Aug 26, 2016
0df5209
a fix for internal variable name and more tests
satra Aug 28, 2016
0964d6d
Merge remote-tracking branch 'upstream/master' into enh/cifti2
satra Dec 3, 2016
6d0ac2f
TEST: reads in all CIFTI axis types and check the output
MichielCottaar Feb 3, 2017
3ced10a
BF: labels in a dlabel file are loaded as string rather than bytes in…
MichielCottaar Feb 3, 2017
f651b07
TEST: create most CIFTI file types from scratch and read them back in
MichielCottaar Feb 3, 2017
badbbca
TEST: define volume dimensions, affine & number of vertices
MichielCottaar Feb 3, 2017
62c56fe
BF: ensure that voxel indices have the correct shape
MichielCottaar Feb 3, 2017
6591cf4
Merge pull request #16 from MichielCottaar/enh/cifti2-tests
satra Feb 3, 2017
2c3350b
Merge remote-tracking branch 'upstream/master' into enh/cifti2
satra Feb 4, 2017
2fa22d1
adding newline
satra Feb 4, 2017
72fcdc9
resolved conflict
satra Feb 15, 2017
4b389e9
BF: delete images to allow Windows to delete dir
matthew-brett Feb 16, 2017
ab1801f
Merge pull request #17 from matthew-brett/cifti-fix
satra Feb 16, 2017
e4f3176
PEP8: test file
satra Feb 17, 2017
9e1de24
ref: if formulation
satra Feb 17, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "nibabel-data/parrec_oblique"]
path = nibabel-data/parrec_oblique
url = https://github.com/grlee77/parrec_oblique.git
[submodule "nibabel-data/nitest-cifti2"]
path = nibabel-data/nitest-cifti2
url = https://github.com/demianw/nibabel-nitest-cifti2.git
1 change: 1 addition & 0 deletions nibabel-data/nitest-cifti2
Submodule nitest-cifti2 added at 26b7cb
1 change: 1 addition & 0 deletions nibabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from .nifti2 import Nifti2Header, Nifti2Image, Nifti2Pair
from .minc1 import Minc1Image
from .minc2 import Minc2Image
from .cifti2 import Cifti2Header, Cifti2Image
# Deprecated backwards compatiblity for MINC1
from .deprecated import ModuleProxy as _ModuleProxy
minc = _ModuleProxy('nibabel.minc')
Expand Down
21 changes: 17 additions & 4 deletions nibabel/arrayproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"""
import warnings

import numpy as np

from .volumeutils import array_from_file, apply_read_scaling
from .fileslice import fileslice
from .keywordonly import kw_only_meth
Expand Down Expand Up @@ -111,8 +113,12 @@ def shape(self):
return self._shape

@property
def is_proxy(self):
return True
def dtype(self):
return self._dtype

@property
def offset(self):
return self._offset

@property
def slope(self):
Expand All @@ -123,8 +129,8 @@ def inter(self):
return self._inter

@property
def offset(self):
return self._offset
def is_proxy(self):
return True

def get_unscaled(self):
''' Read of data from file
Expand Down Expand Up @@ -164,3 +170,10 @@ def is_proxy(obj):
return obj.is_proxy
except AttributeError:
return False


def reshape_dataobj(obj, shape):
""" Use `obj` reshape method if possible, else numpy reshape function
"""
return (obj.reshape(shape) if hasattr(obj, 'reshape')
else np.reshape(obj, shape))
27 changes: 27 additions & 0 deletions nibabel/cifti2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""CIfTI format IO

.. currentmodule:: nibabel.cifti2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these set of lines have any effect on the generated documentation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthew-brett - these were copied over from the prior __init__ files that things were tracked from: gifti, nicom. if there is no need for this perhaps that can be handled in a separate PR going across nibabel.

is there an automated documentation builder somewhere for pull-requests and the main repo?


.. autosummary::
:toctree: ../generated

cifti2
"""

from .parse_cifti2 import Cifti2Extension
from .cifti2 import (Cifti2MetaData, Cifti2Header, Cifti2Image, Cifti2Label,
Cifti2LabelTable, Cifti2VertexIndices,
Cifti2VoxelIndicesIJK, Cifti2BrainModel, Cifti2Matrix,
Cifti2MatrixIndicesMap, Cifti2NamedMap, Cifti2Parcel,
Cifti2Surface,
Cifti2TransformationMatrixVoxelIndicesIJKtoXYZ,
Cifti2Vertices, Cifti2Volume, CIFTI_BRAIN_STRUCTURES,
Cifti2HeaderError, CIFTI_MODEL_TYPES, load, save)
Loading