neurospin / pypreprocess

Preprocessing scripts for neuro imaging
105 stars 66 forks source link

TypeError: slice indices must be integers or None or have an __index__ method #273

Closed chrisgorgo closed 7 years ago

chrisgorgo commented 7 years ago
In [13]: from pypreprocess.realign import MRIMotionCorrection

In [14]: mc = MRIMotionCorrection()

In [15]: mc.fit(["D:/data/ds000001/sub-01/func/sub-01_task-balloonanalogrisktask_run-01_bold.nii.gz"])
Intra-session registration: Realigning session 1/1...
Eliminating unimportant voxels (target quality: 0.9)...
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-bf833857234e> in <module>()
----> 1 mc.fit(["D:/data/ds000001/sub-01/func/sub-01_task-balloonanalogrisktask_run-01_bold.nii.gz"])

D:\drive\workspace\pypreprocess\pypreprocess\realign.py in fit(self, vols)
    496             sess_rp = self._single_session_fit(
    497                 self.vols_[sess],
--> 498                 affine_correction=affine_correction)
    499
    500             self.realignment_parameters_.append(sess_rp)

D:\drive\workspace\pypreprocess\pypreprocess\realign.py in _single_session_fit(self, vols, quality, affine_correction)
    276                     dets[t] = scipy.linalg.det(alpha - np.dot(tmp.T, tmp))
    277                 msk = np.argsort(det1 - dets)
--> 278                 msk = msk[:np.round(len(dets) / 10.)]
    279
    280                 # eliminate unimportant voxels

TypeError: slice indices must be integers or None or have an __index__ method

In [16]: nii = nb.load("D:/data/ds000001/sub-01/func/sub-01_task-balloonanalogrisktask_run-01_bold.nii.gz")

In [17]: mc.fit([nii])
Intra-session registration: Realigning session 1/1...
Eliminating unimportant voxels (target quality: 0.9)...
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-374b0f8c8e6c> in <module>()
----> 1 mc.fit([nii])

D:\drive\workspace\pypreprocess\pypreprocess\realign.py in fit(self, vols)
    496             sess_rp = self._single_session_fit(
    497                 self.vols_[sess],
--> 498                 affine_correction=affine_correction)
    499
    500             self.realignment_parameters_.append(sess_rp)

D:\drive\workspace\pypreprocess\pypreprocess\realign.py in _single_session_fit(self, vols, quality, affine_correction)
    276                     dets[t] = scipy.linalg.det(alpha - np.dot(tmp.T, tmp))
    277                 msk = np.argsort(det1 - dets)
--> 278                 msk = msk[:np.round(len(dets) / 10.)]
    279
    280                 # eliminate unimportant voxels

TypeError: slice indices must be integers or None or have an __index__ method

In [18]: mc.fit(nii)
Intra-session registration: Realigning session 1/1...
Eliminating unimportant voxels (target quality: 0.9)...
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-a02494f1d9d4> in <module>()
----> 1 mc.fit(nii)

D:\drive\workspace\pypreprocess\pypreprocess\realign.py in fit(self, vols)
    496             sess_rp = self._single_session_fit(
    497                 self.vols_[sess],
--> 498                 affine_correction=affine_correction)
    499
    500             self.realignment_parameters_.append(sess_rp)

D:\drive\workspace\pypreprocess\pypreprocess\realign.py in _single_session_fit(self, vols, quality, affine_correction)
    276                     dets[t] = scipy.linalg.det(alpha - np.dot(tmp.T, tmp))
    277                 msk = np.argsort(det1 - dets)
--> 278                 msk = msk[:np.round(len(dets) / 10.)]
    279
    280                 # eliminate unimportant voxels

TypeError: slice indices must be integers or None or have an __index__ method

In [19]: nii.shape
Out[19]: (64, 64, 33, 300)
chrisgorgo commented 7 years ago

This error goes away when I use:

mc = MRIMotionCorrection(quality=1.0)

chrisgorgo commented 7 years ago

This bug is also making tests on master fail:

======================================================================
ERROR: pypreprocess.tests.test_slice_timing.test_STC_for_sinusoidal_mixture
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/miniconda2/envs/testenv/lib/python3.5/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/travis/build/neurospin/pypreprocess/pypreprocess/tests/test_slice_timing.py", line 136, in test_STC_for_sinusoidal_mixture
    stc.fit(n_slices=n_slices, n_scans=n_scans)
  File "/home/travis/build/neurospin/pypreprocess/pypreprocess/slice_timing.py", line 305, in fit
    phi[1 + N / 2 - offset:] = -phi[N / 2 + offset - 1:0:-1]
TypeError: slice indices must be integers or None or have an __index__ method
======================================================================
ERROR: pypreprocess.tests.test_slice_timing.test_STC_for_HRF
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/miniconda2/envs/testenv/lib/python3.5/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/travis/build/neurospin/pypreprocess/pypreprocess/tests/test_slice_timing.py", line 208, in test_STC_for_HRF
    stc.fit(n_scans=n_scans, n_slices=n_slices)
  File "/home/travis/build/neurospin/pypreprocess/pypreprocess/slice_timing.py", line 305, in fit
    phi[1 + N / 2 - offset:] = -phi[N / 2 + offset - 1:0:-1]
TypeError: slice indices must be integers or None or have an __index__ method
======================================================================
ERROR: pypreprocess.tests.test_slice_timing.test_transform
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/miniconda2/envs/testenv/lib/python3.5/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/travis/build/neurospin/pypreprocess/pypreprocess/tests/test_slice_timing.py", line 244, in test_transform
    fmristc = fMRISTC().fit(raw_data=stuff)
  File "/home/travis/build/neurospin/pypreprocess/pypreprocess/slice_timing.py", line 305, in fit
    phi[1 + N / 2 - offset:] = -phi[N / 2 + offset - 1:0:-1]
TypeError: slice indices must be integers or None or have an __index__ method
----------------------------------------------------------------------

It must be caused by some API breaking dependency update...