當前位置: 首頁>>代碼示例>>Python>>正文


Python Raster.getYSize方法代碼示例

本文整理匯總了Python中molusce.algorithms.dataprovider.Raster.getYSize方法的典型用法代碼示例。如果您正苦於以下問題:Python Raster.getYSize方法的具體用法?Python Raster.getYSize怎麽用?Python Raster.getYSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在molusce.algorithms.dataprovider.Raster的用法示例。


在下文中一共展示了Raster.getYSize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestRaster

# 需要導入模塊: from molusce.algorithms.dataprovider import Raster [as 別名]
# 或者: from molusce.algorithms.dataprovider.Raster import getYSize [as 別名]
class TestRaster (unittest.TestCase):
    def setUp(self):
        self.r1 = Raster('examples/multifact.tif')
        self.r2 = Raster('examples/sites.tif')
        self.r3 = Raster('examples/two_band.tif')

        # r1
        data1 = np.array(
            [
                [1,1,3],
                [3,2,1],
                [0,3,1]
            ])
        # r2
        data2 = np.array(
            [
                [1,2,1],
                [1,2,1],
                [0,1,2]
            ])
        mask = [
            [False, False, False],
            [False, False, False],
            [False, False, False]
        ]
        self.data1 = ma.array(data=data1, mask=mask)
        self.data2 = ma.array(data=data2, mask=mask)

    def test_RasterInit(self):
        self.assertEqual(self.r1.getBandsCount(), 1)
        band = self.r1.getBand(1)
        shape = band.shape
        x = self.r1.getXSize()
        y = self.r1.getYSize()
        self.assertEqual(shape, (x,y))

        self.assertEqual(self.r2.getBandsCount(), 1)
        band = self.r2.getBand(1)
        assert_array_equal(band, self.data2)

        self.assertTrue(self.r1.geoDataMatch(self.r2))

        self.assertTrue(self.r1.isMetricProj())


    def test_getBandStat(self):
        stat = self.r1.getBandStat(1)
        self.assertAlmostEqual(stat['mean'], 15.0/9)
        self.assertAlmostEqual(stat['std'], np.sqrt(10.0/9))

    def test_normalize(self):
        multifact = [
            [1,1,3],
            [3,2,1],
            [0,3,1],
        ]

        # Normalize using std and mean
        r1 = Raster('examples/multifact.tif')
        r1.normalize()
        r1.denormalize()
        assert_array_equal(r1.getBand(1), multifact)

        # Normalize using min and max
        r1 = Raster('examples/multifact.tif')
        r1.normalize(mode='maxmin')
        r1.denormalize()
        assert_array_equal(r1.getBand(1), multifact)

        # Two normalization procedures
        r1 = Raster('examples/multifact.tif')
        r1.normalize()
        r1.normalize(mode='maxmin')
        r1.denormalize()
        assert_array_equal(r1.getBand(1), multifact)
        r1 = Raster('examples/multifact.tif')
        r1.normalize(mode='maxmin')
        r1.normalize()
        r1.denormalize()
        assert_array_equal(r1.getBand(1), multifact)


    def test_getNeighbours(self):
        neighbours = self.r2.getNeighbours(row=1,col=0, size=0)
        self.assertEqual(neighbours, [[1]])

        neighbours = self.r2.getNeighbours(row=1,col=1, size=1)
        assert_array_equal(neighbours, [self.data2])

        neighbours = self.r3.getNeighbours(row=1,col=1, size=1)
        assert_array_equal(neighbours, [self.data2, self.data1])

        # Check pixel on the raster bound and nonzero neighbour size
        self.assertRaises(ProviderError, self.r2.getNeighbours, col=1, row=0, size=1)
        self.assertRaises(ProviderError, self.r2.getNeighbours, col=1, row=1, size=2)

    def test_geodata(self):
        geodata = self.r1.getGeodata()
        self.r1.setGeoData(geodata)
        geodata['xSize'] = geodata['xSize'] + 10
#.........這裏部分代碼省略.........
開發者ID:asiaairsurvey,項目名稱:molusce,代碼行數:103,代碼來源:test_dataprovider.py


注:本文中的molusce.algorithms.dataprovider.Raster.getYSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。