示例#1
0
    def test_local_pyramid(self):
        arr = np.zeros((1, 250, 250))
        epsg_code = 3857
        extent = Extent(0.0, 0.0, 10.0, 10.0)

        tile = Tile(arr, 'FLOAT', None)
        projected_extent = ProjectedExtent(extent, epsg_code)

        rdd = BaseTestClass.pysc.parallelize([(projected_extent, tile)])

        raster_rdd = RasterLayer.from_numpy_rdd(LayerType.SPATIAL, rdd)
        laid_out = raster_rdd.tile_to_layout(LocalLayout(250))

        # Single tile is at level 0
        result = laid_out.pyramid()
        assert result.max_zoom == 0

        laid_out = raster_rdd.tile_to_layout(LocalLayout(25))
        result = laid_out.pyramid()

        assert result.max_zoom == 4
        assert result.levels[4].layer_metadata.tile_layout.layoutCols == 10
        assert result.levels[3].layer_metadata.tile_layout.layoutCols == 5
        assert result.levels[2].layer_metadata.tile_layout.layoutCols == 3
        assert result.levels[1].layer_metadata.tile_layout.layoutCols == 2
        assert result.levels[0].layer_metadata.tile_layout.layoutCols == 1
示例#2
0
    def test_read(self):
        for x in range(11, 0, -1):
            actual_layer = query(self.uri, self.layer_name,
                                 x).tile_to_layout(LocalLayout(),
                                                   self.metadata.crs)
            expected_layer = self.result.levels[x].tile_to_layout(
                LocalLayout(), self.metadata.crs)

            actual_md = actual_layer.layer_metadata
            expected_md = expected_layer.layer_metadata

            self.assertEqual(actual_md.tile_layout, expected_md.tile_layout)
            self.assertEqual(actual_md.layout_definition,
                             expected_md.layout_definition)
            self.assertEqual(actual_md.bounds, expected_md.bounds)
    def test_partition_preservation(self):
        partition_states = []
        strategy = SpatialPartitionStrategy(16)

        tiled = self.rdd.tile_to_layout()

        tiled2 = self.rdd.tile_to_layout(partition_strategy=strategy)
        partition_states.append(tiled2.get_partition_strategy())

        added_layer = (tiled + tiled2) * 0.75
        partition_states.append(added_layer.get_partition_strategy())

        local_max_layer = added_layer.local_max(tiled)
        partition_states.append(local_max_layer.get_partition_strategy())

        focal_layer = local_max_layer.focal(Operation.MAX, Square(1))
        partition_states.append(focal_layer.get_partition_strategy())

        reprojected_layer = focal_layer.tile_to_layout(
            layout=LocalLayout(), target_crs=3857, partition_strategy=strategy)
        partition_states.append(reprojected_layer.get_partition_strategy())

        pyramided = reprojected_layer.pyramid()
        partition_states.append(
            pyramided.levels[pyramided.max_zoom].get_partition_strategy())

        self.assertTrue(all(x == partition_states[0]
                            for x in partition_states))
示例#4
0
    def test_different_crs_float(self):
        result = BaseTestClass.rdd.tile_to_layout(layout=LocalLayout(
            self.cols),
                                                  target_crs="EPSG:4324")
        new_metadata = result.layer_metadata

        self.assertEqual(self.expected_crs, new_metadata.crs)
示例#5
0
    def test_same_crs_zoom(self):
        result = BaseTestClass.rdd.tile_to_layout(layout=LocalLayout(
            self.cols),
                                                  target_crs="EPSG:4326")
        new_metadata = result.layer_metadata

        self.assertTrue("+datum=WGS84" in new_metadata.crs)
示例#6
0
    def test_to_geotiff_rdd_tiledrasterlayer(self):
        tiled_rdd = self.rdd.tile_to_layout(LocalLayout(tile_size=128))
        tiled_collected = tiled_rdd.to_numpy_rdd().first()[1]

        geotiff_rdd = tiled_rdd.to_geotiff_rdd()
        geotiff_collected = geotiff_rdd.first()[1]

        def to_geotiff(x):
            with tempfile.NamedTemporaryFile() as temp:
                temp.write(x)
                temp_path = pathlib.Path(temp.name)

                with rasterio.open(str(temp_path)) as src:
                    self.assertTrue(src.is_tiled)
                    data = src.read()
                    return Tile(data, self.mapped_types[str(data.dtype)],
                                src.nodata)

        rasterio_geotiff = to_geotiff(geotiff_collected)

        self.assertTrue(
            (tiled_collected.cells == rasterio_geotiff.cells).all())
        self.assertEqual(tiled_collected.cell_type, rasterio_geotiff.cell_type)
        self.assertEqual(tiled_collected.no_data_value,
                         rasterio_geotiff.no_data_value)
