Пример #1
0
def test_FEATFSFDesign():

    for featdir in TEST_ANALYSES.keys():

        nev = TEST_ANALYSES[featdir]['nevs']
        shape = TEST_ANALYSES[featdir]['shape']
        desshape = TEST_ANALYSES[featdir]['designShape']
        featdir = op.join(datadir, featdir)
        settings = featanalysis.loadSettings(featdir)

        # We can't load the voxelwise EVs
        # here, because all of the .nii.gz
        # files in the test directory are
        # stubs. Voxelwise EVs get tested
        # in the test_FEATFSFDesign_firstLevelVoxelwiseEV
        # function
        des = featdesign.FEATFSFDesign(featdir, loadVoxelwiseEVs=False)

        # Can also specify the design.fsf settings
        featdesign.FEATFSFDesign(featdir,
                                 settings=settings,
                                 loadVoxelwiseEVs=False)

        rvox = tests.random_voxels(shape)

        assert len(des.getEVs()) == nev
        assert des.getDesign().shape == desshape
        assert des.getDesign(rvox).shape == desshape

        del des
        des = None
Пример #2
0
def test_FEATFSFDesign_firstLevelVoxelwiseEV(seed):

    template = op.join(datadir, '1stlevel_2.feat')

    with tests.testdir() as testdir:

        # Set up some test data - we make
        # a copy of the feat directory,
        # and generate some dummy data for
        # the voxelwise EVs.
        featdir = op.join(testdir, '1stlevel_2.feat')
        shape4D = (64, 64, 5, 45)
        shape = shape4D[:3]

        featdir = tests.make_mock_feat_analysis(template,
                                                testdir,
                                                shape4D,
                                                indata=False,
                                                pes=False,
                                                copes=False,
                                                zstats=False,
                                                residuals=False,
                                                clustMasks=False)

        # Now load the design, and make sure that
        # the voxel EVs are filled correctly
        design = featdesign.FEATFSFDesign(featdir)
        voxevIdxs = [
            ev.index for ev in design.getEVs()
            if isinstance(ev, (featdesign.VoxelwiseEV,
                               featdesign.VoxelwiseConfoundEV))
        ]

        randVoxels = np.vstack([np.random.randint(0, s, 10) for s in shape]).T

        for voxel in randVoxels:

            voxel = [int(v) for v in voxel]
            offset = np.ravel_multi_index(voxel, shape)
            matrix = design.getDesign(voxel)

            for i, evidx in enumerate(voxevIdxs):
                expect = np.arange(i, i + 45) + offset
                assert np.all(np.isclose(matrix[:, evidx], expect))
        del design
        design = None
Пример #3
0
def test_FEATImage_attributes():

    # TEst bad input
    with pytest.raises(Exception):
        featimage.FEATImage('baddir')

    for featdir in TEST_ANALYSES.keys():

        shape = TEST_ANALYSES[featdir]['shape']
        xform = TEST_ANALYSES[featdir]['xform']
        with tests.testdir() as testdir:

            if 'realdata' not in featdir:
                featdir = tests.make_mock_feat_analysis(op.join(
                    datadir, featdir),
                                                        testdir,
                                                        shape,
                                                        xform,
                                                        pes=False,
                                                        copes=False,
                                                        zstats=False,
                                                        residuals=False,
                                                        clustMasks=False)
            else:
                featdir = op.join(datadir, featdir)

            # Now create a FEATImage. We validate its
            # attributes against the values returned by
            # the functions in featdesign/featanalysis.
            fi = featimage.FEATImage(featdir)
            settings = featanalysis.loadSettings(featdir)
            design = featdesign.FEATFSFDesign(featdir, settings)
            desmat = design.getDesign()
            evnames = [ev.title for ev in design.getEVs()]
            contrastnames, contrasts = featanalysis.loadContrasts(featdir)

            assert np.all(np.isclose(fi.shape, shape))
            assert np.all(np.isclose(fi.voxToWorldMat, xform))

            assert fi.getFEATDir() == featdir
            assert fi.getAnalysisName() == op.splitext(op.basename(featdir))[0]
            assert fi.isFirstLevelAnalysis(
            ) == featanalysis.isFirstLevelAnalysis(settings)
            assert fi.getTopLevelAnalysisDir(
            ) == featanalysis.getTopLevelAnalysisDir(featdir)
            assert fi.getReportFile() == featanalysis.getReportFile(featdir)
            assert fi.hasStats() == featanalysis.hasStats(featdir)
            assert fi.numPoints() == desmat.shape[0]
            assert fi.numEVs() == desmat.shape[1]
            assert fi.evNames() == evnames
            assert fi.numContrasts() == len(contrasts)
            assert fi.contrastNames() == contrastnames
            assert fi.contrasts() == contrasts
            assert np.all(np.isclose(fi.getDesign(), desmat))

            assert fi.thresholds() == featanalysis.getThresholds(settings)

            for ci in range(len(contrasts)):
                result = fi.clusterResults(ci)
                expect = featanalysis.loadClusterResults(featdir, settings, ci)
                assert len(result) == len(expect)
                assert all([
                    rc.nvoxels == ec.nvoxels for rc, ec in zip(result, expect)
                ])