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)
    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)
    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)