Exemplo n.º 1
0
    def test_getTransition(self):
        self.table = CrossTable(self.X, self.Y)

        fromClass, toClass = 1, 2
        self.assertEqual(self.table.getTransition(fromClass, toClass), 0)
        fromClass, toClass = 1, 3
        self.assertEqual(self.table.getTransition(fromClass, toClass), 3)
Exemplo n.º 2
0
    def test_init(self):
        mess = 'compute table failed'
        table = CrossTable(self.X, self.Y)
        crTab = table.getCrosstable()
        for i in range(self.r):
            self.assertEqual(all(crTab[i]), all(self.T[i]), mess)
        self.assertEqual(all(table.getSumRows()), all(self.sum_r), mess)
        self.assertEqual(all(table.getSumCols()), all(self.sum_s), mess)
        self.assertEqual(table.n, self.total, mess)
        r, s = table.shape
        self.assertEqual(r, self.r, mess)
        self.assertEqual(s, self.s, mess)

        x = np.ma.array([1, 2, 3, 4, 5, 5])
        y = np.ma.array([1, 2, 3, 3, 5, 6])
        self.assertRaises(CrossTable(x, y))

        table = CrossTable(x, y, expand=True)
        for i in [1, 2, 3, 4, 5, 6]:
            assert i in table.graduation_x
            assert i in table.graduation_y
Exemplo n.º 3
0
    def __init__(self, initRaster, finalRaster):
        QObject.__init__(self)

        if not initRaster.geoDataMatch(finalRaster):
            raise CrossTabManagerError('Geometries of the raster maps are different!')

        if initRaster.getBandsCount() + finalRaster.getBandsCount() != 2:
            raise CrossTabManagerError("An input raster has more then one band. Use 1-band rasters!")

        self.pixelArea = initRaster.getPixelArea()

        self.crosstable = CrossTable(initRaster.getBand(1), finalRaster.getBand(1))

        self.crosstable.rangeChanged.connect(self.__crosstableProgressRangeChanged)
        self.crosstable.updateProgress.connect(self.__crosstableProgressChanged)
        self.crosstable.crossTableFinished.connect(self.__crosstableFinished)
        self.crosstable.errorReport.connect(self.__crosstableError)
Exemplo n.º 4
0
    def test_expectedTable(self):
        # CrossTable:
        # [2, 0, 3],
        # [2, 1, 0],

        table = CrossTable(self.X, self.Y)
        tab = table.getExpectedTable()
        answer = [[20 / 8.0, 5 / 8.0, 15 / 8.0], [12 / 8.0, 3 / 8.0, 9 / 8.0]]
        np.testing.assert_array_equal(answer, tab)

        tab = table.getExpectedProbtable()
        answer = [[20 / 64.0, 5 / 64.0, 15 / 64.0],
                  [12 / 64.0, 3 / 64.0, 9 / 64.0]]
        np.testing.assert_array_equal(answer, tab)

        np.testing.assert_array_equal(table.getProbCols(),
                                      [4.0 / 8, 1.0 / 8, 3.0 / 8])
        np.testing.assert_array_equal(table.getProbRows(), [5.0 / 8, 3.0 / 8])
Exemplo n.º 5
0
 def calculateCrosstable(self):
     try:
         self.rangeChanged.emit('Initialization...', 2)
         self.updateProgress.emit()
         self.crosstable = CrossTable(self.X, self.Y, expand=self.expand)
         self.updateProgress.emit()
         self.__propagateCrossTableSignals()
         self.crosstable.computeCrosstable()
     except MemoryError:
         self.errorReport.emit(
             self.tr(
                 "The system out of memory during cross table calculation"))
         raise
     except:
         self.errorReport.emit(
             self.tr(
                 "An unknown error occurs during cross table calculation"))
         raise
     finally:
         self.processFinished.emit()