def alpha(ctx, src_path, dst_path, ndv, creation_options, workers): """Adds/replaced an alpha band to your RGB or RGBA image If you don't supply ndv, the alpha mask will be infered. """ with rio.open(src_path) as src: band_count = src.count if ndv: ndv = _parse_ndv(ndv, band_count) add_alpha(src_path, dst_path, ndv, creation_options, workers)
def islossy(input, ndv): """ Determine if there are >= 10 nodata regions in an image If true, returns the string `--lossy lossy`. """ with rio.open(input, "r") as src: img = src.read() ndv = _parse_ndv(ndv, 3) if count_ndv_regions(img, ndv) >= 10: click.echo("True") else: click.echo("False")
def test_parse_ndv_fail_bands(ndv): with pytest.raises(ValueError) as excinfo: _parse_ndv(str(ndv), 3) assert "does not match band count of" in str(excinfo.value)
def test_parse_ndv(ndv): ndvals = _parse_ndv(str(ndv), len(ndv)) assert [float(n) for n in ndv] == ndvals assert isinstance(ndvals[0], float)