Пример #1
0
    def test_ward_spatial_scikit_with_mask(self):
        from pyhrf.parcellation import parcellation_dist, parcellation_ward_spatial
        from pyhrf.graph import graph_from_lattice, kerMask2D_4n
        from pyhrf.ndarray import expand_array_in_mask

        if debug:
            print 'data:'
            print self.p1
            print ''

        mask = self.p1 != 0
        graph = graph_from_lattice(mask, kerMask2D_4n)

        X = self.p1[np.where(mask)].reshape(-1,1)

        labels = parcellation_ward_spatial(X, n_clusters=4, graph=graph)

        labels = expand_array_in_mask(labels, mask)



        # print 'labels:'
        # print labels

        #+1 because parcellation_dist sees 0 as background:
        dist = parcellation_dist(self.p1+1, labels+1)[0]
        self.assertEqual(dist, 0)
Пример #2
0
    def test_ward_spatial_scikit(self):
        from pyhrf.parcellation import parcellation_dist, \
            parcellation_ward_spatial
        from pyhrf.graph import graph_from_lattice, kerMask2D_4n

        X = np.reshape(self.p1, (-1, 1))
        graph = graph_from_lattice(np.ones(self.p1.shape), kerMask2D_4n)

        labels = parcellation_ward_spatial(X, n_clusters=5, graph=graph)

        labels = np.reshape(labels, self.p1.shape)
        # +1 because parcellation_dist sees 0 as background
        dist = parcellation_dist(self.p1 + 1, labels + 1)[0]
        self.assertEqual(dist, 0)
Пример #3
0
    def test_parcellation_distance(self):

        from pyhrf.parcellation import parcellation_dist
        #dist = 4 (cost method: intersection size)

        # print 'p1:'
        # print self.p1

        # print 'p2:'
        # print self.p2

        dist, cano_parcellation = parcellation_dist(self.p1, self.p2)

        # print 'cano_parcellation:'
        # print cano_parcellation

        self.assertEqual(dist, 4)
Пример #4
0
    def test_ward_spatial_cmd(self):
        from pyhrf.parcellation import parcellation_dist

        output_file = op.join(self.tmp_dir, 'parcellation_output_test.nii')

        nparcels = 4
        cmd = 'pyhrf_parcellate_glm -m %s %s %s -o %s -v %d ' \
            '-n %d -t ward_spatial ' \
            % (self.mask_fn, self.p1_fn, self.p2_fn, output_file,
               logger.getEffectiveLevel(), nparcels)
        if os.system(cmd) != 0:
            raise Exception('"' + cmd + '" did not execute correctly')
        logger.info('cmd: %s', cmd)

        labels = xndarray.load(output_file).data
        logger.info('labels.dtype:%s', str(labels.dtype))
        dist = parcellation_dist(self.p1, labels)[0]
        logger.info('dist:%d', dist)
        self.assertEqual(dist, 0)
Пример #5
0
    def test_ward_spatial_cmd(self):
        from pyhrf.parcellation import parcellation_dist

        #pyhrf.verbose.verbosity = 2
        output_file = op.join(self.tmp_dir,'parcellation_output_test.nii')

        nparcels = 4
        cmd = 'pyhrf_parcellate_glm -m %s %s %s -o %s -v %d ' \
            '-n %d -t ward_spatial ' \
        %(self.mask_fn, self.p1_fn, self.p2_fn, output_file,
          pyhrf.verbose.verbosity, nparcels)
        if os.system(cmd) != 0 :
            raise Exception('"' + cmd + '" did not execute correctly')
        pyhrf.verbose(1, 'cmd: %s' %cmd)

        labels = xndarray.load(output_file).data
        pyhrf.verbose(2, 'labels.dtype:%s' %str(labels.dtype))
        dist = parcellation_dist(self.p1, labels)[0]
        pyhrf.verbose(2, 'dist:%d' %dist)
        self.assertEqual(dist, 0)
Пример #6
0
    def test_ward_spatial_scikit_with_mask(self):
        from pyhrf.parcellation import parcellation_dist, parcellation_ward_spatial
        from pyhrf.graph import graph_from_lattice, kerMask2D_4n
        from pyhrf.ndarray import expand_array_in_mask

        if debug:
            print 'data:'
            print self.p1
            print ''

        mask = self.p1 != 0
        graph = graph_from_lattice(mask, kerMask2D_4n)

        X = self.p1[np.where(mask)].reshape(-1, 1)

        labels = parcellation_ward_spatial(X, n_clusters=4, graph=graph)

        labels = expand_array_in_mask(labels, mask)
        #+1 because parcellation_dist sees 0 as background:
        dist = parcellation_dist(self.p1 + 1, labels + 1)[0]
        self.assertEqual(dist, 0)
Пример #7
0
    def test_parcellation_distance(self):

        from pyhrf.parcellation import parcellation_dist

        dist, cano_parcellation = parcellation_dist(self.p1, self.p2)
        self.assertEqual(dist, 4)