示例#1
0
def test_rio_driver_open(data_folder):
    base = "file://" + str(data_folder) + "/metadata.yml"

    rdr = mk_rio_driver()
    assert rdr is not None

    load_ctx = rdr.new_load_context(iter([]), None)
    bi = mk_band('b1', base, path="test.tif", format=GeoTIFF)
    load_ctx = rdr.new_load_context(iter([bi]), load_ctx)
    fut = rdr.open(bi, load_ctx)
    assert isinstance(fut, Future)

    src = fut.result()
    assert src.crs is not None
    assert src.transform is not None
    assert src.crs.epsg == 4326
    assert src.shape == (2000, 4000)
    assert src.nodata == -999
    assert src.dtype == np.dtype(np.int16)

    xx = src.read().result()
    assert xx.shape == src.shape
    assert xx.dtype == src.dtype

    # check overrides
    bi = mk_band('b1',
                 base,
                 path="zeros_no_geo_int16_7x3.tif",
                 format=GeoTIFF,
                 nodata=None)

    # First verify that missing overrides in the band doesn't cause issues
    assert bi.crs is None
    assert bi.transform is None
    assert bi.nodata is None

    load_ctx = rdr.new_load_context(iter([bi]), load_ctx)
    with warnings.catch_warnings():
        warnings.simplefilter('ignore',
                              rasterio.errors.NotGeoreferencedWarning)
        src = rdr.open(bi, load_ctx).result()

    assert src.crs is None
    assert src.transform is None
    assert src.nodata is None

    # Now test that overrides work
    bi.crs = epsg3857
    bi.transform = Affine.translation(10, 100)
    bi.nodata = -33

    load_ctx = rdr.new_load_context(iter([bi]), load_ctx)
    with warnings.catch_warnings():
        warnings.simplefilter('ignore',
                              rasterio.errors.NotGeoreferencedWarning)
        src = rdr.open(bi, load_ctx).result()

    assert src.crs == bi.crs
    assert src.transform == bi.transform
    assert src.nodata == bi.nodata
def test_new_xr_load(data_folder):
    base = "file://" + str(data_folder) + "/metadata.yml"

    rdr = mk_rio_driver()
    assert rdr is not None

    _bands = []

    def band_info_collector(bands, ctx):
        for b in bands:
            _bands.append(b)

    tee_new_load_context(rdr, band_info_collector)

    band_a = dict(name='a', path='test.tif')

    band_b = dict(name='b', band=2, path='test.tif')

    ds = mk_sample_dataset([band_a, band_b], base)

    sources = Datacube.group_datasets([ds], 'time')

    im, meta = rio_slurp(str(data_folder) + '/test.tif')
    measurements = [ds.type.measurements[n] for n in ('a', 'b')]

    xx, _ = xr_load(sources, meta.gbox, measurements, rdr)

    assert len(_bands) == 2

    assert im[0].shape == xx.a.isel(time=0).shape
    assert im[1].shape == xx.b.isel(time=0).shape

    np.testing.assert_array_equal(im[0], xx.a.values[0])
    np.testing.assert_array_equal(im[1], xx.b.values[0])