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

Merge branch 'enh/complex' into 'master'

Enh/complex

See merge request fsl/fslpy!157
parents c0369c6d 05ab92ce
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,13 @@ order. ...@@ -6,6 +6,13 @@ order.
------------------------- -------------------------
Added
^^^^^
* New :meth:`.Image.iscomplex` attribute.
Changed Changed
^^^^^^^ ^^^^^^^
......
...@@ -1195,6 +1195,14 @@ class Image(Nifti): ...@@ -1195,6 +1195,14 @@ class Image(Nifti):
else: return nvals else: return nvals
@property
def iscomplex(self):
"""Returns ``True`` if this image has a complex data type, ``False``
otherwise.
"""
return np.issubdtype(self.dtype, np.complexfloating)
@Nifti.voxToWorldMat.setter @Nifti.voxToWorldMat.setter
def voxToWorldMat(self, xform): def voxToWorldMat(self, xform):
"""Overrides the :meth:`Nifti.voxToWorldMat` property setter. """Overrides the :meth:`Nifti.voxToWorldMat` property setter.
......
...@@ -299,6 +299,7 @@ def _test_Image_atts(imgtype): ...@@ -299,6 +299,7 @@ def _test_Image_atts(imgtype):
path = op.abspath(op.join(testdir, path)) path = op.abspath(op.join(testdir, path))
i = fslimage.Image(path) i = fslimage.Image(path)
assert not i.iscomplex
assert tuple(i.shape) == tuple(expdims) assert tuple(i.shape) == tuple(expdims)
assert tuple(i.data.shape) == tuple(expdims) assert tuple(i.data.shape) == tuple(expdims)
assert tuple(i.pixdim) == tuple(exppixdims) assert tuple(i.pixdim) == tuple(exppixdims)
...@@ -1369,3 +1370,15 @@ def test_identifyAffine(): ...@@ -1369,3 +1370,15 @@ def test_identifyAffine():
rubbish = np.random.random((4, 4)) rubbish = np.random.random((4, 4))
with pytest.raises(ValueError): with pytest.raises(ValueError):
identify(img, rubbish) identify(img, rubbish)
def test_complex():
data = np.random.random((5, 5, 5)) + \
np.random.random((5, 5, 5)) * 1j
image = fslimage.Image(data)
dmin, dmax = image.dataRange
assert image.iscomplex
assert image[3, 3, 3] == data[3, 3, 3]
assert dmin == data.min()
assert dmax == data.max()
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