Exemple #1
0
    def __init__(self, band1, band2, expand = False):
        """
        @param band1    First band (numpy masked array)
        @param band2    Second band (numpy masked array)
        @param expand   If the param is True, use union of categories of the bands and compute NxN crosstable
        """
        QObject.__init__(self)

        if not sizes_equal(band1, band2):
            raise CrossTabError('Sizes of rasters are not equal!')

        band1, band2 = masks_identity(band1, band2, dtype=np.uint8)

        self.X = np.ma.compressed(band1).flatten()
        self.Y = np.ma.compressed(band2).flatten()

        # Compute gradations of the bands
        self.graduation_x = get_gradations(self.X)
        self.graduation_y = get_gradations(self.Y)
        if expand:
            self.graduation_x = list(set(self.graduation_x + self.graduation_y))
            self.graduation_y = self.graduation_x

        rows, cols = len(self.graduation_x), len(self.graduation_y)
        self.shape = (rows, cols)

        self._T = None       # Crosstable
        self.n  = None       # Count of elements in the crosstable
Exemple #2
0
    def __init__(self, band1, band2, expand=False):
        """
        @param band1    First band (numpy masked array)
        @param band2    Second band (numpy masked array)
        @param expand   If the param is True, use union of categories of the bands and compute NxN crosstable
        """
        QObject.__init__(self)

        if not sizes_equal(band1, band2):
            raise CrossTabError('Sizes of rasters are not equal!')

        band1, band2 = masks_identity(band1, band2, dtype=np.uint8)

        self.X = np.ma.compressed(band1).flatten()
        self.Y = np.ma.compressed(band2).flatten()

        # Compute gradations of the bands
        self.graduation_x = get_gradations(self.X)
        self.graduation_y = get_gradations(self.Y)
        if expand:
            self.graduation_x = list(set(self.graduation_x +
                                         self.graduation_y))
            self.graduation_y = self.graduation_x

        rows, cols = len(self.graduation_x), len(self.graduation_y)
        self.shape = (rows, cols)

        self._T = None  # Crosstable
        self.n = None  # Count of elements in the crosstable
Exemple #3
0
    def __init__(self, band1, band2):

        if not sizes_equal(band1, band2):
            raise CrossTabError('Sizes of rasters are not equal!')

        band1, band2 = masks_identity(band1, band2)

        X = np.ma.compressed(band1)
        Y = np.ma.compressed(band2)

        # Compute gradations of the bands
        self.graduation_x = get_gradations(X)
        self.graduation_y = get_gradations(Y)

        rows, cols = len(self.graduation_x), len(self.graduation_y)
        self.shape = (rows, cols)

        # Compute crosstable
        self.T = np.zeros([rows, cols], dtype=int)
        self.n = len(X)                 # Count of unmasked elements  (= sum of all elements of the table)
        for i in range(self.n):
            class_num_x = self.graduation_x.index(X[i])
            class_num_y = self.graduation_y.index(Y[i])
            self.T[class_num_x][class_num_y] +=1
Exemple #4
0
 def test_Size_no_equals(self):
     self.assertEqual(sizes_equal(self.X2, self.Y), False, 'sizes are equal')
Exemple #5
0
 def test_size_equals(self):
     self.assertEqual(sizes_equal(self.X, self.Y), True, 'incorrent size')
Exemple #6
0
 def test_Size_no_equals(self):
     self.assertEqual(sizes_equal(self.X2, self.Y), False,
                      'sizes are equal')
Exemple #7
0
 def test_size_equals(self):
     self.assertEqual(sizes_equal(self.X, self.Y), True, 'incorrent size')