示例#1
0
    def test_ones(self, name):
        pipeline = Pipeline(
            get_project_path() / 'test/data/pipeline/ones.tif',
            get_project_path() / f'test/data/pipeline/{name}.tif', 45, 45)
        pipeline.run()
        result = pipeline.result

        window = get_corresponding_window(
            get_project_path() / 'test/data/pipeline/ones.tif',
            get_project_path() / f'test/data/pipeline/{name}.tif')
        pixels = get_pixels(window)
        rectangle = pixels
        inner_rectangle = rectangle[np.logical_and(
            np.logical_and(rectangle[:, 0] != window[0][0],
                           rectangle[:, 1] != window[1][0]),
            np.logical_and(rectangle[:, 0] != window[0][1] - 1,
                           rectangle[:, 1] != window[1][1] - 1))]

        # check result is lesser equal 9 everywhere
        assert (result <= 9).all()
        # check that all counts on the diagonal are greater 0 and less or equal 3
        assert (result[rectangle[:, 0], rectangle[:, 1]] > 0).all()
        assert (result[inner_rectangle[:, 0], inner_rectangle[:,
                                                              1]] == 9).all()
        # check that result is 0 everywhere else
        result[rectangle[:, 0], rectangle[:, 1]] = 0
        assert (result == 0).all()
示例#2
0
    def test_bottom_edge(self, name):
        pipeline = Pipeline(
            get_project_path() / 'test/data/pipeline/bottom_edge.tif',
            get_project_path() / f'test/data/pipeline/{name}.tif', 45, 45)
        pipeline.run()
        result = pipeline.result

        height, width = get_shape(get_project_path() /
                                  f'test/data/pipeline/{name}.tif')

        if height == width == 30:
            assert (result == 0).all()
        else:
            window = get_corresponding_window(
                get_project_path() / 'test/data/pipeline/bottom_edge.tif',
                get_project_path() / f'test/data/pipeline/{name}.tif')
            pixels = get_pixels(window)
            horizontal_edge = pixels[pixels[:, 0] == window[0][1] - 1]
            # check result is lesser equal 9 everywhere
            assert (result <= 9).all()
            # check that all counts on the vertical edge are greater 0 and less or equal 3
            assert (result[horizontal_edge[:, 0], horizontal_edge[:, 1]] >
                    0).all() and (result[horizontal_edge[:, 0],
                                         horizontal_edge[:, 1]] <= 3).all()
            # check that result is 0 everywhere else
            result[horizontal_edge[:, 0], horizontal_edge[:, 1]] = 0
            assert (result == 0).all()
示例#3
0
    def test_zeros(self, name):
        pipeline = Pipeline(
            get_project_path() / 'test/data/pipeline/zeros.tif',
            get_project_path() / f'test/data/pipeline/{name}.tif', 45, 45)
        pipeline.run()
        result = pipeline.result

        # check result is 0 everywhere
        assert (result == 0).all()
示例#4
0
    def test_left_edge(self, name):
        pipeline = Pipeline(
            get_project_path() / 'test/data/pipeline/left_edge.tif',
            get_project_path() / f'test/data/pipeline/{name}.tif', 45, 45)
        pipeline.run()
        result = pipeline.result

        window = get_corresponding_window(
            get_project_path() / 'test/data/pipeline/left_edge.tif',
            get_project_path() / f'test/data/pipeline/{name}.tif')
        pixels = get_pixels(window)
        vertical_edge = pixels[pixels[:, 1] == window[1][0]]

        # check result is lesser equal 9 everywhere
        assert (result <= 9).all()
        # check that all counts on the vertical edge are greater 0 and less or equal 3
        assert (result[vertical_edge[:, 0], vertical_edge[:, 1]] > 0).all(
        ) and (result[vertical_edge[:, 0], vertical_edge[:, 1]] <= 3).all()
        # check that result is 0 everywhere else
        result[vertical_edge[:, 0], vertical_edge[:, 1]] = 0
        assert (result == 0).all()
示例#5
0
    def test_eye(self, name):
        pipeline = Pipeline(
            get_project_path() / 'test/data/pipeline/eye.tif',
            get_project_path() / f'test/data/pipeline/{name}.tif', 45, 45)
        pipeline.run()
        result = pipeline.result

        window = get_corresponding_window(
            get_project_path() / 'test/data/pipeline/eye.tif',
            get_project_path() / f'test/data/pipeline/{name}.tif')
        first_pixel = get_pixels(window)[0]
        diagonal = np.array([[
            first_pixel[0] + i, first_pixel[1] + i
        ] for i in range(
            min(window[0][1] - window[0][0], window[1][1] - window[1][0]))])
        # check result is lesser equal 9 everywhere
        assert (result <= 9).all()
        # check that all counts on the diagonal are greater 0 and less or equal 3
        assert (result[diagonal[:, 0], diagonal[:, 1]] > 0).all() and (
            result[diagonal[:, 0], diagonal[:, 1]] <= 3).all()
        # check that result is 0 everywhere else
        result[diagonal[:, 0], diagonal[:, 1]] = 0
        assert (result == 0).all()
示例#6
0
from utils.helpers import get_project_path
from pipeline import Pipeline

fb_raster_path = get_project_path(
) / 'data/humdata/population_nga_2018-10-01.tif'
grid_raster_path = get_project_path(
) / 'data/grid3/NGA - population - v1.2 - mastergrid.tif'

# prime factorization of fb_raster.height=34558: 2 * 37 * 467
# prime factorization of fb_raster.width=43172: 2 * 2 * 43 * 251
# choose window shape: (467,251)
window_height = 467
window_width = 251

pipeline = Pipeline(fb_raster_path,
                    grid_raster_path,
                    window_height,
                    window_width,
                    log=True)

pipeline.run()
pipeline.write_to_tif()
 def test_get_project_path(self):
     assert get_project_path() == Path(__file__).parent.parent.absolute()