def __attrs_post_init__(self): """Define _kwargs, open dataset and get info.""" if self.nodata is not None: self._kwargs["nodata"] = self.nodata if self.unscale is not None: self._kwargs["unscale"] = self.unscale if self.resampling_method is not None: self._kwargs["resampling_method"] = self.resampling_method if self.vrt_options is not None: self._kwargs["vrt_options"] = self.vrt_options if self.post_process is not None: self._kwargs["post_process"] = self.post_process self.src_dataset = rasterio.open(self.filepath) self.dataset = WarpedVRT( self.src_dataset, src_crs=self.src_dataset.gcps[1], src_transform=transform.from_gcps(self.src_dataset.gcps[0]), ) self.nodata = self.nodata if self.nodata is not None else self.dataset.nodata self.bounds = transform_bounds( self.dataset.crs, constants.WGS84_CRS, *self.dataset.bounds, densify_pts=21 ) if self.minzoom is None or self.maxzoom is None: self._set_zooms() if self.colormap is None: self._get_colormap() return self
def __attrs_post_init__(self): """Define _kwargs, open dataset and get info.""" self.src_dataset = self.src_dataset or rasterio.open(self.filepath) self.dataset = WarpedVRT( self.src_dataset, src_crs=self.src_dataset.gcps[1], src_transform=transform.from_gcps(self.src_dataset.gcps[0]), ) super().__attrs_post_init__()
def _s1_metadata(src_path, percentiles, **kwarg): with rasterio.open(src_path) as src_dst: with WarpedVRT( src_dst, src_crs=src_dst.gcps[1], src_transform=transform.from_gcps(src_dst.gcps[0]), src_nodata=0, ) as vrt_dst: return utils.raster_get_stats(vrt_dst, percentiles=percentiles, **kwarg)
def __attrs_post_init__(self): """Define _kwargs, open dataset and get info.""" self.src_dataset = self.src_dataset or self._ctx_stack.enter_context( rasterio.open(self.input)) self.dataset = self._ctx_stack.enter_context( WarpedVRT( self.src_dataset, src_crs=self.src_dataset.gcps[1], src_transform=transform.from_gcps(self.src_dataset.gcps[0]), )) super().__attrs_post_init__()
def worker(band: str): asset = "{}/{}-{}.tiff".format(sentinel_prefix, scene_params["beam"].lower(), band) with rasterio.open(asset) as src_dst: with WarpedVRT( src_dst, src_crs=src_dst.gcps[1], src_transform=transform.from_gcps(src_dst.gcps[0]), src_nodata=0, ) as vrt_dst: return reader.tile(vrt_dst, tile_x, tile_y, tile_z, tilesize=tilesize, **kwargs)
def worker(band: str): asset = "{}/{}-{}.tiff".format(sentinel_prefix, scene_params["beam"].lower(), band) with rasterio.open(asset) as src_dst: with WarpedVRT( src_dst, src_crs=src_dst.gcps[1], src_transform=transform.from_gcps(src_dst.gcps[0]), src_nodata=0, ) as vrt_dst: return reader.metadata( vrt_dst, percentiles=(pmin, pmax), hist_options=hist_options, **kwargs, )
def _s1_tiler(src_path): with rasterio.open(src_path) as src_dst: with WarpedVRT( src_dst, src_crs=src_dst.gcps[1], src_transform=transform.from_gcps(src_dst.gcps[0]), src_nodata=0, ) as vrt_dst: if not utils.tile_exists(vrt_dst.bounds, tile_z, tile_x, tile_y): raise TileOutsideBounds( "Tile {}/{}/{} is outside image bounds".format( tile_z, tile_x, tile_y)) return utils._tile_read(vrt_dst, bounds=tile_bounds, tilesize=tilesize)
def test_from_gcps(): with rasterio.open("tests/data/white-gemini-iv.vrt", 'r') as src: aff = transform.from_gcps(src.gcps[0]) assert not aff == src.transform assert len(aff) == 9 assert not transform.tastes_like_gdal(aff)
def info(ctx, input, aspect, indent, namespace, meta_member, verbose, bidx, masked): """Print metadata about the dataset as JSON. Optionally print a single metadata item as a string. """ with ctx.obj['env'], rasterio.open(input) as src: info = dict(src.profile) info['shape'] = (info['height'], info['width']) info['bounds'] = src.bounds if src.crs: epsg = src.crs.to_epsg() if epsg: info['crs'] = 'EPSG:{}'.format(epsg) else: info['crs'] = src.crs.to_string() else: info['crs'] = None info['res'] = src.res info['colorinterp'] = [ci.name for ci in src.colorinterp] info['units'] = [units or None for units in src.units] info['descriptions'] = src.descriptions info['indexes'] = src.indexes info['mask_flags'] = [[flag.name for flag in flags] for flags in src.mask_flag_enums] if src.crs: info['lnglat'] = src.lnglat() gcps, gcps_crs = src.gcps if gcps: info['gcps'] = {'points': [p.asdict() for p in gcps]} if gcps_crs: epsg = gcps_crs.to_epsg() if epsg: info['gcps']['crs'] = 'EPSG:{}'.format(epsg) else: info['gcps']['crs'] = src.crs.to_string() else: info['gcps']['crs'] = None info['gcps']['transform'] = from_gcps(gcps) if verbose: stats = [asdict(src.statistics(bidx)) for bidx in src.indexes] info['stats'] = stats info['checksum'] = [src.checksum(i) for i in src.indexes] if aspect == 'meta': if meta_member == 'subdatasets': for name in src.subdatasets: click.echo(name) elif meta_member == 'stats': st = src.statistics(bidx) click.echo( "{st.min} {st.max} {st.mean} {st.std}".format(st=st)) elif meta_member == 'checksum': click.echo(str(src.checksum(bidx))) elif meta_member: if isinstance(info[meta_member], (list, tuple)): click.echo(" ".join(map(str, info[meta_member]))) else: click.echo(info[meta_member]) else: click.echo(json.dumps(info, sort_keys=True, indent=indent)) elif aspect == 'tags': click.echo(json.dumps(src.tags(ns=namespace), indent=indent))