Skip to content

Commit 5bffac6

Browse files
committed
BF+TST: test /fix for signed int data type
We were incorrectly loading signed ints as unsigned; fix and test.
1 parent b0a8006 commit 5bffac6

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

nibabel/ecat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@
155155
_dtdefs = ( # code, name, equivalent dtype
156156
(1, 'ECAT7_BYTE', np.uint8),
157157
(2, 'ECAT7_VAXI2', np.int16),
158-
(3, 'ECAT7_VAXI4', np.float32),
158+
(3, 'ECAT7_VAXI4', np.int32),
159159
(4, 'ECAT7_VAXR4', np.float32),
160160
(5, 'ECAT7_IEEER4', np.float32),
161-
(6, 'ECAT7_SUNI2', np.uint16),
161+
(6, 'ECAT7_SUNI2', np.int16),
162162
(7, 'ECAT7_SUNI4', np.int32))
163163
data_type_codes = make_dt_codes(_dtdefs)
164164

nibabel/tests/test_ecat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_subheader(self):
172172
np.array([ 2.20241979, 2.20241979, 3.125, 1.]))
173173
assert_equal(self.subhdr.get_zooms()[0], 2.20241978764534)
174174
assert_equal(self.subhdr.get_zooms()[2], 3.125)
175-
assert_equal(self.subhdr._get_data_dtype(0),np.uint16)
175+
assert_equal(self.subhdr._get_data_dtype(0), np.int16)
176176
#assert_equal(self.subhdr._get_frame_offset(), 1024)
177177
assert_equal(self.subhdr._get_frame_offset(), 1536)
178178
dat = self.subhdr.raw_data_from_fileobj()

nibabel/tests/test_ecat_data.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)