示例#7
0
class CombineSpatialBandsTest(BaseTestClass):
    layer_1 = create_spatial_layer(tile_1)
    layer_2 = create_spatial_layer(tile_2)
    layer_3 = create_spatial_layer(tile_3)

    r1 = BaseTestClass.pysc.parallelize(layer_1)
    r2 = BaseTestClass.pysc.parallelize(layer_2)
    r3 = BaseTestClass.pysc.parallelize(layer_3)

    rdd_1 = RasterLayer.from_numpy_rdd(LayerType.SPATIAL, r1)
    rdd_2 = RasterLayer.from_numpy_rdd(LayerType.SPATIAL, r2)
    rdd_3 = RasterLayer.from_numpy_rdd(LayerType.SPATIAL, r3)

    tiled_rdd_1 = rdd_1.tile_to_layout(LocalLayout(5, 5))
    tiled_rdd_2 = rdd_2.tile_to_layout(LocalLayout(5, 5))
    tiled_rdd_3 = rdd_3.tile_to_layout(LocalLayout(5, 5))

    @pytest.fixture(autouse=True)
    def tearDown(self):
        yield
        BaseTestClass.pysc._gateway.close()

    def test_combine_bands_raster_layers(self):
        actual = combine_bands([self.rdd_1, self.rdd_2,
                                self.rdd_3]).to_numpy_rdd().values().collect()

        for x in actual:
            self.assertEqual(x.cells.shape, (3, 5, 5))
            self.assertTrue((x.cells[0, :, :] == first).all())
            self.assertTrue((x.cells[1, :, :] == second).all())
            self.assertTrue((x.cells[2, :, :] == third).all())

    def test_combine_bands_tiled_layers(self):
        actual = combine_bands([self.tiled_rdd_3, self.tiled_rdd_2, self.tiled_rdd_1]) \
                .to_numpy_rdd().values().collect()

        for x in actual:
            self.assertEqual(x.cells.shape, (3, 5, 5))
            self.assertTrue((x.cells[0, :, :] == third).all())
            self.assertTrue((x.cells[1, :, :] == second).all())
            self.assertTrue((x.cells[2, :, :] == first).all())
    def test_segment_tiles(self):
        # GeoTrellis will read GeoTiff Segments given no window size
        # Retile them to match Rasterio read and check the cell values
        geotrellis_tiles = self.read_multiband_geotrellis()\
                               .tile_to_layout(LocalLayout(512))\
                               .to_numpy_rdd().collect()
        # TODO: assert there is only one geotrellis tile
        geotrellis_tile = dict(geotrellis_tiles)[SpatialKey(0, 0)]

        rasterio_tiles = self.read_geotiff_rasterio([self.file_path], False)
        self.assertEquals(len(rasterio_tiles), 1)
        rasterio_tile = rasterio_tiles[0]

        self.assertTilesEqual(geotrellis_tile.cells, rasterio_tile['cells'])
示例#9
0
 def test_tile_to_local_layout(self):
     tiled = self.layer.tile_to_layout(LocalLayout(5))
     assert tiled.layer_metadata.extent == Extent(0, 0, 10, 6)
     assert tiled.layer_metadata.tile_layout == TileLayout(2, 2, 5, 5)
示例#10
0
    def test_to_to_layout_with_partitioner(self):
        strategy = SpatialPartitionStrategy(4)
        tiled = self.layer.tile_to_layout(LocalLayout(5),
                                          partition_strategy=strategy)

        self.assertEqual(tiled.get_partition_strategy(), strategy)
 def test_read_with_reproject_local_gdal(self):
     self.read(LocalLayout(128, 256), ReadMethod.GDAL, target_crs=3857)
 def test_read_with_reproject_local_geotrellis(self):
     self.read(LocalLayout(128, 256), ReadMethod.GEOTRELLIS, target_crs=3857)
 def test_read_no_reproject_local_gdal(self):
     self.read(LocalLayout(256, 256), ReadMethod.GDAL)
 def test_read_no_reproject_local_geotrellis(self):
     self.read(LocalLayout(256, 256), ReadMethod.GEOTRELLIS)
示例#15
0
    def test_collection_floating(self):
        result = self.rdd.collect_metadata(LocalLayout(self.cols))

        self.assertEqual(result.extent, self.extent)
        self.assertEqual(result.layout_definition.extent, self.extent)
        self.assertEqual(result.layout_definition.tileLayout, self.layout)
 def test_read_ordered_no_reproject_local_geotrellis(self):
     self.read(LocalLayout(256, 256), ReadMethod.GEOTRELLIS, multiplex=True)