예제 #1
0
    def testrun(self):
        funcim = load_image(funcfile)
        fmriims = FmriImageList.from_image(funcim, volume_start_times=2.)

        f1 = ExperimentalQuantitative("f1", lambda t:t)
        f2 = ExperimentalQuantitative("f1", lambda t:t**2)
        f3 = ExperimentalQuantitative("f1", lambda t:t**3)

        f = f1 + f2 + f3
        c = Contrast(f1, f)
        c.compute_matrix(fmriims.volume_start_times)
        c2 = Contrast(f1 + f2, f)
        c2.compute_matrix(fmriims.volume_start_times)

        outputs = []
        outputs.append(model.output_AR1(self.ar1, fmriims, clobber=True))
        outputs.append(model.output_resid(self.resid_OLS, fmriims, 
                                          clobber=True))
        ols = model.OLS(fmriims, f, outputs)
        ols.execute()

        outputs = []
        out_fn = os.path.join(self.out_dir, 'out.nii')
        outputs.append(model.output_T(out_fn, c, fmriims, clobber=True))
        outputs.append(model.output_F(self.F, c2, fmriims, clobber=True))
        outputs.append(model.output_resid(self.resid, fmriims, clobber=True))
        rho = load_image(self.ar1)
        ar = model.AR1(fmriims, f, rho, outputs)
        ar.execute()
예제 #2
0
    def setUp(self):
        self.fd = np.asarray(load_image(funcfile))
        self.fi = FmriImageList.from_image(load_image(funcfile))
        # I think it makes more sense to use fd instead of fi for GLM
        # purposes -- reduces some noticeable overhead in creating the
        # array from FmriImageList

        # create a design matrix, model and contrast matrix

        self.design = noise((self.fd.shape[0],3))
        self.model = ols_model(self.design)
        self.cmatrix = np.array([[1,0,0],[0,1,0]])
예제 #3
0
def test_write():
    fp, fname = mkstemp('.nii')
    img = load_image(funcfile)
    save_image(img, fname)
    test = FmriImageList.from_image(load_image(fname))
    yield nose.tools.assert_equal, test[0].affine.shape, (4,4)
    yield nose.tools.assert_equal, img[0].affine.shape, (5,4)
    yield nose.tools.assert_true, np.allclose(test[0].affine, img[0].affine[1:])
    # Under windows, if you don't close before delete, you get a
    # locking error.
    os.close(fp)
    os.remove(fname)
예제 #4
0
def test_write():
    fname = 'myfile.nii'
    img = load_image(funcfile)
    with InTemporaryDirectory():
        save_image(img, fname)
        test = FmriImageList.from_image(load_image(fname))
        assert_equal(test[0].affine.shape, (4,4))
        assert_equal(img[0].affine.shape, (5,4))
        # Check the affine...
        A = np.identity(4)
        A[:3,:3] = img[:,:,:,0].affine[:3,:3]
        A[:3,-1] = img[:,:,:,0].affine[:3,-1]
        assert_true(np.allclose(test[0].affine, A))
        del test
예제 #5
0
파일: test_fmri.py 프로젝트: Lx37/nipy
def test_write():
    fname = "myfile.nii"
    img = load_image(funcfile)
    with InTemporaryDirectory():
        save_image(img, fname)
        test = FmriImageList.from_image(load_image(fname))
        assert_equal(test[0].affine.shape, (4, 4))
        assert_equal(img[0].affine.shape, (5, 4))
        # Check the affine...
        A = np.identity(4)
        A[:3, :3] = img[:, :, :, 0].affine[:3, :3]
        A[:3, -1] = img[:, :, :, 0].affine[:3, -1]
        assert_true(np.allclose(test[0].affine, A))
        del test
예제 #6
0
def test_write():
    fp, fname = mkstemp('.nii')
    img = load_image(funcfile)
    save_image(img, fname)
    test = FmriImageList.from_image(load_image(fname))
    yield assert_equal, test[0].affine.shape, (4,4)
    yield assert_equal, img[0].affine.shape, (5,4)

    # Check the affine...
    A = np.identity(4)
    A[:3,:3] = img[:,:,:,0].affine[:3,:3]
    A[:3,-1] = img[:,:,:,0].affine[:3,-1]
    yield assert_true, np.allclose(test[0].affine, A)

    # Under windows, if you don't close before delete, you get a
    # locking error.
    os.close(fp)
    os.remove(fname)
예제 #7
0
def setup():
    # Suppress warnings during tests to reduce noise
    warnings.simplefilter("ignore")


def teardown():
    # Clear list of warning filters
    warnings.resetwarnings()


# Module globals
FIMG = load_image(funcfile)
# Put time on first axis
FIMG = img_rollaxis(FIMG, "t")
FDATA = FIMG.get_data()
FIL = FmriImageList.from_image(FIMG)

# I think it makes more sense to use FDATA instead of FIL for GLM
# purposes -- reduces some noticeable overhead in creating the
# array from FmriImageList

# create a design matrix, model and contrast matrix
DESIGN = noise((FDATA.shape[0], 3))
MODEL = OLSModel(DESIGN)
CMATRIX = np.array([[1, 0, 0], [0, 1, 0]])

# two prototypical functions in a GLM analysis
def fit(input):
    return MODEL.fit(input).resid

예제 #8
0
def setup():
    # Suppress warnings during tests to reduce noise
    warnings.simplefilter("ignore")


def teardown():
    # Clear list of warning filters
    warnings.resetwarnings()


# Module globals
FIMG = load_image(funcfile)
# Put time on first axis
FIMG = rollimg(FIMG, 't')
FDATA = FIMG.get_data()
FIL = FmriImageList.from_image(FIMG)

# I think it makes more sense to use FDATA instead of FIL for GLM
# purposes -- reduces some noticeable overhead in creating the
# array from FmriImageList

# create a design matrix, model and contrast matrix
DESIGN = noise((FDATA.shape[0], 3))
MODEL = OLSModel(DESIGN)
CMATRIX = np.array([[1, 0, 0], [0, 1, 0]])


# two prototypical functions in a GLM analysis
def fit(input):
    return MODEL.fit(input).resid