From 13da569092e84d195efcae26219f1336914d41d7 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Fri, 13 Jan 2023 04:58:04 +0000
Subject: [PATCH 1/3] TEST: use int32 instead of int64
---
tests/__init__.py | 1 +
tests/test_featanalysis.py | 2 +-
tests/test_image.py | 3 +-
tests/test_image_resample.py | 4 +--
tests/test_image_roi.py | 4 +--
tests/test_melodicimage.py | 4 +--
tests/test_scripts/test_fsl_apply_x5.py | 4 +--
tests/test_transform/test_nonlinear.py | 18 ++++++------
tests/test_wrappers/test_wrapperutils.py | 37 +++++++++++++++---------
9 files changed, 45 insertions(+), 32 deletions(-)
diff --git a/tests/__init__.py b/tests/__init__.py
index 6e6ad861..39bebb23 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -318,6 +318,7 @@ def make_mock_feat_analysis(featdir,
data = np.ravel_multi_index(data, shape)
data = data.reshape(list(shape) + [1]).repeat(timepoints, axis=3)
data[..., :] += range(i, i + timepoints)
+ data = data.astype(np.int32)
img = nib.nifti1.Nifti1Image(data, xform)
diff --git a/tests/test_featanalysis.py b/tests/test_featanalysis.py
index da378984..96445cdb 100644
--- a/tests/test_featanalysis.py
+++ b/tests/test_featanalysis.py
@@ -312,7 +312,7 @@ def test_loadClusterResults():
# header, so we have to generate it.
if not firstlevel:
datafile = op.join(featdir, 'filtered_func_data.nii.gz')
- data = np.random.randint(1, 10, (91, 109, 91))
+ data = np.random.randint(1, 10, (91, 109, 91), dtype=np.int32)
xform = np.array([[-2, 0, 0, 90],
[ 0, 2, 0, -126],
[ 0, 0, 2, -72],
diff --git a/tests/test_image.py b/tests/test_image.py
index 8fc76c55..bb3b02ce 100644
--- a/tests/test_image.py
+++ b/tests/test_image.py
@@ -550,7 +550,8 @@ def test_defaultImageType():
else:
exptype = nib.Nifti2Image
- img = fslimage.Image(np.random.randint(1, 10, (30, 30, 30)))
+ data = np.random.randint(1, 10, (30, 30, 30), dtype=np.int32)
+ img = fslimage.Image(data)
assert type(img.nibImage) == exptype
diff --git a/tests/test_image_resample.py b/tests/test_image_resample.py
index ccc0b893..6d6baf4e 100644
--- a/tests/test_image_resample.py
+++ b/tests/test_image_resample.py
@@ -234,7 +234,7 @@ def test_resampleToReference3():
# Test resampling image to ref
# with mismatched dimensions
- imgdata = np.random.randint(0, 65536, (5, 5, 5))
+ imgdata = np.random.randint(0, 65536, (5, 5, 5), dtype=np.int32)
img = fslimage.Image(imgdata, xform=affine.scaleOffsetXform(
(2, 2, 2), (0.5, 0.5, 0.5)))
@@ -272,7 +272,7 @@ def test_resampleToReference4():
# will bring them into alignment
img2ref = affine.scaleOffsetXform([2, 2, 2], [10, 10, 10])
- imgdata = np.random.randint(0, 65536, (5, 5, 5))
+ imgdata = np.random.randint(0, 65536, (5, 5, 5), dtype=np.int32)
refdata = np.zeros((5, 5, 5))
img = fslimage.Image(imgdata)
ref = fslimage.Image(refdata, xform=img2ref)
diff --git a/tests/test_image_roi.py b/tests/test_image_roi.py
index 0917c6e2..eebf18ef 100644
--- a/tests/test_image_roi.py
+++ b/tests/test_image_roi.py
@@ -46,7 +46,7 @@ def test_roi():
]
for inshape, bounds, outshape, offset in tests:
- data = np.random.randint(1, 10, inshape)
+ data = np.random.randint(1, 10, inshape, dtype=np.int32)
image = fslimage.Image(data, xform=np.eye(4))
result = roi.roi(image, bounds)
@@ -84,7 +84,7 @@ def test_roi():
# - not enough bounds
# - too many bounds
# - hi >= lo
- data = np.random.randint(1, 10, (10, 10, 10))
+ data = np.random.randint(1, 10, (10, 10, 10), dtype=np.int32)
image = fslimage.Image(data, xform=np.eye(4))
with pytest.raises(ValueError): roi.roi(image, [(0, 10), (0, 10)])
with pytest.raises(ValueError): roi.roi(image, [(0, 10), (0, 10), (0, 10), (0, 10)])
diff --git a/tests/test_melodicimage.py b/tests/test_melodicimage.py
index c3f17260..9bf89f6e 100644
--- a/tests/test_melodicimage.py
+++ b/tests/test_melodicimage.py
@@ -67,7 +67,7 @@ def _create_dummy_melodic_analysis(basedir,
fslimage.Image(icimg).save(icfile)
if with_data:
- dataimg = np.zeros(list(shape4D[:3]) + [timepoints])
+ dataimg = np.zeros(list(shape4D[:3]) + [timepoints], dtype=np.int32)
for t in range(timepoints):
dataimg[..., t] = t
@@ -82,7 +82,7 @@ def _create_dummy_melodic_analysis(basedir,
if with_meanfile:
nvoxels = np.prod(shape4D[:3])
- data = np.arange(0, nvoxels).reshape(shape4D[:3])
+ data = np.arange(0, nvoxels).reshape(shape4D[:3]).astype(np.int32)
fslimage.Image(data).save(meanfile)
return meldir
diff --git a/tests/test_scripts/test_fsl_apply_x5.py b/tests/test_scripts/test_fsl_apply_x5.py
index b3b66691..8d83169d 100644
--- a/tests/test_scripts/test_fsl_apply_x5.py
+++ b/tests/test_scripts/test_fsl_apply_x5.py
@@ -99,7 +99,7 @@ def test_linear_altref(seed):
src2ref = affine.scaleOffsetXform([1, 1, 1], [5, 5, 5])
altv2w = affine.scaleOffsetXform([1, 1, 1], [10, 10, 10])
- srcdata = np.random.randint(1, 65536, (10, 10, 10))
+ srcdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
src = fslimage.Image(srcdata, xform=np.eye(4))
ref = fslimage.Image(src.data, xform=src2ref)
altref = fslimage.Image(src.data, xform=altv2w)
@@ -127,7 +127,7 @@ def test_nonlinear_altref(seed):
ref2src = affine.invert(src2ref)
altv2w = affine.scaleOffsetXform([1, 1, 1], [10, 10, 10])
- srcdata = np.random.randint(1, 65536, (10, 10, 10))
+ srcdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
src = fslimage.Image(srcdata, xform=np.eye(4))
ref = fslimage.Image(src.data, xform=src2ref)
altref = fslimage.Image(src.data, xform=altv2w)
diff --git a/tests/test_transform/test_nonlinear.py b/tests/test_transform/test_nonlinear.py
index 1cb8cf8f..682a7fae 100644
--- a/tests/test_transform/test_nonlinear.py
+++ b/tests/test_transform/test_nonlinear.py
@@ -384,8 +384,8 @@ def test_applyDeformation():
np.random.random(3))
ref2src = affine.invert(src2ref)
- srcdata = np.random.randint(1, 65536, (10, 10, 10))
- refdata = np.random.randint(1, 65536, (10, 10, 10))
+ srcdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
+ refdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
src = fslimage.Image(srcdata)
ref = fslimage.Image(refdata, xform=src2ref)
@@ -407,8 +407,8 @@ def test_applyDeformation_altsrc():
[0, 0, 0])
ref2src = affine.invert(src2ref)
- srcdata = np.random.randint(1, 65536, (10, 10, 10))
- refdata = np.random.randint(1, 65536, (10, 10, 10))
+ srcdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
+ refdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
src = fslimage.Image(srcdata)
ref = fslimage.Image(refdata, xform=src2ref)
@@ -455,8 +455,8 @@ def test_applyDeformation_premat():
[0, 0, 0])
ref2src = affine.invert(src2ref)
- srcdata = np.random.randint(1, 65536, (10, 10, 10))
- refdata = np.random.randint(1, 65536, (10, 10, 10))
+ srcdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
+ refdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
src = fslimage.Image(srcdata)
ref = fslimage.Image(refdata, xform=src2ref)
@@ -508,8 +508,8 @@ def test_applyDeformation_altref():
np.random.random(3))
ref2src = affine.invert(src2ref)
- srcdata = np.random.randint(1, 65536, (10, 10, 10))
- refdata = np.random.randint(1, 65536, (10, 10, 10))
+ srcdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
+ refdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
src = fslimage.Image(srcdata)
ref = fslimage.Image(refdata, xform=src2ref)
@@ -544,7 +544,7 @@ def test_applyDeformation_worldAligned():
src2ref = refv2w
ref2src = affine.invert(src2ref)
- srcdata = np.random.randint(1, 65536, (10, 10, 10))
+ srcdata = np.random.randint(1, 65536, (10, 10, 10), dtype=np.int32)
src = fslimage.Image(srcdata)
ref = fslimage.Image(srcdata, xform=src2ref)
diff --git a/tests/test_wrappers/test_wrapperutils.py b/tests/test_wrappers/test_wrapperutils.py
index 166bf431..7d712669 100644
--- a/tests/test_wrappers/test_wrapperutils.py
+++ b/tests/test_wrappers/test_wrapperutils.py
@@ -293,10 +293,13 @@ def test_fileOrImage():
with tempdir.tempdir():
- img1 = nib.nifti1.Nifti1Image(np.array([[1, 2], [ 3, 4]]), np.eye(4))
- img2 = nib.nifti1.Nifti1Image(np.array([[5, 6], [ 7, 8]]), np.eye(4))
- img3 = nib.nifti1.Nifti1Image(np.array([[1, 2], [ 3, 4]]), np.eye(4))
- expected = np.array([[5, 12], [21, 32]])
+ img1 = nib.nifti1.Nifti1Image(
+ np.array([[1, 2], [ 3, 4]], dtype=np.int32), np.eye(4))
+ img2 = nib.nifti1.Nifti1Image(
+ np.array([[5, 6], [ 7, 8]], dtype=np.int32), np.eye(4))
+ img3 = nib.nifti1.Nifti1Image(
+ np.array([[1, 2], [ 3, 4]], dtype=np.int32), np.eye(4))
+ expected = np.array([[5, 12], [21, 32]], dtype=np.int32)
nib.save(img1, 'img1.nii')
nib.save(img2, 'img2.nii')
@@ -446,7 +449,8 @@ def test_fileOrThing_outprefix():
with tempdir.tempdir() as td:
- img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]]), np.eye(4))
+ img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]], dtype=np.int32),
+ np.eye(4))
exp1 = np.asanyarray(img.dataobj) * 5
exp2 = np.asanyarray(img.dataobj) * 10
nib.save(img, 'img.nii')
@@ -483,7 +487,8 @@ def test_fileOrThing_pathlib():
nib.save(outimg, out)
with tempdir.tempdir() as td:
- img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]]), np.eye(4))
+ img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]], dtype=np.int32),
+ np.eye(4))
exp = np.asanyarray(img.dataobj) * 5
nib.save(img, 'img.nii')
@@ -503,7 +508,8 @@ def test_fileOrThing_outprefix_pathlib():
nib.save(out2, '{}_times10.nii.gz'.format(output_base))
with tempdir.tempdir() as td:
- img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]]), np.eye(4))
+ img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]], dtype=np.int32),
+ np.eye(4))
exp1 = np.asanyarray(img.dataobj) * 5
exp2 = np.asanyarray(img.dataobj) * 10
nib.save(img, 'img.nii')
@@ -528,7 +534,8 @@ def test_fileOrThing_outprefix_differentTypes():
f.write(text)
with tempdir.tempdir() as td:
- img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]]), np.eye(4))
+ img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]], dtype=np.int32),
+ np.eye(4))
expi = np.asanyarray(img.dataobj) * 2
expt = '1234567890'
@@ -573,7 +580,8 @@ def test_fileOrThing_outprefix_directory():
nib.save(img4, op.join(outdir, 'img4.nii.gz'))
with tempdir.tempdir() as td:
- img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]]), np.eye(4))
+ img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]], dtype=np.int32),
+ np.eye(4))
exp2 = np.asanyarray(img.dataobj) * 2
exp4 = np.asanyarray(img.dataobj) * 4
@@ -730,7 +738,8 @@ def test_chained_fileOrImageAndArray():
np.savetxt(outarray, array * 2)
outimg.to_filename(outimage)
- image = nib.nifti1.Nifti1Image(np.array([[1, 2], [ 3, 4]]), np.eye(4))
+ image = nib.nifti1.Nifti1Image(np.array([[1, 2], [ 3, 4]], dtype=np.int32),
+ np.eye(4))
array = np.array([[5, 6, 7, 8]])
expimg = nib.nifti1.Nifti1Image(np.asanyarray(image.dataobj) * 2, np.eye(4))
@@ -789,7 +798,8 @@ def test_fileOrThing_chained_outprefix():
np.savetxt('{}_array.txt'.format(out), outarr)
outimg.to_filename('{}_image.nii'.format(out))
- image = nib.nifti1.Nifti1Image(np.array([[1, 2], [ 3, 4]]), np.eye(4))
+ image = nib.nifti1.Nifti1Image(np.array([[1, 2], [ 3, 4]], dtype=np.int32),
+ np.eye(4))
array = np.array([[5, 6, 7, 8]])
expimg = nib.nifti1.Nifti1Image(np.asanyarray(image.dataobj) * 2, np.eye(4))
@@ -822,7 +832,8 @@ def test_fileOrThing_submit_cmdonly():
nib.save(img, output)
with tempdir.tempdir() as td:
- img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]]), np.eye(4))
+ img = nib.nifti1.Nifti1Image(np.array([[1, 2], [3, 4]], dtype=np.int32),
+ np.eye(4))
exp = np.asanyarray(img.dataobj) * 2
nib.save(img, 'input.nii.gz')
@@ -1001,7 +1012,7 @@ def test_fileOrImage_all_tempfiles_cleared():
i = nib.Nifti1Image(i.get_fdata() + 1, np.eye(4))
i.to_filename(out)
- arr = np.array([[1, 2], [ 3, 4]])
+ arr = np.array([[1, 2], [ 3, 4]], dtype=np.int32)
img = nib.nifti1.Nifti1Image(arr, np.eye(4))
imgout = image(img, wutils.LOAD).out
--
2.39.1