def __init__(self, ds: Dataset, band: str, uri_scheme: Optional[str] = None): try: mp, = ds.type.lookup_measurements([band]).values() except KeyError: raise ValueError('No such band: {}'.format(band)) mm = ds.measurements.get(mp.canonical_name) if mm is None: raise ValueError('No such band: {}'.format(band)) if ds.uris is None: raise ValueError('No uris defined on a dataset') base_uri = pick_uri(ds.uris, uri_scheme) bint, layer = _get_band_and_layer(mm) self.name = band self.uri = uri_resolve(base_uri, mm.get('path')) self.band = bint self.layer = layer self.dtype = mp.dtype self.nodata = mp.nodata self.units = mp.units self.crs = ds.crs self.transform = ds.transform self.format = ds.format or '' self.driver_data = _extract_driver_data(ds)
def __init__(self, ds: Dataset, band: str, uri_scheme: Optional[str] = None): mm = ds.measurements.get(band) mp = ds.type.measurements.get(band) if mm is None or mp is None: raise ValueError('No such band: {}'.format(band)) if ds.uris is None: raise ValueError('No uris defined on a dataset') base_uri = pick_uri(ds.uris, uri_scheme) bint, layer = _get_band_and_layer(mm) self.name = band self.uri = uri_resolve(base_uri, mm.get('path')) self.band = bint self.layer = layer self.dtype = mp.dtype self.nodata = mp.nodata self.units = mp.units self.crs = ds.crs self.transform = ds.transform self.center_time = ds.center_time self.format = ds.format self.driver_data = _extract_driver_data(ds)
def measurement_paths(ds: Dataset) -> Dict[str, str]: """ Returns a dictionary mapping from band name to url pointing to band storage resource. :return: Band Name => URL """ if ds.uris is None: raise ValueError('No locations on this dataset') base = pick_uri(ds.uris) return dict((k, uri_resolve(base, m.get('path'))) for k, m in ds.measurements.items())
def test_pick_uri(): f, s, h = ('file://a', 's3://b', 'http://c') assert pick_uri([f, s, h]) is f assert pick_uri([s, h, f]) is f assert pick_uri([s, h]) is s assert pick_uri([h, s]) is h assert pick_uri([f, s, h], 'http:') is h assert pick_uri([f, s, h], 's3:') is s assert pick_uri([f, s, h], 'file:') is f with pytest.raises(ValueError): pick_uri([]) with pytest.raises(ValueError): pick_uri([f, s, h], 'ftp:') with pytest.raises(ValueError): pick_uri([s, h], 'file:')