|
| 1 | +# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*- |
| 2 | +# vi: set ft=python sts=4 ts=4 sw=4 et: |
| 3 | +### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## |
| 4 | +# |
| 5 | +# See COPYING file distributed along with the NiBabel package for the |
| 6 | +# copyright and license terms. |
| 7 | +# |
| 8 | +### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## |
| 9 | +""" Test we can correctly import example ECAT files |
| 10 | +""" |
| 11 | +from __future__ import print_function, absolute_import |
| 12 | + |
| 13 | +import os |
| 14 | +from os.path import join as pjoin |
| 15 | + |
| 16 | +import numpy as np |
| 17 | + |
| 18 | +from .nibabel_data import get_nibabel_data, needs_nibabel_data |
| 19 | +from ..ecat import load |
| 20 | + |
| 21 | +from nose.tools import assert_equal |
| 22 | +from numpy.testing import (assert_array_equal, assert_almost_equal) |
| 23 | + |
| 24 | +ECAT_TEST_PATH = pjoin(get_nibabel_data(), 'nipy-ecattest') |
| 25 | + |
| 26 | + |
| 27 | +class TestNegatives(object): |
| 28 | + opener = staticmethod(load) |
| 29 | + example_params = dict( |
| 30 | + fname = os.path.join(ECAT_TEST_PATH, 'ECAT7_testcaste_neg_values.v'), |
| 31 | + shape = (256, 256, 63, 1), |
| 32 | + type = np.int16, |
| 33 | + # These values from freec64 |
| 34 | + min = -0.00061576, |
| 35 | + max = 0.19215, |
| 36 | + mean = 0.04933, |
| 37 | + # unit: 1/cm |
| 38 | + ) |
| 39 | + |
| 40 | + @needs_nibabel_data('nitest-minc2') |
| 41 | + def test_load(self): |
| 42 | + # Check highest level load of minc works |
| 43 | + img = self.opener(self.example_params['fname']) |
| 44 | + assert_equal(img.shape, self.example_params['shape']) |
| 45 | + assert_equal(img.get_data_dtype(0).type, self.example_params['type']) |
| 46 | + # Check correspondence of data and recorded shape |
| 47 | + data = img.get_data() |
| 48 | + assert_equal(data.shape, self.example_params['shape']) |
| 49 | + # min, max, mean values from given parameters |
| 50 | + assert_almost_equal(data.min(), self.example_params['min'], 4) |
| 51 | + assert_almost_equal(data.max(), self.example_params['max'], 4) |
| 52 | + assert_almost_equal(data.mean(), self.example_params['mean'], 4) |
0 commit comments