Example #1
0
def test_hdf5_lock_release_on_failure():
    from datacube.storage._rio import RasterDatasetDataSource, _HDF5_LOCK
    from datacube.storage import BandInfo

    band = dict(name='xx', layer='xx', dtype='uint8', units='K', nodata=33)

    ds = mk_sample_dataset(
        [band],
        uri='file:///tmp/this_probably_doesnot_exist_37237827513/xx.nc',
        format=NetCDF)
    src = RasterDatasetDataSource(BandInfo(ds, 'xx'))

    with pytest.raises(OSError):
        with src.open():
            assert False and "Did not expect to get here"

    assert not _HDF5_LOCK._is_owned()
Example #2
0
def test_multiband_support_in_datasetsource(example_gdal_path):
    defn = {
        "id": '12345678123456781234567812345678',
        "format": {
            "name": "GeoTiff"
        },
        "image": {
            "bands": {
                'green': {
                    'type': 'reflective',
                    'cell_size': 25.0,
                    'path': example_gdal_path,
                    'label': 'Coastal Aerosol',
                    'number': '1',
                },
            }
        }
    }

    # Without new band attribute, default to band number 1
    d = Dataset(_EXAMPLE_DATASET_TYPE, defn, uris=['file:///tmp'])

    ds = RasterDatasetDataSource(BandInfo(d, 'green'))

    bandnum = ds.get_bandnumber(None)

    assert bandnum == 1

    with ds.open() as foo:
        data = foo.read()
        assert isinstance(data, np.ndarray)

    #############
    # With new 'image.bands.[band].band' attribute
    band_num = 3
    defn['image']['bands']['green']['band'] = band_num
    d = Dataset(_EXAMPLE_DATASET_TYPE, defn, uris=['file:///tmp'])

    ds = RasterDatasetDataSource(BandInfo(d, 'green'))

    assert ds.get_bandnumber(None) == band_num
Example #3
0
 def ds(uri):
     d = Dataset(_EXAMPLE_DATASET_TYPE, defn, uris=[uri])
     return RasterDatasetDataSource(BandInfo(d, 'green'))
Example #4
0
 def new_datasource(self, band):
     return RasterDatasetDataSource(band)