Skip to content
Snippets Groups Projects
Commit 8721da08 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

tests for naninfrange module

parent 8467fdf5
No related branches found
No related tags found
No related merge requests found
...@@ -9,14 +9,12 @@ from __future__ import print_function ...@@ -9,14 +9,12 @@ from __future__ import print_function
import collections import collections
import random import random
import time
import itertools as it import itertools as it
import numpy as np import numpy as np
import nibabel as nib import nibabel as nib
import pytest import pytest
import fsl.utils.naninfrange as nir
import fsl.data.image as image
import fsl.data.imagewrapper as imagewrap import fsl.data.imagewrapper as imagewrap
from . import random_voxels from . import random_voxels
...@@ -291,46 +289,6 @@ def test_sliceTupleToSliceObj(): ...@@ -291,46 +289,6 @@ def test_sliceTupleToSliceObj():
assert func(slices) == sliceobj 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(): def test_adjustCoverage():
...@@ -617,7 +575,7 @@ def _test_ImageWrapper_read(niters, seed, threaded, addnans=False): ...@@ -617,7 +575,7 @@ def _test_ImageWrapper_read(niters, seed, threaded, addnans=False):
data[coords] = np.nan 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 = [] rrs = []
for vol in range(nvols): for vol in range(nvols):
......
#!/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])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment