Пример #1
0
    def test_getitemCellsize(self):

        grid = ga.ones((100,100), yorigin=1000, xorigin=1200, cellsize=10, origin="ul")

        self.assertTupleEqual(grid[3:4].cellsize, (-10, 10))
        self.assertTupleEqual(grid[0::2, 0::4].cellsize, (-20, 40))
        self.assertTupleEqual(grid[0::3, 0::5].cellsize, (-30, 50))
        self.assertTupleEqual(grid[0::1, 0::7].cellsize, (-10, 70))
        # needs to be extended...
        self.assertTupleEqual(grid[[1,2,5]].cellsize, (-20, 10))
        self.assertTupleEqual(grid[[1,2,4,10]].cellsize, (-30, 10))

        self.assertTupleEqual(grid[[0,10,5]].cellsize, (-25, 10))

        grid = ga.ones((100,100), yorigin=1000, xorigin=1200, cellsize=10,origin="ll")
        self.assertTupleEqual(grid[3:4].cellsize, (10, 10))
        self.assertTupleEqual(grid[0::2, 0::4].cellsize, (20, 40))
        self.assertTupleEqual(grid[0::3, 0::5].cellsize, (30, 50))
        self.assertTupleEqual(grid[0::1, 0::7].cellsize, (10, 70))

        grid = ga.ones((100,100), yorigin=1000, xorigin=1200, cellsize=10, origin="lr")
        self.assertTupleEqual(grid[3:4].cellsize, (10, -10))
 
        grid = ga.ones((100,100), yorigin=1000, xorigin=1200, cellsize=10, origin="ur")
        self.assertTupleEqual(grid[3:4].cellsize, (-10, -10))
Пример #2
0
 def test_incorrectValue(self):
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter("always")
         # With some Python versions w is empty, so skip the test...
         if w:
             ga.ones((200,300), proj=4444) # invalid epsg code 
             self.assertEqual(str(w[0].message), "Projection not understood")
             self.assertEqual(w[0].category, RuntimeWarning)
Пример #3
0
    def test_bbox(self):
        grids = (
            ga.ones((100,100),yorigin=1000,xorigin=1200,origin="ul"),
            ga.ones((100,100),yorigin=1000,xorigin=1200,origin="ll"),
            ga.ones((100,100),yorigin=1000,xorigin=1200,origin="ur"),
            ga.ones((100,100),yorigin=1000,xorigin=1200,origin="lr"),
        )
        expected = (
            {'xmin': 1200, 'ymin': 900, 'ymax': 1000, 'xmax': 1300},
            {'xmin': 1200, 'ymin': 1000, 'ymax': 1100, 'xmax': 1300},
            {'xmin': 1100, 'ymin': 900, 'ymax': 1000, 'xmax': 1200},
            {'xmin': 1100, 'ymin': 1000, 'ymax': 1100, 'xmax': 1200},
        )

        for g, e in zip(grids, expected):
            self.assertDictEqual(g.bbox, e)
Пример #4
0
    def test_getitemCellsize(self):

        grid = ga.ones((100, 100),
                       yorigin=1000,
                       xorigin=1200,
                       cellsize=10,
                       origin="ul")

        self.assertTupleEqual(grid[3:4].cellsize, (-10, 10))
        self.assertTupleEqual(grid[0::2, 0::4].cellsize, (-20, 40))

        self.assertTupleEqual(grid[0::3, 0::5].cellsize, (-30, 50))
        self.assertTupleEqual(grid[0::1, 0::7].cellsize, (-10, 70))
        # # # needs to be extended...
        self.assertTupleEqual(grid[[1, 2, 5]].cellsize, (-20, 10))
        self.assertTupleEqual(grid[[1, 2, 4, 10]].cellsize, (-30, 10))

        self.assertTupleEqual(grid[[0, 10, 5]].cellsize, (-25, 10))

        grid = ga.ones((100, 100),
                       yorigin=1000,
                       xorigin=1200,
                       cellsize=10,
                       origin="ll")
        self.assertTupleEqual(grid[3:4].cellsize, (10, 10))
        self.assertTupleEqual(grid[0::2, 0::4].cellsize, (20, 40))
        self.assertTupleEqual(grid[0::3, 0::5].cellsize, (30, 50))
        self.assertTupleEqual(grid[0::1, 0::7].cellsize, (10, 70))

        grid = ga.ones((100, 100),
                       yorigin=1000,
                       xorigin=1200,
                       cellsize=10,
                       origin="lr")
        self.assertTupleEqual(grid[3:4].cellsize, (10, -10))

        grid = ga.ones((100, 100),
                       yorigin=1000,
                       xorigin=1200,
                       cellsize=10,
                       origin="ur")
        self.assertTupleEqual(grid[3:4].cellsize, (-10, -10))
