Ejemplo n.º 1
0
    def test_enlarge(self):
        for base in self.grids[1:]:
            bbox = base.bbox
            if base.fill_value is None:
                base.fill_value = -9999
            cellsize = [abs(cs) for cs in base.cellsize]
            newbbox = {
                "ymin": bbox["ymin"] - .7 * cellsize[0],
                "xmin": bbox["xmin"] - 2.5 * cellsize[1],
                "ymax": bbox["ymax"] + 6.1 * cellsize[0],
                "xmax": bbox["xmax"] + .1 * cellsize[1]
            }
            enlrgrid = base.enlarge(**newbbox)
            self.assertEqual(enlrgrid.nrows, base.nrows + 1 + 7)
            self.assertEqual(enlrgrid.ncols, base.ncols + 3 + 1)

        x = np.arange(20).reshape((4, 5))
        grid = ga.array(x,
                        yorigin=100,
                        xorigin=200,
                        origin="ll",
                        cellsize=20,
                        fill_value=-9)
        enlarged = grid.enlarge(xmin=130, xmax=200, ymin=66)
        self.assertDictEqual(enlarged.bbox, {
            'xmin': 120,
            'ymin': 60,
            'ymax': 180,
            'xmax': 300
        })
Ejemplo n.º 2
0
def testArray(shape):
    dinfo = dtypeInfo(np.int32)
    return ga.array(
        data = np.random.randint(dinfo["min"], high=dinfo["max"], size=shape, dtype=np.int32),
        proj = 9001,
        yorigin = 7235561,
        xorigin = 3820288,
        cellsize = 1000,
        fill_value = -9999,
        mode = "L",
    )
Ejemplo n.º 3
0
    def test_full_like(self):
        grid = ga.array(data=np.arange(48).reshape(2, 4, 6),
                        fill_value=-42,
                        yorigin=-15,
                        xorigin=72,
                        ycellsize=33.33,
                        xcellsize=33.33)

        value = -4444
        test = ga.full_like(grid, value)
        self.assertTupleEqual(test.shape, grid.shape)
        self.assertTrue(np.all(test == value))
        self.assertDictEqual(test.header, grid.header)
Ejemplo n.º 4
0
def testArray(shape):
    dinfo = dtypeInfo(np.int32)
    return ga.array(
        data=np.random.randint(dinfo["min"],
                               high=dinfo["max"],
                               size=shape,
                               dtype=np.int32),
        proj=9001,
        yorigin=7235561,
        xorigin=3820288,
        cellsize=1000,
        fill_value=-9999,
        mode="L",
    )
Ejemplo n.º 5
0
    def test_geoloc(self):

        data = np.arange(48).reshape(2, 4, 6)
        xvals = np.array([4, 8, 8.5, 13, 14, 17])
        yvals = np.array([18, 17, 14, 12])
        xvalues, yvalues = np.meshgrid(xvals, yvals)

        gridul = ga.array(data=data,
                          fill_value=-42,
                          yvalues=yvalues,
                          xvalues=xvalues)

        self.assertEqual(gridul.yorigin, yvals[0])
        self.assertEqual(gridul.xorigin, xvals[0])

        gridlr = ga.array(data=data,
                          fill_value=-42,
                          origin="lr",
                          yvalues=yvalues,
                          xvalues=xvalues)

        self.assertEqual(gridlr.yorigin, yvals[-1])
        self.assertEqual(gridlr.xorigin, xvals[-1])
Ejemplo n.º 6
0
    def test_ones_zeros_like(self):
        grid = ga.array(data=np.arange(48).reshape(2, 4, 6),
                        fill_value=-42,
                        yorigin=-15,
                        xorigin=72,
                        ycellsize=33.33,
                        xcellsize=33.33)

        cases = [(ga.ones_like, 1), (ga.zeros_like, 0)]
        for like_func, value in cases:
            test = like_func(grid)
            self.assertTupleEqual(test.shape, grid.shape)
            self.assertTrue(np.all(test == value))
            self.assertDictEqual(test.header, grid.header)
Ejemplo n.º 7
0
def testArray(shape):
    dinfo = dtypeInfo(np.int32)
    data = np.arange(np.prod(shape), dtype=np.float32).reshape(shape)
    out = ga.array(
        # data = np.random.randint(dinfo["min"], high=dinfo["max"], size=shape, dtype=np.int32),
        data=data,
        proj=32633,  # WGS 84 / UTM 33N
        origin="ul",
        yorigin=9000000,
        xorigin=170000,
        cellsize=1000,
        fill_value=-9999,
        color_mode="L")
    return out
