コード例 #1
0
ファイル: test_calculate.py プロジェクト: tianran10/pandarus
def test_rasterstats_mismatched_crs(monkeypatch):
    monkeypatch.setattr('pandarus.calculate.gen_zonal_stats', fake_zonal_stats)

    with tempfile.TemporaryDirectory() as dirpath:
        fp = os.path.join(dirpath, "test.json")
        with pytest.warns(UserWarning):
            raster_statistics(grid, 'name', dem, output=fp)
コード例 #2
0
ファイル: test_calculate.py プロジェクト: tianran10/pandarus
def test_rasterstats(monkeypatch):
    monkeypatch.setattr('pandarus.calculate.gen_zonal_stats', fake_zonal_stats)

    with tempfile.TemporaryDirectory() as dirpath:
        fp = os.path.join(dirpath, "test.json")
        result = raster_statistics(grid,
                                   'name',
                                   range_raster,
                                   output=fp,
                                   compress=False)
        assert result == fp

        result = json.load(open(fp))

    expected = [
        ['grid cell 0', 0],
        ['grid cell 1', 1],
        ['grid cell 2', 2],
        ['grid cell 3', 3],
    ]

    assert result['metadata'].keys() == {'vector', 'raster', 'when'}
    assert result['metadata']['vector'].keys() == {
        'field', 'filename', 'path', 'sha256'
    }
    assert result['metadata']['raster'].keys() == {
        'band', 'filename', 'path', 'sha256'
    }
    assert result['data'] == expected
コード例 #3
0
ファイル: test_calculate.py プロジェクト: tianran10/pandarus
def test_rasterstats_new_path(monkeypatch):
    monkeypatch.setattr('pandarus.calculate.gen_zonal_stats', fake_zonal_stats)

    fp = raster_statistics(grid, 'name', range_raster, compress=False)
    assert 'rasterstats' in fp
    assert '.json' in fp
    assert os.path.isfile(fp)
    os.remove(fp)
コード例 #4
0
ファイル: test_calculate.py プロジェクト: tianran10/pandarus
def test_rasterstats_overwrite_existing(monkeypatch):
    monkeypatch.setattr('pandarus.calculate.gen_zonal_stats', fake_zonal_stats)

    with tempfile.TemporaryDirectory() as dirpath:
        fp = os.path.join(dirpath, "test.json")

        with open(fp, "w") as f:
            f.write("Original content")

        result = raster_statistics(grid,
                                   'name',
                                   range_raster,
                                   output=fp,
                                   compress=False)

        assert result == fp

        content = open(result).read()
        assert content != 'Original content'
コード例 #5
0
ファイル: tasks.py プロジェクト: cmutel/pandarus_remote
def rasterstats_task(vector_id, raster_id, band, output_fp):
    vector = File.get(File.id == vector_id)
    raster = File.get(File.id == raster_id)

    # Job enqueued twice
    if RasterStats.select().where(
            (RasterStats.vector == vector) &
            (RasterStats.raster == raster)).count():
        return

    output = raster_statistics(vector.filepath, vector.field, raster.filepath, output=output_fp, band=band)

    # Job enqueued twice
    if RasterStats.select().where(
            (RasterStats.vector == vector) &
            (RasterStats.raster == raster)).count():
        return

    RasterStats(
        vector=vector,
        raster=raster,
        output=output
    ).save()
コード例 #6
0
ファイル: test_calculate.py プロジェクト: tianran10/pandarus
def test_rasterstats_invalid():
    with pytest.raises(AssertionError):
        raster_statistics(grid, 'name', square)