Пример #5
0
 def test_getitemOrigin(self):
     grids = (
         ga.ones((100, 100), yorigin=1000, xorigin=1200, origin="ul"),
         ga.ones((100, 100), yorigin=1000, xorigin=1200, origin="ll"),
         ga.ones((100, 100), yorigin=1000, xorigin=1200, origin="ur"),
         ga.ones((100, 100), yorigin=1000, xorigin=1200, origin="lr"),
     )
     slices = (
         (slice(3, 4)),
         (slice(3, 4), slice(55, 77, None)),
         (slice(None, None, 7), slice(55, 77, None)),
         (-1, ),
     )
     expected = (((997, 1200), (997, 1255), (1000, 1255), (901, 1200)),
                 ((1096, 1200), (1096, 1255), (1001, 1255), (1000, 1200)),
                 ((997, 1200), (997, 1177), (1000, 1177), (901, 1200)),
                 ((1096, 1200), (1096, 1177), (1001, 1177), (1000, 1200)))
     for i, grid in enumerate(grids):
         for slc, exp in zip(slices, expected[i]):
             self.assertTupleEqual(exp, grid[slc].getOrigin())
             break
         break
Пример #6
0
    def test_bbox(self):
        grids = (
            ga.ones((100, 100), yorigin=1000, xorigin=1200, origin="ul"),
            ga.ones((100, 100), yorigin=1000, xorigin=1200, origin="ll"),
            ga.ones((100, 100), yorigin=1000, xorigin=1200, origin="ur"),
            ga.ones((100, 100), yorigin=1000, xorigin=1200, origin="lr"),
        )
        expected = (
            {
                'xmin': 1200,
                'ymin': 900,
                'ymax': 1000,
                'xmax': 1300
            },
            {
                'xmin': 1200,
                'ymin': 1000,
                'ymax': 1100,
                'xmax': 1300
            },
            {
                'xmin': 1100,
                'ymin': 900,
                'ymax': 1000,
                'xmax': 1200
            },
            {
                'xmin': 1100,
                'ymin': 1000,
                'ymax': 1100,
                'xmax': 1200
            },
        )

        for g, e in zip(grids, expected):
            self.assertDictEqual(g.bbox, e)
Пример #7
0
 def test_getitemOrigin(self):
     grids = (
         ga.ones((100,100),yorigin=1000,xorigin=1200,origin="ul"),
         ga.ones((100,100),yorigin=1000,xorigin=1200,origin="ll"),
         ga.ones((100,100),yorigin=1000,xorigin=1200,origin="ur"),
         ga.ones((100,100),yorigin=1000,xorigin=1200,origin="lr"),
     )
     slices = (
         ( slice(3,4) ),
         ( slice(3,4),slice(55,77,None) ),
         ( slice(None,None,7),slice(55,77,None) ),
         ( -1, ),
     )
     expected = (
         ( (997,  1200), (997,  1255), (1000, 1255), (901,  1200) ),
         ( (1096, 1200), (1096, 1255), (1001, 1255), (1000, 1200) ),
         ( (997,  1200), (997,  1177), (1000, 1177), (901,  1200) ),
         ( (1096, 1200), (1096, 1177), (1001, 1177), (1000, 1200) )
     )
     for i,grid in enumerate(grids):
         for slc,exp in zip(slices,expected[i]):
             self.assertTupleEqual( exp, grid[slc].getOrigin() )
             break
         break
Пример #8
0
 def test_correctValue(self):
     g = ga.ones((200,300), proj=3857) # WGS 84 / Pseudo-Mercator aka Web-Mercator
     self.assertTrue(g.proj)
Пример #9
0
 def test_ones(self):
     shape = (2, 4, 6)
     grid = ga.ones(shape)
     self.assertEqual(grid.shape, shape)
     self.assertTrue(np.all(grid == 1))
Пример #10
0
 def test_ones(self):
     shape = (2,4,6)
     grid = ga.ones(shape)
     self.assertEqual(grid.shape, shape)
     self.assertTrue(np.all(grid == 1))