Ejemplo n.º 8
0
 def test_array(self):
     data = np.arange(48).reshape(2,4,6)
     fill_value = -42
     yorigin = -15
     xorigin = 72
     cellsize = (33.33, 33.33)
     grid = ga.array(
         data=data, fill_value=fill_value,
         yorigin=yorigin, xorigin=xorigin,
         cellsize=cellsize
     )
     self.assertEqual(grid.shape, data.shape)
     self.assertEqual(grid.fill_value, fill_value)
     self.assertEqual(grid.yorigin, yorigin)
     self.assertEqual(grid.xorigin, xorigin)
     self.assertEqual(grid.cellsize, cellsize)
     self.assertTrue(np.all(grid == data))
Ejemplo n.º 9
0
 def test_array(self):
     data = np.arange(48).reshape(2,4,6)
     fill_value = -42
     yorigin = -15
     xorigin = 72
     cellsize = (33.33, 33.33)
     grid = ga.array(
         data=data, fill_value=fill_value,
         yorigin=yorigin, xorigin=xorigin,
         cellsize=cellsize
     )
     self.assertEqual(grid.shape, data.shape)
     self.assertEqual(grid.fill_value, fill_value)
     self.assertEqual(grid.yorigin, yorigin)
     self.assertEqual(grid.xorigin, xorigin)
     self.assertEqual(grid.cellsize, cellsize)
     self.assertTrue(np.all(grid == data))
Ejemplo n.º 10
0
    def test_getitem(self):
        for base in self.grids:
            # simplifies the tests...
            base = base[0] if base.ndim > 2 else base
            grid = base.copy()
            slices = (base < 3, base == 10, np.where(base > 6),
                      (slice(None, None, None), slice(0, 4,
                                                      3)), (1, 1), Ellipsis)

            idx = np.arange(12, 20)
            self.assertTrue(np.all(grid[idx].data == base[ga.array(idx)].data))
            for i, s in enumerate(slices):
                slc1 = grid[s]
                slc2 = base[s]
                self.assertTrue(np.all(slc1.data == slc2.data))
                try:
                    self.assertTrue(np.all(slc1.mask == slc2.mask))
                except AttributeError:  # __getitem__ returned a scalar
                    pass
Ejemplo n.º 11
0
 def test_getitem(self):        
     for base in self.grids:
         # simplifies the tests...
         base = base[0] if base.ndim > 2 else base
         grid = base.copy()
         slices = (
              base < 3,
              base == 10,
              np.where(base>6),
              (slice(None,None,None),slice(0,4,3)),(1,1),Ellipsis
         )
         
         idx = np.arange(12,20)
         self.assertTrue(np.all(grid[idx].data == base[ga.array(idx)].data))
         for i,s in enumerate(slices):
             slc1 = grid[s]
             slc2 = base[s]
             self.assertTrue(np.all(slc1.data == slc2.data))
             try:
                 self.assertTrue(np.all(slc1.mask == slc2.mask))
             except AttributeError: # __getitem__ returned a scalar
                 pass 
Ejemplo n.º 12
0
    def test_enlarge(self):
        for base in self.grids[1:]:
            bbox = base.bbox
            if base.fill_value is None:
                base.fill_value = -9999
            cellsize = map(abs, base.cellsize)
            newbbox = {
                "ymin" : bbox["ymin"] -  .7 * cellsize[0],
                "xmin" : bbox["xmin"] - 2.5 * cellsize[1],
                "ymax" : bbox["ymax"] + 6.1 * cellsize[0],
                "xmax" : bbox["xmax"] +  .1 * cellsize[1]
            }
            enlrgrid = base.enlarge(**newbbox)
            self.assertEqual(enlrgrid.nrows, base.nrows + 1 + 7)
            self.assertEqual(enlrgrid.ncols, base.ncols + 3 + 1)

        x = np.arange(20).reshape((4,5))
        grid = ga.array(x, yorigin=100, xorigin=200, origin="ll", cellsize=20, fill_value=-9)
        enlarged = grid.enlarge(xmin=130, xmax=200, ymin=66)
        self.assertDictEqual(
            enlarged.bbox, 
            {'xmin': 120, 'ymin': 60, 'ymax': 180, 'xmax': 300}    
        )