diff --git a/tests/test_imagewrapper.py b/tests/test_imagewrapper.py index c481ada3158b475846ba7bd17d57a4f91abf2297..b074358d28f6ee05101fa4e7a9a714249c7820dc 100644 --- a/tests/test_imagewrapper.py +++ b/tests/test_imagewrapper.py @@ -9,14 +9,12 @@ from __future__ import print_function import collections import random -import time import itertools as it import numpy as np import nibabel as nib import pytest - -import fsl.data.image as image +import fsl.utils.naninfrange as nir import fsl.data.imagewrapper as imagewrap from . import random_voxels @@ -291,46 +289,6 @@ def test_sliceTupleToSliceObj(): assert func(slices) == sliceobj -def test_naninfrange(): - # numinf, numnan, expectedResult - tests = [( 0, 0, (0, 100)), - ( 0, 1, (0, 100)), - ( 1, 0, (0, 100)), - ( 1, 1, (0, 100)), - ( 5, 5, (0, 100)), - ( 0, 'all', (np.nan, np.nan)), - ('all', 0, (np.nan, np.nan))] - - # Test non floating point data as wll - data = np.linspace(0, 100, 100, dtype=np.uint32) - assert imagewrap.naninfrange(data) == (0, 100) - - for numinf, numnan, expected in tests: - - data = np.linspace(0, 100, 100) - - if numinf == 'all': data[:] = np.inf - elif numnan == 'all': data[:] = np.nan - - nanoff = 1 - if numinf != 'all': - for i in range(1, numinf + 1): - data[i] = np.inf - nanoff += numinf - - if numnan != 'all': - for i in range(nanoff, numnan + nanoff): - data[i] = np.nan - - result = imagewrap.naninfrange(data) - - if np.isfinite(expected[0]): assert result[0] == expected[0] - elif np.isnan( expected[0]): assert np.isnan(result[0]) - elif np.isinf( expected[0]): assert np.isinf(result[0]) - if np.isfinite(expected[1]): assert result[1] == expected[1] - elif np.isnan( expected[1]): assert np.isnan(result[1]) - elif np.isinf( expected[1]): assert np.isinf(result[1]) - def test_adjustCoverage(): @@ -617,7 +575,7 @@ def _test_ImageWrapper_read(niters, seed, threaded, addnans=False): data[coords] = np.nan - volRanges = [imagewrap.naninfrange(data[..., v]) for v in range(nvols)] + volRanges = [nir.naninfrange(data[..., v]) for v in range(nvols)] rrs = [] for vol in range(nvols): diff --git a/tests/test_naninfrange.py b/tests/test_naninfrange.py new file mode 100644 index 0000000000000000000000000000000000000000..dee79948a1a4021ab6f0e3fa72a84e64319e5b4d --- /dev/null +++ b/tests/test_naninfrange.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# +# test_naninfrange.py - +# +# Author: Paul McCarthy <pauldmccarthy@gmail.com> +# + + +import numpy as np + +import fsl.utils.naninfrange as naninfrange + + +def test_naninfrange(): + # numinf, numnan, expectedResult + tests = [( 0, 0, (0, 100)), + ( 0, 1, (0, 100)), + ( 1, 0, (0, 100)), + ( 1, 1, (0, 100)), + ( 5, 5, (0, 100)), + ( 0, 'all', (np.nan, np.nan)), + ('all', 0, (np.nan, np.nan))] + + # Test non floating point data as wll + data = np.linspace(0, 100, 100, dtype=np.uint32) + assert naninfrange.naninfrange(data) == (0, 100) + + for numinf, numnan, expected in tests: + + data = np.linspace(0, 100, 100) + + if numinf == 'all': data[:] = np.inf + elif numnan == 'all': data[:] = np.nan + + nanoff = 1 + if numinf != 'all': + for i in range(1, numinf + 1): + data[i] = np.inf + nanoff += numinf + + if numnan != 'all': + for i in range(nanoff, numnan + nanoff): + data[i] = np.nan + + result = naninfrange.naninfrange(data) + + if np.isfinite(expected[0]): assert result[0] == expected[0] + elif np.isnan( expected[0]): assert np.isnan(result[0]) + elif np.isinf( expected[0]): assert np.isinf(result[0]) + if np.isfinite(expected[1]): assert result[1] == expected[1] + elif np.isnan( expected[1]): assert np.isnan(result[1]) + elif np.isinf( expected[1]): assert np.isinf(result[1])