~ubuntu-branches/ubuntu/wily/nibabel/wily-proposed

« back to all changes in this revision

Viewing changes to nibabel/freesurfer/tests/test_io.py

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2012-05-06 12:58:22 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120506125822-3jiwjkmdqcxkrior
Tags: 1.2.0-1
* New upstream release: bugfixes, support for new formats
  (Freesurfer, ECAT, etc), nib-ls tool.
* debian/copyright
  - corrected reference to the format specs
  - points to github's repository as the origin of sources
  - removed lightunit license/copyright -- removed upstream
  - added netcdf module license/copyright terms
* debian/control
  - added python-fuse to Recommends and Build-Depends for dicomfs
  - boosted policy compliance to 3.9.3 (no further changes)
* debian/watch
  - adjusted to download numbered tag

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
from os.path import join as pjoin
 
3
 
 
4
from nose.tools import assert_true
 
5
import numpy as np
 
6
from numpy.testing import assert_equal
 
7
 
 
8
from .. import read_geometry, read_morph_data, read_annot, read_label
 
9
 
 
10
 
 
11
have_freesurfer = True
 
12
if 'SUBJECTS_DIR' not in os.environ:
 
13
    # Test suite relies on the definition of SUBJECTS_DIR
 
14
    have_freesurfer = False
 
15
 
 
16
freesurfer_test = np.testing.dec.skipif(not have_freesurfer,
 
17
                                        'SUBJECTS_DIR not set')
 
18
 
 
19
if have_freesurfer:
 
20
    subj_dir = os.environ["SUBJECTS_DIR"]
 
21
    subject_id = 'fsaverage'
 
22
    data_path = pjoin(subj_dir, subject_id)
 
23
 
 
24
 
 
25
@freesurfer_test
 
26
def test_geometry():
 
27
    """Test IO of .surf"""
 
28
    surf_path = pjoin(data_path, "surf", "%s.%s" % ("lh", "inflated"))
 
29
    coords, faces = read_geometry(surf_path)
 
30
    assert_equal(0, faces.min())
 
31
    assert_equal(coords.shape[0], faces.max() + 1)
 
32
 
 
33
    # Test quad with sphere
 
34
    surf_path = pjoin(data_path, "surf", "%s.%s" % ("lh", "sphere"))
 
35
    coords, faces = read_geometry(surf_path)
 
36
    assert_equal(0, faces.min())
 
37
    assert_equal(coords.shape[0], faces.max() + 1)
 
38
 
 
39
 
 
40
@freesurfer_test
 
41
def test_morph_data():
 
42
    """Test IO of morphometry data file (eg. curvature)."""
 
43
    curv_path = pjoin(data_path, "surf", "%s.%s" % ("lh", "curv"))
 
44
    curv = read_morph_data(curv_path)
 
45
    assert_true(-1.0 < curv.min() < 0)
 
46
    assert_true(0 < curv.max() < 1.0)
 
47
 
 
48
 
 
49
@freesurfer_test
 
50
def test_annot():
 
51
    """Test IO of .annot"""
 
52
    annots = ['aparc', 'aparc.a2005s']
 
53
    for a in annots:
 
54
        annot_path = pjoin(data_path, "label", "%s.%s.annot" % ("lh", a))
 
55
        labels, ctab, names = read_annot(annot_path)
 
56
        assert_true(labels.shape == (163842, ))
 
57
        assert_true(ctab.shape == (len(names), 5))
 
58
 
 
59
 
 
60
@freesurfer_test
 
61
def test_label():
 
62
    """Test IO of .label"""
 
63
    label_path = pjoin(data_path, "label", "lh.BA1.label")
 
64
    label = read_label(label_path)
 
65
    # XXX : test more
 
66
    assert_true(np.all(label > 0))