Example #1
0
    def test_apply_inplace(self):
        msk = np.zeros([8, 8], dtype=np.bool)
        msk[3, 2] = True
        msk[:2, 3:] = True
        val = np.arange(64, dtype=np.float64).reshape([8, 8])
        val_ = val.copy()
        val[msk] = -1
        grid = RegularGrid([0, 0, 1, 1, 0, 0], values=val, nodata_value=-1)
        grid.apply(lambda x: x**2, inplace=True)

        self.assertTrue(np.all(grid[:, :, 0][msk] == -1))
        self.assertTrue(np.all(grid[:, :, 0][~msk] == val_[~msk]**2))
Example #2
0
    def test_apply(self):
        msk = np.zeros([8, 8], dtype=np.bool)
        msk[3, 2] = True
        msk[:2, 3:] = True
        val = np.arange(64, dtype=np.float64).reshape([8, 8])
        val_ = val.copy()
        val[msk] = -1
        grid = RegularGrid([0, 0, 1, 1, 0, 0], values=val, nodata_value=-1)
        newgrid = grid.apply(lambda x: x**2)

        npt.assert_equal(newgrid[msk], -1)
        npt.assert_equal(newgrid[:, :, 0][~msk], val_[~msk]**2)