def test_atmos(): i = 77 args = {"atmo": 0.03, "contrast": 15, "bias": 0.5, "out_dtype": "uint8"} with rasterio.open("tests/rgb8.tif") as src: ij, window = list(src.block_windows())[i] arr = atmos_worker([src], window, ij, args) assert arr.dtype == args["out_dtype"] assert arr.shape == (3, 32, 32) assert arr.max() <= 255 max_uint8 = arr.max() with rasterio.open("tests/rgba8.tif") as src: ij, window = list(src.block_windows())[i] arr2 = atmos_worker([src], window, ij, args) # operates on rgb assert np.allclose(arr, arr2[0:3]) # retains alpha band assert np.allclose(src.read(4, window=window), arr2[3]) with rasterio.open("tests/rgb16.tif") as src: ij, window = list(src.block_windows())[i] arr = atmos_worker([src], window, ij, args) assert arr.dtype == args["out_dtype"] assert arr.shape == (3, 32, 32) assert arr.max() <= 255 with rasterio.open("tests/rgb8.tif") as src: ij, window = list(src.block_windows())[i] args["out_dtype"] = "uint16" arr = atmos_worker([src], window, ij, args) assert arr.dtype == args["out_dtype"] assert arr.shape == (3, 32, 32) assert arr.max() > max_uint8
def atmos( ctx, atmo, contrast, bias, jobs, out_dtype, src_path, dst_path, creation_options, as_color, ): """Atmospheric correction """ if as_color: click.echo("rio color {} {} {}".format( src_path, dst_path, simple_atmo_opstring(atmo, contrast, bias))) exit(0) with rasterio.open(src_path) as src: opts = src.profile.copy() windows = [(window, ij) for ij, window in src.block_windows()] opts.update(**creation_options) opts["transform"] = guard_transform(opts["transform"]) out_dtype = out_dtype if out_dtype else opts["dtype"] opts["dtype"] = out_dtype args = { "atmo": atmo, "contrast": contrast, "bias": bias, "out_dtype": out_dtype } jobs = check_jobs(jobs) if jobs > 1: with riomucho.RioMucho( [src_path], dst_path, atmos_worker, windows=windows, options=opts, global_args=args, mode="manual_read", ) as mucho: mucho.run(jobs) else: with rasterio.open(dst_path, "w", **opts) as dest: with rasterio.open(src_path) as src: rasters = [src] for window, ij in windows: arr = atmos_worker(rasters, window, ij, args) dest.write(arr, window=window)
def test_atmos(): i = 77 args = { 'atmo': 0.03, 'contrast': 15, 'bias': 0.5, 'out_dtype': 'uint8'} with rasterio.open('tests/rgb8.tif') as src: ij, window = list(src.block_windows())[i] arr = atmos_worker([src], window, ij, args) assert arr.dtype == args['out_dtype'] assert arr.shape == (3, 32, 32) assert arr.max() <= 255 max_uint8 = arr.max() with rasterio.open('tests/rgba8.tif') as src: ij, window = list(src.block_windows())[i] arr2 = atmos_worker([src], window, ij, args) # operates on rgb assert np.allclose(arr, arr2[0:3]) # retains alpha band assert np.allclose(src.read(4, window=window), arr2[3]) with rasterio.open('tests/rgb16.tif') as src: ij, window = list(src.block_windows())[i] arr = atmos_worker([src], window, ij, args) assert arr.dtype == args['out_dtype'] assert arr.shape == (3, 32, 32) assert arr.max() <= 255 with rasterio.open('tests/rgb8.tif') as src: ij, window = list(src.block_windows())[i] args['out_dtype'] = 'uint16' arr = atmos_worker([src], window, ij, args) assert arr.dtype == args['out_dtype'] assert arr.shape == (3, 32, 32) assert arr.max() > max_uint8
def atmos(ctx, atmo, contrast, bias, jobs, out_dtype, src_path, dst_path, creation_options, as_color): """Atmospheric correction """ if as_color: click.echo("rio color {} {} {}".format( src_path, dst_path, simple_atmo_opstring(atmo, contrast, bias))) exit(0) with rasterio.open(src_path) as src: opts = src.profile.copy() windows = [(window, ij) for ij, window in src.block_windows()] opts.update(**creation_options) opts['transform'] = guard_transform(opts['transform']) out_dtype = out_dtype if out_dtype else opts['dtype'] opts['dtype'] = out_dtype args = { 'atmo': atmo, 'contrast': contrast, 'bias': bias, 'out_dtype': out_dtype } jobs = check_jobs(jobs) if jobs > 1: with riomucho.RioMucho( [src_path], dst_path, atmos_worker, windows=windows, options=opts, global_args=args, mode="manual_read" ) as mucho: mucho.run(jobs) else: with rasterio.open(dst_path, 'w', **opts) as dest: with rasterio.open(src_path) as src: rasters = [src] for window, ij in windows: arr = atmos_worker(rasters, window, ij, args) dest.write(arr, window=window)