Ejemplo n.º 1
0
def test_FEATImage_imageAccessors():

    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)
            else:
                featdir = op.join(datadir, featdir)

            shape4D = shape
            shape = shape4D[:3]

            fi = featimage.FEATImage(featdir)
            nevs = fi.numEVs()
            ncons = fi.numContrasts()

            # Testing the FEATImage intenral cache
            for i in range(2):
                assert fi.getResiduals().shape == shape4D

                for ev in range(nevs):
                    assert fi.getPE(ev).shape == shape
                for con in range(ncons):
                    assert fi.getCOPE(con).shape == shape
                    assert fi.getZStats(con).shape == shape
                    assert fi.getClusterMask(con).shape == shape
Ejemplo n.º 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
Ejemplo n.º 3
0
def test_FEATImage_nostats():

    featdir = op.join(datadir, '1stlevel_nostats.feat')
    shape = (4, 4, 5, 45)

    with tests.testdir() as testdir:

        featdir = tests.make_mock_feat_analysis(featdir, testdir, shape)
        fi = featimage.FEATImage(featdir)

        assert fi.getDesign() is None
        assert fi.numPoints() == 0
        assert fi.numEVs() == 0
        assert fi.evNames() == []

        with pytest.raises(Exception):
            fi.fit([1, 2, 3], (2, 2, 2))

        with pytest.raises(Exception):
            fi.partialFit([1, 2, 3], (2, 2, 2))
Ejemplo n.º 4
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)
                ])