Пример #1
0
    def test_add_masked_rasters(self):
        raster1 = self.masked_raster(self.values, self.mask)
        raster2 = raster1
        raster_we_got = raster1 + raster2

        values_we_want = [[-4, -2], [0, ft.no_data_value(fern.int64)], [2, 4]]
        mask_we_want = self.mask
        raster_we_want = self.masked_raster(values_we_want, mask_we_want)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)
Пример #2
0
    def test_add_float_masked_raster(self):
        float_ = 5.0
        raster = self.masked_raster(self.values, self.mask)
        raster_we_got = float_ + raster

        values_we_want = [[3, 4], [5, ft.no_data_value(fern.int64)], [6, 7]]
        mask_we_want = self.mask
        raster_we_want = self.masked_raster(values_we_want,
                                            mask_we_want,
                                            value_type=fern.int64)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)
Пример #3
0
    def test_add_masked_raster_int(self):
        raster = self.masked_raster(self.values, self.mask)
        int_ = 5
        raster_we_got = raster + int_

        values_we_want = [[3, 4], [5, ft.no_data_value(fern.int64)], [6, 7]]
        mask_we_want = self.mask
        raster_we_want = self.masked_raster(values_we_want,
                                            mask_we_want,
                                            value_type=fern.int64)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)
Пример #4
0
    def test_multiply_float_masked_raster(self):
        float_ = 5.0
        raster = self.masked_raster(self.values, self.mask)
        raster_we_got = float_ * raster

        values_we_want = [[-10, -5], [0, ft.no_data_value(fern.int64)],
                          [5, 10]]
        mask_we_want = self.mask
        raster_we_want = self.masked_raster(values_we_want,
                                            mask_we_want,
                                            value_type=fern.int64)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)
Пример #5
0
    def test_add_masked_rasters(self):
        raster1 = self.masked_raster(self.values, self.mask)
        raster2 = raster1
        raster_we_got = raster1 + raster2

        values_we_want = [
            [ -4,           -2],
            [  0, ft.no_data_value(fern.int64)],
            [  2,            4]]
        mask_we_want = self.mask
        raster_we_want = self.masked_raster(values_we_want, mask_we_want)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)
Пример #6
0
    def test_multiply_float_masked_raster(self):
        float_ = 5.0
        raster = self.masked_raster(self.values, self.mask)
        raster_we_got = float_ * raster

        values_we_want = [
            [-10,           -5],
            [  0, ft.no_data_value(fern.int64)],
            [  5,           10]]
        mask_we_want = self.mask
        raster_we_want = self.masked_raster(values_we_want, mask_we_want,
            value_type=fern.int64)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)
Пример #7
0
    def test_add_float_masked_raster(self):
        float_ = 5.0
        raster = self.masked_raster(self.values, self.mask)
        raster_we_got = float_ + raster

        values_we_want = [
            [  3,            4],
            [  5, ft.no_data_value(fern.int64)],
            [  6,            7]]
        mask_we_want = self.mask
        raster_we_want = self.masked_raster(values_we_want, mask_we_want,
            value_type=fern.int64)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)
Пример #8
0
    def test_add_masked_raster_int(self):
        raster = self.masked_raster(self.values, self.mask)
        int_ = 5
        raster_we_got = raster + int_

        values_we_want = [
            [  3,            4],
            [  5, ft.no_data_value(fern.int64)],
            [  6,            7]]
        mask_we_want = self.mask
        raster_we_want = self.masked_raster(values_we_want, mask_we_want,
            value_type=fern.int64)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)
Пример #9
0
    def test_pcraster_example(self):

        values = [
            [  70,  70,  80, -999,  120 ],
            [  70,  70,  90, -999, -999 ],
            [  70,  70, 100,  140,  280 ],
            [ 180, 160, 110,  160,  320 ],
            [ 510, 440, 300,  400,  480 ] ]
        mask = [
            [False, False, False,  True, False ],
            [False, False, False,  True,  True ],
            [False, False, False, False, False ],
            [False, False, False, False, False ],
            [False, False, False, False, False ] ]
        origin = (0.0, 0.0)
        cell_sizes = (50.0, 50.0)

        dem = fern.MaskedRaster(
            values=values,
            mask=mask,
            origin=origin,
            cell_sizes=cell_sizes,
            value_type=fern.float32)

        raster_we_got = fa.slope(dem)

        no_data = ft.no_data_value(fern.float32)

        values_we_want = [
            [ 0.01178515, 0.11441274, 0.39392081, no_data   , 0.67342925],
            [ 0.1296362 , 0.20615529, 0.60374987, no_data   , no_data   ],
            [ 1.30181491, 0.77540314, 0.64250487, 1.73150945, 1.86823785],
            [ 3.73464012, 3.54153919, 2.576092  , 3.01537728, 2.36008477],
            [ 2.75834608, 3.06698918, 2.58792615, 2.65845108, 1.64738858]]
        mask_we_want = mask
        raster_we_want = self.masked_raster(values_we_want, mask_we_want,
            cell_sizes=cell_sizes, value_type=fern.float32)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)
Пример #10
0
    def test_pcraster_example(self):

        values = [[70, 70, 80, -999, 120], [70, 70, 90, -999, -999],
                  [70, 70, 100, 140, 280], [180, 160, 110, 160, 320],
                  [510, 440, 300, 400, 480]]
        mask = [[False, False, False, True, False],
                [False, False, False, True, True],
                [False, False, False, False, False],
                [False, False, False, False, False],
                [False, False, False, False, False]]
        origin = (0.0, 0.0)
        cell_sizes = (50.0, 50.0)

        dem = fern.MaskedRaster(values=values,
                                mask=mask,
                                origin=origin,
                                cell_sizes=cell_sizes,
                                value_type=fern.float32)

        raster_we_got = fa.slope(dem)

        no_data = ft.no_data_value(fern.float32)

        values_we_want = [
            [0.01178515, 0.11441274, 0.39392081, no_data, 0.67342925],
            [0.1296362, 0.20615529, 0.60374987, no_data, no_data],
            [1.30181491, 0.77540314, 0.64250487, 1.73150945, 1.86823785],
            [3.73464012, 3.54153919, 2.576092, 3.01537728, 2.36008477],
            [2.75834608, 3.06698918, 2.58792615, 2.65845108, 1.64738858]
        ]
        mask_we_want = mask
        raster_we_want = self.masked_raster(values_we_want,
                                            mask_we_want,
                                            cell_sizes=cell_sizes,
                                            value_type=fern.float32)

        self.assertMaskedRasterEqual(raster_we_got, raster_we_want)