From bddc8a2d072ded96bb3fa9027b9ebf7afa0be655 Mon Sep 17 00:00:00 2001 From: dnomadb Date: Tue, 5 Jun 2018 16:15:21 -0700 Subject: [PATCH 01/16] trying out pre commit hook --- .pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0c39c64 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: +- repo: https://github.com/ambv/black + rev: stable + hooks: + - id: black + args: [--safe] + language_version: python3.6 \ No newline at end of file From cb36a2231c36d67368dfda0e249a2ee87d54dc3b Mon Sep 17 00:00:00 2001 From: dnomadb Date: Tue, 5 Jun 2018 16:17:57 -0700 Subject: [PATCH 02/16] adding to requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 9cb3015..f2c317e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ rasterio raster-tester scikit-image scipy +pre-commit From 17735ce6b571d89265a00f8f086a9f4a2dc9a25a Mon Sep 17 00:00:00 2001 From: dnomadb Date: Tue, 5 Jun 2018 16:20:32 -0700 Subject: [PATCH 03/16] include changes --- nodata/alphamask.py | 19 +++- nodata/blob.py | 106 +++++++++++--------- nodata/scripts/alpha.py | 20 ++-- nodata/scripts/cli.py | 93 +++++++++++++----- setup.py | 55 +++++------ tests/make_testing_data.py | 70 +++++++------ tests/test_alpha_func.py | 39 ++++++-- tests/test_blob_cli.py | 191 ++++++++++++++++++++++++------------ tests/test_blob_func.py | 26 +++-- tests/test_scripts_alpha.py | 32 +++--- 10 files changed, 416 insertions(+), 235 deletions(-) diff --git a/nodata/alphamask.py b/nodata/alphamask.py index ee53529..b06f4fe 100644 --- a/nodata/alphamask.py +++ b/nodata/alphamask.py @@ -19,7 +19,9 @@ def value_grab(a, b): out[b] = measures[a[0] - 1][m_key] return None - sci_meas.labeled_comprehension(labeled_img, labeled_img, u_labels, value_grab, float, 0, pass_positions=True) + sci_meas.labeled_comprehension( + labeled_img, labeled_img, u_labels, value_grab, float, 0, pass_positions=True + ) return out.reshape(labeled_img.shape) @@ -49,7 +51,7 @@ def all_valid_edges(data, ndv, threshold=0): def simple_mask(data, ndv): - '''Exact nodata masking''' + """Exact nodata masking""" depth, rows, cols = data.shape nd = np.iinfo(data.dtype).max alpha = np.invert(np.all(np.dstack(data) == ndv, axis=2)).astype(data.dtype) * nd @@ -69,12 +71,19 @@ def slic_mask(arr, nodata, n_clusters=50, threshold=5, debug=False): clusters = slic(near_nodata, n_clusters) labeled = measure.label(clusters) + 1 measures = measure.regionprops(labeled, intensity_image=near_nodata, cache=True) - mean_intensity = _hacky_make_image(labeled, np.unique(labeled), measures, 'mean_intensity') + mean_intensity = _hacky_make_image( + labeled, np.unique(labeled), measures, "mean_intensity" + ) mask = binary_fill_holes(np.invert(binary_fill_holes(mean_intensity >= threshold))) nd = np.iinfo(arr.dtype).max mask = np.invert(mask) * nd if debug: d = dict([(m.label, m.mean_intensity) for m in measures]) - return mask.astype('uint8'), labeled.astype('uint32'), mean_intensity.astype('uint32'), d + return ( + mask.astype("uint8"), + labeled.astype("uint32"), + mean_intensity.astype("uint32"), + d, + ) else: - return mask.astype('uint8') + return mask.astype("uint8") diff --git a/nodata/blob.py b/nodata/blob.py index 5038c4f..b8762f7 100644 --- a/nodata/blob.py +++ b/nodata/blob.py @@ -17,16 +17,13 @@ def pad_window(wnd, pad): # rasterio < 1.0, already a tuple pass - return ( - (wnd[0][0] - pad, wnd[0][1] + pad), - (wnd[1][0] - pad, wnd[1][1] + pad) - ) + return ((wnd[0][0] - pad, wnd[0][1] + pad), (wnd[1][0] - pad, wnd[1][1] + pad)) def test_rgb(count, nodata, alphafy, outCount): if count == 3 and alphafy: if not isinstance(nodata, Number): - raise ValueError('3 band imagery must have a defined nodata value') + raise ValueError("3 band imagery must have a defined nodata value") return None, nodata, outCount elif alphafy: @@ -56,12 +53,12 @@ def handle_RGB(img, mask): def blob_worker(srcs, window, ij, globalArgs): - pad = globalArgs['max_search_distance'] + 1 + pad = globalArgs["max_search_distance"] + 1 padded = pad_window(window, pad) padWindow = Window.from_slices(*padded, boundless=True) img = srcs[0].read(boundless=True, window=padWindow) - if isinstance(globalArgs['selectNodata'], Number): + if isinstance(globalArgs["selectNodata"], Number): mask = srcs[0].read_masks(boundless=True, window=padWindow)[0] img = handle_RGB(img, mask) alphamask = False @@ -69,47 +66,50 @@ def blob_worker(srcs, window, ij, globalArgs): mask = img[-1] alphamask = True - if globalArgs['maskThreshold'] is not None and alphamask: - img[-1] = (np.invert(img[-1] < globalArgs['maskThreshold']).astype(img.dtype) - * np.iinfo(img.dtype).max) + if globalArgs["maskThreshold"] is not None and alphamask: + img[-1] = ( + np.invert(img[-1] < globalArgs["maskThreshold"]).astype(img.dtype) + * np.iinfo(img.dtype).max + ) mask = img[-1] if runNodataFiller(mask, pad): img = fill_nodata( - img, mask, globalArgs['bands'], - globalArgs['max_search_distance'])[:, pad: -pad, pad: -pad] + img, mask, globalArgs["bands"], globalArgs["max_search_distance"] + )[:, pad:-pad, pad:-pad] - if globalArgs['nibblemask'] \ - and alphamask is False \ - and 'nodata' in srcs[0].meta: + if globalArgs["nibblemask"] and alphamask is False and "nodata" in srcs[0].meta: img = nibble_filled_mask( - img, - srcs[0].meta['nodata'], - globalArgs['max_search_distance']) + img, srcs[0].meta["nodata"], globalArgs["max_search_distance"] + ) - elif globalArgs['nibblemask'] and alphamask: + elif globalArgs["nibblemask"] and alphamask: img[-1] = nibble_filled_mask( - img[-1], - None, - globalArgs['max_search_distance'], - True) + img[-1], None, globalArgs["max_search_distance"], True + ) else: - img = img[:, pad: -pad, pad: -pad] + img = img[:, pad:-pad, pad:-pad] return img def blob_nodata( - src_path, dst_path, bidx, max_search_distance, nibblemask, - creation_options, maskThreshold, workers, alphafy): + src_path, + dst_path, + bidx, + max_search_distance, + nibblemask, + creation_options, + maskThreshold, + workers, + alphafy, +): """ """ with rio.open(src_path) as src: - windows = [ - [window, ij] for ij, window in src.block_windows() - ] + windows = [[window, ij] for ij, window in src.block_windows()] options = src.meta.copy() kwds = src.profile.copy() @@ -128,8 +128,9 @@ def blob_nodata( if bidx and (len(bidx) == 0 or len(bidx) > src.count): raise ValueError( - "Bands %s differ from source count of %s" % - (', '.join([str(b) for b in bidx]), src.count)) + "Bands %s differ from source count of %s" + % (", ".join([str(b) for b in bidx]), src.count) + ) elif alphafy and src.count == 3: bidx = list(src.indexes) bidx.append(src.indexes[-1] + 1) @@ -137,20 +138,23 @@ def blob_nodata( bidx = list(src.indexes) if maskThreshold is not None: - maskThreshold = np.iinfo(options['dtype']).max - maskThreshold + maskThreshold = np.iinfo(options["dtype"]).max - maskThreshold with riomucho.RioMucho( - [src_path], dst_path, blob_worker, - windows=windows, - global_args={ - 'max_search_distance': max_search_distance, - 'nibblemask': nibblemask, - 'bands': bidx, - 'maskThreshold': maskThreshold, - 'selectNodata': selectNodata - }, - options=options, - mode='manual_read') as rm: + [src_path], + dst_path, + blob_worker, + windows=windows, + global_args={ + "max_search_distance": max_search_distance, + "nibblemask": nibblemask, + "bands": bidx, + "maskThreshold": maskThreshold, + "selectNodata": selectNodata, + }, + options=options, + mode="manual_read", + ) as rm: rm.run(workers) @@ -160,7 +164,11 @@ def nibble_filled_mask(filled, nodataval, max_search_distance, is_mask=False): if is_mask: filled = minimum_filter(filled, size=(max_search_distance * 2 + 1)) else: - nmsk = (filled[0] == nodataval) & (filled[1] == nodataval) & (filled[2] == nodataval) + nmsk = ( + (filled[0] == nodataval) + & (filled[1] == nodataval) + & (filled[2] == nodataval) + ) nmsk = maximum_filter(nmsk, size=(max_search_distance * 2 + 1)) mskInds = np.where(nmsk == True) filled[:, mskInds[0], mskInds[1]] = nodataval @@ -169,18 +177,18 @@ def nibble_filled_mask(filled, nodataval, max_search_distance, is_mask=False): def make_nibbled(src_path, dst_path, nibble): - with rio.open(src_path, 'r') as src: + with rio.open(src_path, "r") as src: img = src.read(masked=False) kwargs = src.meta - if 'nodata' in src.meta: - nodataval = src.meta['nodata'] + if "nodata" in src.meta: + nodataval = src.meta["nodata"] else: nodataval = 0.0 - kwargs.update(compress='lzw') + kwargs.update(compress="lzw") nibbled = nibble_filled_mask(img, nodataval, nibble) - with rio.open(dst_path, 'w', **kwargs) as dst: + with rio.open(dst_path, "w", **kwargs) as dst: for i, arr in enumerate(nibbled, 1): dst.write(arr, i) diff --git a/nodata/scripts/alpha.py b/nodata/scripts/alpha.py index 3abb134..ed38bc5 100644 --- a/nodata/scripts/alpha.py +++ b/nodata/scripts/alpha.py @@ -2,6 +2,7 @@ from multiprocessing import cpu_count, Pool import sys import zlib + try: from itertools import izip except ImportError: @@ -35,6 +36,7 @@ def finalize_worker(): # The following function is executed by worker processes. + def compute_window_mask(args): """Execute the given function with keyword arguments to compute a valid data mask. @@ -44,7 +46,7 @@ def compute_window_mask(args): window, nodata, extra_args = args global mask_function, src_dataset - padding = int(extra_args.get('padding', 0)) + padding = int(extra_args.get("padding", 0)) if padding: start, stop = zip(*window) @@ -76,8 +78,7 @@ class NodataPoolMan: windows of a dataset. """ - def __init__(self, input_path, func, nodata, num_workers=None, - max_tasks=100): + def __init__(self, input_path, func, nodata, num_workers=None, max_tasks=100): """Create a pool of workers to process window masks""" self.input_path = input_path self.func = func @@ -89,8 +90,8 @@ def __init__(self, input_path, func, nodata, num_workers=None, self.dtype = src.dtypes[0] self.pool = Pool( - num_workers or cpu_count()-1, init_worker, (input_path, func), - max_tasks) + num_workers or cpu_count() - 1, init_worker, (input_path, func), max_tasks + ) def mask(self, windows, **kwargs): """Iterate over windows and compute mask arrays. @@ -101,11 +102,10 @@ def mask(self, windows, **kwargs): Yields window, ndarray pairs. """ iterargs = izip(windows, repeat(self.nodata), repeat(kwargs)) - for out_window, data in self.pool.imap_unordered( - compute_window_mask, iterargs): + for out_window, data in self.pool.imap_unordered(compute_window_mask, iterargs): - out_data = numpy.fromstring( - zlib.decompress(data), self.dtype).reshape( - [int(x) for x in rasterio.windows.shape(out_window)]) + out_data = numpy.fromstring(zlib.decompress(data), self.dtype).reshape( + [int(x) for x in rasterio.windows.shape(out_window)] + ) yield out_window, out_data diff --git a/nodata/scripts/cli.py b/nodata/scripts/cli.py index 440a908..f479da7 100644 --- a/nodata/scripts/cli.py +++ b/nodata/scripts/cli.py @@ -14,32 +14,81 @@ def cli(): @click.command( short_help="Blob + expand valid data area by (inter|extra)polation into" - "nodata areas") -@click.argument('src_path', type=click.Path(exists=True)) -@click.argument('dst_path', type=click.Path(exists=False)) -@click.option('--bidx', '-b', default=None, - help="Bands to blob [default = all]") -@click.option('--max-search-distance', '-m', default=4, - help="Maximum blobbing radius [default = 4]") -@click.option('--nibblemask', '-n', default=False, is_flag=True, - help="Nibble blobbed nodata areas [default=False]") + "nodata areas" +) +@click.argument("src_path", type=click.Path(exists=True)) +@click.argument("dst_path", type=click.Path(exists=False)) +@click.option("--bidx", "-b", default=None, help="Bands to blob [default = all]") +@click.option( + "--max-search-distance", + "-m", + default=4, + help="Maximum blobbing radius [default = 4]", +) +@click.option( + "--nibblemask", + "-n", + default=False, + is_flag=True, + help="Nibble blobbed nodata areas [default=False]", +) @creation_options -@click.option('--mask-threshold', '-d', default=None, type=int, +@click.option( + "--mask-threshold", + "-d", + default=None, + type=int, help="Alpha pixel threshold upon which to regard data as masked " - "(ie, for lossy you'd want an aggressive threshold of 0) " - "[default=None]") -@click.option('--jobs', '-j', default=4, type=int, - help="Number of workers for multiprocessing [default=4]") -@click.option('--alphafy', '-a', is_flag=True, - help='If a RGB raster is found, blob + add alpha band where nodata is') -def blob(src_path, dst_path, bidx, max_search_distance, nibblemask, - creation_options, mask_threshold, jobs, alphafy): + "(ie, for lossy you'd want an aggressive threshold of 0) " + "[default=None]", +) +@click.option( + "--jobs", + "-j", + default=4, + type=int, + help="Number of workers for multiprocessing [default=4]", +) +@click.option( + "--alphafy", + "-a", + is_flag=True, + help="If a RGB raster is found, blob + add alpha band where nodata is", +) +def blob( + src_path, + dst_path, + bidx, + max_search_distance, + nibblemask, + creation_options, + mask_threshold, + jobs, + alphafy, +): """""" - args = (src_path, dst_path, bidx, max_search_distance, nibblemask, - creation_options, mask_threshold, jobs, alphafy) + args = ( + src_path, + dst_path, + bidx, + max_search_distance, + nibblemask, + creation_options, + mask_threshold, + jobs, + alphafy, + ) blob_nodata( - src_path, dst_path, bidx, max_search_distance, nibblemask, - creation_options, mask_threshold, jobs, alphafy) + src_path, + dst_path, + bidx, + max_search_distance, + nibblemask, + creation_options, + mask_threshold, + jobs, + alphafy, + ) cli.add_command(blob) diff --git a/setup.py b/setup.py index 9ff59f9..8ec43e6 100644 --- a/setup.py +++ b/setup.py @@ -3,36 +3,35 @@ # Get the long description from the relevant file -with codecs_open('README.rst', encoding='utf-8') as f: +with codecs_open("README.rst", encoding="utf-8") as f: long_description = f.read() -setup(name='nodata', - version='0.5.0', - description=u"Utilities for handling nodata", - long_description=long_description, - classifiers=[], - keywords='', - author=u"Damon Burgett", - author_email='damon@mapbox.com', - url='https://github.com/mapbox/nodata', - license='MIT', - packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), - include_package_data=True, - zip_safe=False, - install_requires=[ - 'click', - 'raster-tester', - 'rasterio>=1.0a12', - 'rio-mucho', - 'scikit-image', - 'scipy' - ], - extras_require={ - 'test': ['pytest', 'pytest-cov'], - }, - entry_points=""" +setup( + name="nodata", + version="0.5.0", + description=u"Utilities for handling nodata", + long_description=long_description, + classifiers=[], + keywords="", + author=u"Damon Burgett", + author_email="damon@mapbox.com", + url="https://github.com/mapbox/nodata", + license="MIT", + packages=find_packages(exclude=["ez_setup", "examples", "tests"]), + include_package_data=True, + zip_safe=False, + install_requires=[ + "click", + "raster-tester", + "rasterio>=1.0a12", + "rio-mucho", + "scikit-image", + "scipy", + ], + extras_require={"test": ["pytest", "pytest-cov"]}, + entry_points=""" [console_scripts] nodata=nodata.scripts.cli:cli - """ - ) + """, +) diff --git a/tests/make_testing_data.py b/tests/make_testing_data.py index c709f8e..2a197b9 100644 --- a/tests/make_testing_data.py +++ b/tests/make_testing_data.py @@ -6,61 +6,75 @@ def makehappytiff(dst_path, seams_path): kwargs = { - 'blockxsize': 256, - 'blockysize': 256, - 'compress': 'lzw', - 'count': 4, - 'crs': {'init': u'epsg:3857'}, - 'driver': u'GTiff', - 'dtype': 'uint8', - 'height': 1065, - 'nodata': None, - 'tiled': True, - 'transform': Affine(4.595839562240513, 0.0, -13550756.3744, 0.0, -4.595839562240513, 6315533.02503), - 'width': 1065} + "blockxsize": 256, + "blockysize": 256, + "compress": "lzw", + "count": 4, + "crs": {"init": u"epsg:3857"}, + "driver": u"GTiff", + "dtype": "uint8", + "height": 1065, + "nodata": None, + "tiled": True, + "transform": Affine( + 4.595839562240513, + 0.0, + -13550756.3744, + 0.0, + -4.595839562240513, + 6315533.02503, + ), + "width": 1065, + } imsize = 1065 - testdata = [(np.random.rand(imsize,imsize)*255).astype(np.uint8) for i in range(4)] - + testdata = [ + (np.random.rand(imsize, imsize) * 255).astype(np.uint8) for i in range(4) + ] + for i in range(4): - testdata[i][0:100,:] = 0 - testdata[i][:,900:] = 0 + testdata[i][0:100, :] = 0 + testdata[i][:, 900:] = 0 - with rio.open(dst_path, 'w', **kwargs) as dst: + with rio.open(dst_path, "w", **kwargs) as dst: for i, arr in enumerate(testdata, 1): dst.write(arr, i) if seams_path: frto = np.sort(np.random.rand(2) * imsize).astype(int) - rInds = np.arange(frto[0], frto[1], (frto[1] - frto[0]) / float(imsize)).astype(int) + rInds = np.arange(frto[0], frto[1], (frto[1] - frto[0]) / float(imsize)).astype( + int + ) inds = np.arange(imsize) for i in range(4): testdata[i][rInds, inds] = 0 - testdata[i][rInds-1, inds] = 0 - testdata[i][rInds+1, inds] = 0 + testdata[i][rInds - 1, inds] = 0 + testdata[i][rInds + 1, inds] = 0 testdata[i][inds, rInds] = 0 - testdata[i][inds, rInds-1] = 0 - testdata[i][inds, rInds+1] = 0 - with rio.open(seams_path, 'w', **kwargs) as dst: + testdata[i][inds, rInds - 1] = 0 + testdata[i][inds, rInds + 1] = 0 + with rio.open(seams_path, "w", **kwargs) as dst: for i, arr in enumerate(testdata, 1): dst.write(arr, i) def getnulldiff(in1, in2, threshold): - with rio.open(in1, 'r') as src: + with rio.open(in1, "r") as src: msk1 = src.read_masks() - with rio.open(in2, 'r') as src: + with rio.open(in2, "r") as src: msk2 = src.read_masks() allmsk1 = ((msk1[0] == 0) & (msk1[1] == 0) & (msk1[1] == 0)).astype(int) allmsk2 = ((msk2[0] == 0) & (msk2[1] == 0) & (msk2[1] == 0)).astype(int) diff = np.count_nonzero(allmsk1) - np.count_nonzero(allmsk2) - - assert diff >= threshold, "input 1 has more than %d nodata pixels than input 2" % (threshold) + + assert diff >= threshold, "input 1 has more than %d nodata pixels than input 2" % ( + threshold + ) -if __name__ == '__main__': +if __name__ == "__main__": makehappytiff() diff --git a/tests/test_alpha_func.py b/tests/test_alpha_func.py index 671d3ff..e39ac63 100644 --- a/tests/test_alpha_func.py +++ b/tests/test_alpha_func.py @@ -13,21 +13,42 @@ def image_reader(path): @pytest.mark.parametrize( - 'path, expected, args', + "path, expected, args", ( - ('tests/fixtures/alpha_unit/window-1.tif', 'tests/expected/alpha_simple/window-1.tif', (0, 0, 0)), - ('tests/fixtures/alpha_unit/window-2.tif', 'tests/expected/alpha_simple/window-2.tif', (0, 0, 0)), - ('tests/fixtures/alpha_unit/window-3.tif', 'tests/expected/alpha_simple/window-3.tif', (255, 255, 255)), - ('tests/fixtures/alpha_unit/window-4.tif', 'tests/expected/alpha_simple/window-4.tif', (0, 0, 0)), - ('tests/fixtures/alpha_unit/window-5.tif', 'tests/expected/alpha_simple/window-5.tif', (255, 255, 255)) - ) + ( + "tests/fixtures/alpha_unit/window-1.tif", + "tests/expected/alpha_simple/window-1.tif", + (0, 0, 0), + ), + ( + "tests/fixtures/alpha_unit/window-2.tif", + "tests/expected/alpha_simple/window-2.tif", + (0, 0, 0), + ), + ( + "tests/fixtures/alpha_unit/window-3.tif", + "tests/expected/alpha_simple/window-3.tif", + (255, 255, 255), + ), + ( + "tests/fixtures/alpha_unit/window-4.tif", + "tests/expected/alpha_simple/window-4.tif", + (0, 0, 0), + ), + ( + "tests/fixtures/alpha_unit/window-5.tif", + "tests/expected/alpha_simple/window-5.tif", + (255, 255, 255), + ), + ), ) def test_runner(path, expected, args): img = image_reader(path) depth, rows, cols = img.shape pad = 64 outputImg = np.concatenate( - [img, alphamask.simple_mask(img, args).reshape((1, rows, cols))])[:, pad: -pad, pad: -pad] + [img, alphamask.simple_mask(img, args).reshape((1, rows, cols))] + )[:, pad:-pad, pad:-pad] expectedImg = image_reader(expected) @@ -70,6 +91,7 @@ def test_alphamask_good_alphaonly(): assert len(createColIdx) == 1 assert rColIdx == createColIdx[0] + def test_all_valid(): all_valid = alphamask.all_valid ndv = (255, 255, 255) @@ -115,6 +137,7 @@ def test_slic_mask_not_any(): def test_slic_mask_any(): """SLIC does identify nodata on the edge of a noisy background.""" import random + slic_mask = alphamask.slic_mask random.seed(1) diff --git a/tests/test_blob_cli.py b/tests/test_blob_cli.py index 16be4bf..dcb7eb8 100644 --- a/tests/test_blob_cli.py +++ b/tests/test_blob_cli.py @@ -20,184 +20,249 @@ def cleanup(self): except: pass + def test_blob_filling_random(): - tmpdir = '/tmp/blob_filling' + tmpdir = "/tmp/blob_filling" tester = TestingSetup(tmpdir) - okfile = os.path.join(tmpdir, 'ok-random-data.tif') - blobfile = os.path.join(tmpdir, 'ok-random-data-blobs.tif') - filled_file = os.path.join(tmpdir, 'filled-data.tif') + okfile = os.path.join(tmpdir, "ok-random-data.tif") + blobfile = os.path.join(tmpdir, "ok-random-data-blobs.tif") + filled_file = os.path.join(tmpdir, "filled-data.tif") make_testing_data.makehappytiff(okfile, blobfile) runner = CliRunner() - result = runner.invoke(cli, ['blob', blobfile, filled_file, '-m', 4, '-n']) + result = runner.invoke(cli, ["blob", blobfile, filled_file, "-m", 4, "-n"]) assert result.exit_code == 0 assert make_testing_data.getnulldiff(blobfile, filled_file, 101) == None tester.cleanup() + def test_blob_filling_realdata(): - tmpdir = '/tmp/blob_filling' + tmpdir = "/tmp/blob_filling" tester = TestingSetup(tmpdir) - blobfile = os.path.join(os.getcwd(), 'tests/fixtures/blob/seams_4band.tif') - filled_file = os.path.join(tmpdir, 'filliwack.tif') - expectedfile = os.path.join(os.getcwd(), 'tests/expected/blob/seams_4band.tif') + blobfile = os.path.join(os.getcwd(), "tests/fixtures/blob/seams_4band.tif") + filled_file = os.path.join(tmpdir, "filliwack.tif") + expectedfile = os.path.join(os.getcwd(), "tests/expected/blob/seams_4band.tif") runner = CliRunner() - result = runner.invoke(cli, [ - 'blob', blobfile, filled_file, '-m', 4, '-n', '--co', 'compress=LZW']) + result = runner.invoke( + cli, ["blob", blobfile, filled_file, "-m", 4, "-n", "--co", "compress=LZW"] + ) assert result.exit_code == 0 - + raster_tester.compare(filled_file, expectedfile) tester.cleanup() def test_blob_filling_realdata_specific_bands(): - tmpdir = '/tmp/blob_filling' + tmpdir = "/tmp/blob_filling" tester = TestingSetup(tmpdir) - blobfile = os.path.join(os.getcwd(), 'tests/fixtures/blob/seams_4band.tif') - filled_file = os.path.join(tmpdir, 'filliwack-1-2-3.tif') - expectedfile = os.path.join(os.getcwd(), 'tests/expected/blob/bands-1-2-3-filled-only.tif') + blobfile = os.path.join(os.getcwd(), "tests/fixtures/blob/seams_4band.tif") + filled_file = os.path.join(tmpdir, "filliwack-1-2-3.tif") + expectedfile = os.path.join( + os.getcwd(), "tests/expected/blob/bands-1-2-3-filled-only.tif" + ) runner = CliRunner() - result = runner.invoke(cli, [ - 'blob', blobfile, filled_file, '-m', 10, '--co', 'compress=LZW', '--bidx', "[1, 2, 3]"]) + result = runner.invoke( + cli, + [ + "blob", + blobfile, + filled_file, + "-m", + 10, + "--co", + "compress=LZW", + "--bidx", + "[1, 2, 3]", + ], + ) assert result.exit_code == 0 - + raster_tester.compare(filled_file, expectedfile) tester.cleanup() + def test_blob_filling_realdata_rgb(): - tmpdir = '/tmp/blob_filling' + tmpdir = "/tmp/blob_filling" tester = TestingSetup(tmpdir) - blobfile = os.path.join(os.getcwd(), 'tests/fixtures/blob/seams_4band.tif') - rgb_file = os.path.join(tmpdir, '3band.tif') + blobfile = os.path.join(os.getcwd(), "tests/fixtures/blob/seams_4band.tif") + rgb_file = os.path.join(tmpdir, "3band.tif") with rio.open(blobfile) as src: options = src.meta.copy() options.update(nodata=0.0, count=3, tiled=True, blockxsize=256, blockysize=256) - with rio.open(rgb_file, 'w', **options) as dst: + with rio.open(rgb_file, "w", **options) as dst: for b in range(1, 4): dst.write(src.read(b), b) - filled_file = os.path.join(tmpdir, 'filliwack.tif') - expectedfile = os.path.join(os.getcwd(), 'tests/expected/blob/seams_4band.tif') + filled_file = os.path.join(tmpdir, "filliwack.tif") + expectedfile = os.path.join(os.getcwd(), "tests/expected/blob/seams_4band.tif") runner = CliRunner() - result = runner.invoke(cli, [ - 'blob', rgb_file, filled_file, '-m', 4, '-n', '--co', 'compress=LZW', '--alphafy']) + result = runner.invoke( + cli, + [ + "blob", + rgb_file, + filled_file, + "-m", + 4, + "-n", + "--co", + "compress=LZW", + "--alphafy", + ], + ) assert result.exit_code == 0 - + raster_tester.compare(filled_file, expectedfile) tester.cleanup() + def test_blob_filling_realdata_rgba_with_nodata(): - tmpdir = '/tmp/blob_filling' + tmpdir = "/tmp/blob_filling" tester = TestingSetup(tmpdir) - blobfile = os.path.join(os.getcwd(), 'tests/fixtures/blob/seams_4band.tif') - rgb_file = os.path.join(tmpdir, '3band.tif') + blobfile = os.path.join(os.getcwd(), "tests/fixtures/blob/seams_4band.tif") + rgb_file = os.path.join(tmpdir, "3band.tif") with rio.open(blobfile) as src: options = src.meta.copy() options.update(nodata=0.0, tiled=True, blockxsize=256, blockysize=256) - with rio.open(rgb_file, 'w', **options) as dst: + with rio.open(rgb_file, "w", **options) as dst: dst.write(src.read()) - filled_file = os.path.join(tmpdir, 'filliwack.tif') - expectedfile = os.path.join(os.getcwd(), 'tests/expected/blob/seams_4band.tif') + filled_file = os.path.join(tmpdir, "filliwack.tif") + expectedfile = os.path.join(os.getcwd(), "tests/expected/blob/seams_4band.tif") runner = CliRunner() - result = runner.invoke(cli, [ - 'blob', rgb_file, filled_file, '-m', 4, '-n', '--co', 'compress=LZW', '--alphafy']) + result = runner.invoke( + cli, + [ + "blob", + rgb_file, + filled_file, + "-m", + 4, + "-n", + "--co", + "compress=LZW", + "--alphafy", + ], + ) assert result.exit_code == 0 raster_tester.compare(filled_file, expectedfile) tester.cleanup() + def test_blob_filling_realdata_threshold(): - tmpdir = '/tmp/blob_filling' + tmpdir = "/tmp/blob_filling" tester = TestingSetup(tmpdir) - blobfile = os.path.join(os.getcwd(), 'tests/fixtures/blob/thresholder.tif') - filled_file = os.path.join(tmpdir, 'thresh_filled.tif') + blobfile = os.path.join(os.getcwd(), "tests/fixtures/blob/thresholder.tif") + filled_file = os.path.join(tmpdir, "thresh_filled.tif") - expectedfile = os.path.join(os.getcwd(), 'tests/expected/blob/threshold.tif') + expectedfile = os.path.join(os.getcwd(), "tests/expected/blob/threshold.tif") runner = CliRunner() - result = runner.invoke(cli, [ - 'blob', blobfile, filled_file, '-m', 4, '-n', '--co', 'compress=LZW', '-d', 0]) + result = runner.invoke( + cli, + ["blob", blobfile, filled_file, "-m", 4, "-n", "--co", "compress=LZW", "-d", 0], + ) assert result.exit_code == 0 raster_tester.compare(filled_file, expectedfile) tester.cleanup() + def test_blob_filling_rgb(): - tmpdir = '/tmp/blob_filling' + tmpdir = "/tmp/blob_filling" tester = TestingSetup(tmpdir) - infile = os.path.join(os.getcwd(), 'tests/fixtures/blob/rgb_toblob.tif') - blobbed_file = os.path.join(tmpdir, 'blobbedrgb.tif') - expectedfile = os.path.join(os.getcwd(), 'tests/expected/blob/rgb_toblob.tif') + infile = os.path.join(os.getcwd(), "tests/fixtures/blob/rgb_toblob.tif") + blobbed_file = os.path.join(tmpdir, "blobbedrgb.tif") + expectedfile = os.path.join(os.getcwd(), "tests/expected/blob/rgb_toblob.tif") runner = CliRunner() - result = runner.invoke(cli, [ - 'blob', infile, blobbed_file, '-m', 10, '--co', 'compress=JPEG', '--alphafy']) + result = runner.invoke( + cli, + ["blob", infile, blobbed_file, "-m", 10, "--co", "compress=JPEG", "--alphafy"], + ) assert result.exit_code == 0 - + raster_tester.compare(blobbed_file, expectedfile) tester.cleanup() + def test_blob_filling_rgb(): - tmpdir = '/tmp/blob_filling' + tmpdir = "/tmp/blob_filling" tester = TestingSetup(tmpdir) - infile = os.path.join(os.getcwd(), 'tests/fixtures/blob/rgb_toblob.tif') - blobbed_file = os.path.join(tmpdir, 'blobbedrgb.tif') - expectedfile = os.path.join(os.getcwd(), 'tests/expected/blob/rgb_toblob.tif') + infile = os.path.join(os.getcwd(), "tests/fixtures/blob/rgb_toblob.tif") + blobbed_file = os.path.join(tmpdir, "blobbedrgb.tif") + expectedfile = os.path.join(os.getcwd(), "tests/expected/blob/rgb_toblob.tif") runner = CliRunner() - result = runner.invoke(cli, [ - 'blob', infile, blobbed_file, '-m', 10, '--co', 'compress=JPEG', '--alphafy']) + result = runner.invoke( + cli, + ["blob", infile, blobbed_file, "-m", 10, "--co", "compress=JPEG", "--alphafy"], + ) assert result.exit_code == 0 - + raster_tester.compare(blobbed_file, expectedfile) tester.cleanup() + def test_blob_fail_no_nodata(): """Should fail when there RGB + no nodata""" - tmpdir = '/tmp/blob_filling' + tmpdir = "/tmp/blob_filling" tester = TestingSetup(tmpdir) - infile = os.path.join(os.getcwd(), 'tests/fixtures/blob/rgb_toblob.tif') - badfile = os.path.join(tmpdir, 'badfile.tif') + infile = os.path.join(os.getcwd(), "tests/fixtures/blob/rgb_toblob.tif") + badfile = os.path.join(tmpdir, "badfile.tif") with rio.open(infile) as src: options = src.meta.copy() options.update(nodata=None) - with rio.open(badfile, 'w', **options) as dst: + with rio.open(badfile, "w", **options) as dst: dst.write(src.read()) - blobbed_file = os.path.join(tmpdir, 'blobbedrgb.tif') + blobbed_file = os.path.join(tmpdir, "blobbedrgb.tif") runner = CliRunner() - result = runner.invoke(cli, [ - 'blob', badfile, blobbed_file, '-m', 4, '-n', '--co', 'compress=JPEG', '--alphafy']) + result = runner.invoke( + cli, + [ + "blob", + badfile, + blobbed_file, + "-m", + 4, + "-n", + "--co", + "compress=JPEG", + "--alphafy", + ], + ) assert result.exit_code == -1 tester.cleanup() diff --git a/tests/test_blob_func.py b/tests/test_blob_func.py index 2d52449..b27f810 100644 --- a/tests/test_blob_func.py +++ b/tests/test_blob_func.py @@ -2,12 +2,12 @@ import nodata.blob as blob import pytest + def test_window_padding(): - window = ( - (0, 256), - (0, 256) - ) + window = ((0, 256), (0, 256)) assert blob.pad_window(window, 128) == ((-128, 384), (-128, 384)) + + @pytest.fixture def areaToFill(): timg = np.zeros((4, 256, 256), dtype=np.uint8()) @@ -18,10 +18,11 @@ def areaToFill(): rRowInds[rInd] = rRow rColInds[cInd] = rCol for i in range(3): - timg[i, rRowInds[0]: rRowInds[1], rColInds[0]: rColInds[1]] = 100 - timg[-1, rRowInds[0]: rRowInds[1], rColInds[0]: rColInds[1]] = 255 + timg[i, rRowInds[0] : rRowInds[1], rColInds[0] : rColInds[1]] = 100 + timg[-1, rRowInds[0] : rRowInds[1], rColInds[0] : rColInds[1]] = 255 return timg + def test_fill_nodata(areaToFill): mask = areaToFill[-1].copy() notFilledSum = np.sum(np.all(np.dstack(areaToFill) == (0, 0, 0, 0), axis=2)) @@ -29,52 +30,63 @@ def test_fill_nodata(areaToFill): filledSum = np.sum(np.all(np.dstack(filled) == (0, 0, 0, 0), axis=2)) assert notFilledSum > filledSum + def test_handle_rgb(): - img = np.zeros((3, 100,100)) + img = np.zeros((3, 100, 100)) mask = np.zeros((100, 100)) assert blob.handle_RGB(img, mask).shape == (4, 100, 100) + def test_rgb_handling_alphafy(): outNodata, selectNodata, outCount = blob.test_rgb(3, 0.0, True, 4) assert outNodata == None assert selectNodata == 0.0 assert outCount == 4 + def test_rgb_handling_no_alphafy(): outNodata, selectNodata, outCount = blob.test_rgb(3, 0.0, False, 4) assert outNodata == 0.0 assert selectNodata == 0.0 assert outCount == 3 + def test_rgba_handling(): outNodata, selectNodata, outCount = blob.test_rgb(4, None, True, 4) assert outNodata == None assert selectNodata == None assert outCount == 4 + def test_rgb_handling_fail(): with pytest.raises(ValueError): blob.test_rgb(3, None, True, 4) + @pytest.fixture def has_all_nodata(): return np.zeros((8, 8), dtype=np.uint8) + @pytest.fixture def has_one_nodata(): tmpnone = np.zeros((8, 8), dtype=np.uint8) + 255 tmpnone[4, 4] = 0 return tmpnone + @pytest.fixture def has_no_nodata(): return np.zeros((8, 8), dtype=np.uint8) + 255 + def test_run_nodatafiller_nono(has_no_nodata): assert blob.runNodataFiller(has_no_nodata, 2) is False + def test_run_nodatafiller_one(has_one_nodata): assert blob.runNodataFiller(has_one_nodata, 2) is True + def test_run_nodatafiller_all(has_all_nodata): assert blob.runNodataFiller(has_all_nodata, 2) is False diff --git a/tests/test_scripts_alpha.py b/tests/test_scripts_alpha.py index 7999e78..68273ff 100644 --- a/tests/test_scripts_alpha.py +++ b/tests/test_scripts_alpha.py @@ -7,17 +7,19 @@ from rasterio.windows import Window from nodata.scripts.alpha import ( - all_valid, init_worker, finalize_worker, compute_window_mask, - NodataPoolMan) + all_valid, + init_worker, + finalize_worker, + compute_window_mask, + NodataPoolMan, +) def test_all_valid(): - assert ( - all_valid(numpy.empty((2, 2), dtype='uint8'), 0) == 255).all() + assert (all_valid(numpy.empty((2, 2), dtype="uint8"), 0) == 255).all() -@pytest.fixture( - scope='function', params=glob.glob('tests/fixtures/alpha/*.tif')) +@pytest.fixture(scope="function", params=glob.glob("tests/fixtures/alpha/*.tif")) def worker(request): """This provides the global `src` for compute_window_mask""" init_worker(request.param, all_valid) @@ -33,13 +35,15 @@ def test_compute_window_mask(worker): in_window = Window.from_slices((0, 100), (0, 100)) out_window, data = compute_window_mask((in_window, 0, {})) assert in_window == out_window - assert (numpy.fromstring( - zlib.decompress(data), 'uint8').reshape( - [int(c) for c in rasterio.windows.shape(out_window)]) == 255).all() + assert ( + numpy.fromstring(zlib.decompress(data), "uint8").reshape( + [int(c) for c in rasterio.windows.shape(out_window)] + ) + == 255 + ).all() -@pytest.mark.parametrize( - "input_path", glob.glob('tests/fixtures/alpha/*.tif')) +@pytest.mark.parametrize("input_path", glob.glob("tests/fixtures/alpha/*.tif")) def test_pool_man_mask(input_path): """NodataPoolMan initializes and computes mask of a file""" manager = NodataPoolMan(input_path, all_valid, 0) @@ -53,12 +57,10 @@ def test_pool_man_mask(input_path): next(result) -@pytest.mark.parametrize("keywords", [ - {'padding': 0}]) +@pytest.mark.parametrize("keywords", [{"padding": 0}]) def test_pool_man_mask_keywords(keywords): """NodataPoolMan initializes and computes mask of a file""" - manager = NodataPoolMan( - 'tests/fixtures/alpha/lossy-curved-edges.tif', all_valid, 0) + manager = NodataPoolMan("tests/fixtures/alpha/lossy-curved-edges.tif", all_valid, 0) result = manager.mask(windows=[Window.from_slices((0, 100), (0, 100))], **keywords) window, arr = next(result) assert window == Window.from_slices((0, 100), (0, 100)) From 6a98f70901c39da1c0c896f4c6c8e10a095d172f Mon Sep 17 00:00:00 2001 From: dnomadb Date: Tue, 5 Jun 2018 17:10:58 -0700 Subject: [PATCH 04/16] flake8? --- circle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index f583f7f..f382ff5 100644 --- a/circle.yml +++ b/circle.yml @@ -1,7 +1,8 @@ dependencies: pre: - - pip install tox tox-pyenv + - pip install tox tox-pyenv flake8 override: + - flake8 ./ --max-line-length=88 - pyenv local 2.7.10 3.6.1 From a6fa1199047874d80be3c73004c8394a719451ea Mon Sep 17 00:00:00 2001 From: dnomadb Date: Tue, 5 Jun 2018 17:36:33 -0700 Subject: [PATCH 05/16] cleanup --- nodata/blob.py | 2 +- nodata/scripts/alpha.py | 1 - nodata/scripts/cli.py | 11 ----------- tests/make_testing_data.py | 1 - tests/test_alpha_func.py | 2 -- tests/test_blob_cli.py | 27 ++++----------------------- tests/test_blob_func.py | 6 +++--- 7 files changed, 8 insertions(+), 42 deletions(-) diff --git a/nodata/blob.py b/nodata/blob.py index b8762f7..701340a 100644 --- a/nodata/blob.py +++ b/nodata/blob.py @@ -170,7 +170,7 @@ def nibble_filled_mask(filled, nodataval, max_search_distance, is_mask=False): & (filled[2] == nodataval) ) nmsk = maximum_filter(nmsk, size=(max_search_distance * 2 + 1)) - mskInds = np.where(nmsk == True) + mskInds = np.where(nmsk is True) filled[:, mskInds[0], mskInds[1]] = nodataval return filled diff --git a/nodata/scripts/alpha.py b/nodata/scripts/alpha.py index ed38bc5..737af70 100644 --- a/nodata/scripts/alpha.py +++ b/nodata/scripts/alpha.py @@ -1,6 +1,5 @@ from itertools import repeat from multiprocessing import cpu_count, Pool -import sys import zlib try: diff --git a/nodata/scripts/cli.py b/nodata/scripts/cli.py index f479da7..7757874 100644 --- a/nodata/scripts/cli.py +++ b/nodata/scripts/cli.py @@ -67,17 +67,6 @@ def blob( alphafy, ): """""" - args = ( - src_path, - dst_path, - bidx, - max_search_distance, - nibblemask, - creation_options, - mask_threshold, - jobs, - alphafy, - ) blob_nodata( src_path, dst_path, diff --git a/tests/make_testing_data.py b/tests/make_testing_data.py index 2a197b9..db82827 100644 --- a/tests/make_testing_data.py +++ b/tests/make_testing_data.py @@ -1,7 +1,6 @@ import rasterio as rio from rasterio import Affine import numpy as np -import click def makehappytiff(dst_path, seams_path): diff --git a/tests/test_alpha_func.py b/tests/test_alpha_func.py index e39ac63..2ae0986 100644 --- a/tests/test_alpha_func.py +++ b/tests/test_alpha_func.py @@ -1,5 +1,3 @@ -import os -import re import pytest import rasterio as rio import numpy as np diff --git a/tests/test_blob_cli.py b/tests/test_blob_cli.py index dcb7eb8..ba865cf 100644 --- a/tests/test_blob_cli.py +++ b/tests/test_blob_cli.py @@ -1,4 +1,5 @@ -import os, shutil +import os +import shutil from click.testing import CliRunner import rasterio as rio @@ -17,7 +18,7 @@ def __init__(self, testdir): def cleanup(self): try: shutil.rmtree(self.path) - except: + except FileNotFoundError as err: pass @@ -35,7 +36,7 @@ def test_blob_filling_random(): result = runner.invoke(cli, ["blob", blobfile, filled_file, "-m", 4, "-n"]) assert result.exit_code == 0 - assert make_testing_data.getnulldiff(blobfile, filled_file, 101) == None + assert make_testing_data.getnulldiff(blobfile, filled_file, 101) is None tester.cleanup() @@ -210,26 +211,6 @@ def test_blob_filling_rgb(): tester.cleanup() -def test_blob_filling_rgb(): - tmpdir = "/tmp/blob_filling" - tester = TestingSetup(tmpdir) - - infile = os.path.join(os.getcwd(), "tests/fixtures/blob/rgb_toblob.tif") - blobbed_file = os.path.join(tmpdir, "blobbedrgb.tif") - expectedfile = os.path.join(os.getcwd(), "tests/expected/blob/rgb_toblob.tif") - - runner = CliRunner() - - result = runner.invoke( - cli, - ["blob", infile, blobbed_file, "-m", 10, "--co", "compress=JPEG", "--alphafy"], - ) - assert result.exit_code == 0 - - raster_tester.compare(blobbed_file, expectedfile) - tester.cleanup() - - def test_blob_fail_no_nodata(): """Should fail when there RGB + no nodata""" tmpdir = "/tmp/blob_filling" diff --git a/tests/test_blob_func.py b/tests/test_blob_func.py index b27f810..4ef5a7a 100644 --- a/tests/test_blob_func.py +++ b/tests/test_blob_func.py @@ -39,7 +39,7 @@ def test_handle_rgb(): def test_rgb_handling_alphafy(): outNodata, selectNodata, outCount = blob.test_rgb(3, 0.0, True, 4) - assert outNodata == None + assert outNodata is None assert selectNodata == 0.0 assert outCount == 4 @@ -53,8 +53,8 @@ def test_rgb_handling_no_alphafy(): def test_rgba_handling(): outNodata, selectNodata, outCount = blob.test_rgb(4, None, True, 4) - assert outNodata == None - assert selectNodata == None + assert outNodata is None + assert selectNodata is None assert outCount == 4 From 48270dcdfc5d5764ace7498dc1abc92df8d8938c Mon Sep 17 00:00:00 2001 From: dnomadb Date: Tue, 5 Jun 2018 17:42:03 -0700 Subject: [PATCH 06/16] cleanup spaces --- tests/test_blob_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_blob_cli.py b/tests/test_blob_cli.py index ba865cf..c1ceb31 100644 --- a/tests/test_blob_cli.py +++ b/tests/test_blob_cli.py @@ -18,7 +18,7 @@ def __init__(self, testdir): def cleanup(self): try: shutil.rmtree(self.path) - except FileNotFoundError as err: + except FileNotFoundError: pass From 0894d98328c29c29dcda005c23233be5d77264f6 Mon Sep 17 00:00:00 2001 From: dnomadb Date: Wed, 6 Jun 2018 11:43:24 -0700 Subject: [PATCH 07/16] clean up for black --- tests/test_blob_cli.py | 5 +---- tests/test_blob_func.py | 8 ++++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_blob_cli.py b/tests/test_blob_cli.py index c1ceb31..246b023 100644 --- a/tests/test_blob_cli.py +++ b/tests/test_blob_cli.py @@ -16,10 +16,7 @@ def __init__(self, testdir): os.mkdir(self.path) def cleanup(self): - try: - shutil.rmtree(self.path) - except FileNotFoundError: - pass + shutil.rmtree(self.path, ignore_errors=True) def test_blob_filling_random(): diff --git a/tests/test_blob_func.py b/tests/test_blob_func.py index 4ef5a7a..6ed1384 100644 --- a/tests/test_blob_func.py +++ b/tests/test_blob_func.py @@ -17,9 +17,13 @@ def areaToFill(): rInd, cInd = np.random.randint(0, 2, 2) rRowInds[rInd] = rRow rColInds[cInd] = rCol + r1, r2 = rRowInds + c1, c2 = rColInds for i in range(3): - timg[i, rRowInds[0] : rRowInds[1], rColInds[0] : rColInds[1]] = 100 - timg[-1, rRowInds[0] : rRowInds[1], rColInds[0] : rColInds[1]] = 255 + timg[i, r1:r2, c1:c2] = 100 + + timg[-1, r1:r2, c1:c2] = 255 + return timg From fbac746f1acd9886dd505e5e2143854f42403d64 Mon Sep 17 00:00:00 2001 From: dnomadb Date: Wed, 6 Jun 2018 14:10:58 -0700 Subject: [PATCH 08/16] is is not equals in np landia --- nodata/blob.py | 2 +- tests/test_blob_cli.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/nodata/blob.py b/nodata/blob.py index 701340a..da3334e 100644 --- a/nodata/blob.py +++ b/nodata/blob.py @@ -170,7 +170,7 @@ def nibble_filled_mask(filled, nodataval, max_search_distance, is_mask=False): & (filled[2] == nodataval) ) nmsk = maximum_filter(nmsk, size=(max_search_distance * 2 + 1)) - mskInds = np.where(nmsk is True) + mskInds = np.where(nmsk) filled[:, mskInds[0], mskInds[1]] = nodataval return filled diff --git a/tests/test_blob_cli.py b/tests/test_blob_cli.py index 246b023..33da1c9 100644 --- a/tests/test_blob_cli.py +++ b/tests/test_blob_cli.py @@ -122,6 +122,7 @@ def test_blob_filling_realdata_rgb(): "--alphafy", ], ) + assert result.exit_code == 0 raster_tester.compare(filled_file, expectedfile) From 8ac402a9bcf90af5b60529dce0235ac8654af9f7 Mon Sep 17 00:00:00 2001 From: dnomadb Date: Wed, 6 Jun 2018 14:50:37 -0700 Subject: [PATCH 09/16] trying precommit setup --- .pre-commit-config.yaml | 7 ++++++- circle.yml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0c39c64..de70852 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,4 +4,9 @@ repos: hooks: - id: black args: [--safe] - language_version: python3.6 \ No newline at end of file + language_version: python3.6 +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v1.2.3 + hooks: + - id: flake8 + args: [--max-line-length=88] diff --git a/circle.yml b/circle.yml index f382ff5..da2e677 100644 --- a/circle.yml +++ b/circle.yml @@ -4,5 +4,5 @@ dependencies: - pip install tox tox-pyenv flake8 override: - - flake8 ./ --max-line-length=88 + - "git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files" - pyenv local 2.7.10 3.6.1 From 5e012a7447be1949738a7317dc7093231ea74c68 Mon Sep 17 00:00:00 2001 From: dnomadb Date: Wed, 6 Jun 2018 14:54:21 -0700 Subject: [PATCH 10/16] preinstall precommit --- circle.yml | 2 +- requirements.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index da2e677..7d62509 100644 --- a/circle.yml +++ b/circle.yml @@ -1,7 +1,7 @@ dependencies: pre: - - pip install tox tox-pyenv flake8 + - pip install tox tox-pyenv flake8 pre-commit override: - "git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files" diff --git a/requirements.txt b/requirements.txt index f2c317e..9cb3015 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,3 @@ rasterio raster-tester scikit-image scipy -pre-commit From 64f0026bf67085f2d630f285874b4a00b94a647e Mon Sep 17 00:00:00 2001 From: dnomadb Date: Wed, 6 Jun 2018 15:01:14 -0700 Subject: [PATCH 11/16] do not override python version --- .pre-commit-config.yaml | 1 - circle.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index de70852..5290d3c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,6 @@ repos: hooks: - id: black args: [--safe] - language_version: python3.6 - repo: https://github.com/pre-commit/pre-commit-hooks rev: v1.2.3 hooks: diff --git a/circle.yml b/circle.yml index 7d62509..e18419d 100644 --- a/circle.yml +++ b/circle.yml @@ -1,7 +1,7 @@ dependencies: pre: - - pip install tox tox-pyenv flake8 pre-commit + - pip install tox tox-pyenv pre-commit override: - "git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files" From b78b68bb9583ea1388efb31d3e679ceaac5b2371 Mon Sep 17 00:00:00 2001 From: dnomadb Date: Wed, 6 Jun 2018 15:54:37 -0700 Subject: [PATCH 12/16] revert to fbac746f1acd9886dd505e5e2143854f42403d64 --- .pre-commit-config.yaml | 6 +----- circle.yml | 4 ++-- requirements.txt | 1 + 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5290d3c..0c39c64 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,8 +4,4 @@ repos: hooks: - id: black args: [--safe] -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v1.2.3 - hooks: - - id: flake8 - args: [--max-line-length=88] + language_version: python3.6 \ No newline at end of file diff --git a/circle.yml b/circle.yml index e18419d..f382ff5 100644 --- a/circle.yml +++ b/circle.yml @@ -1,8 +1,8 @@ dependencies: pre: - - pip install tox tox-pyenv pre-commit + - pip install tox tox-pyenv flake8 override: - - "git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files" + - flake8 ./ --max-line-length=88 - pyenv local 2.7.10 3.6.1 diff --git a/requirements.txt b/requirements.txt index 9cb3015..f2c317e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ rasterio raster-tester scikit-image scipy +pre-commit From bd9b62b56b883e76f468ea012a0f23f9c2059bff Mon Sep 17 00:00:00 2001 From: dnomadb Date: Thu, 7 Jun 2018 14:05:16 -0700 Subject: [PATCH 13/16] revert to 5e012a7447be1949738a7317dc7093231ea74c68 --- .pre-commit-config.yaml | 7 ++++++- circle.yml | 4 ++-- requirements.txt | 1 - 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0c39c64..de70852 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,4 +4,9 @@ repos: hooks: - id: black args: [--safe] - language_version: python3.6 \ No newline at end of file + language_version: python3.6 +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v1.2.3 + hooks: + - id: flake8 + args: [--max-line-length=88] diff --git a/circle.yml b/circle.yml index f382ff5..7d62509 100644 --- a/circle.yml +++ b/circle.yml @@ -1,8 +1,8 @@ dependencies: pre: - - pip install tox tox-pyenv flake8 + - pip install tox tox-pyenv flake8 pre-commit override: - - flake8 ./ --max-line-length=88 + - "git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files" - pyenv local 2.7.10 3.6.1 diff --git a/requirements.txt b/requirements.txt index f2c317e..9cb3015 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,3 @@ rasterio raster-tester scikit-image scipy -pre-commit From 16aedf982b576e8cdb9af45770d696c38de27a89 Mon Sep 17 00:00:00 2001 From: dnomadb Date: Thu, 7 Jun 2018 15:15:00 -0700 Subject: [PATCH 14/16] check for python version before running precommit --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 7d62509..4fba85f 100644 --- a/circle.yml +++ b/circle.yml @@ -4,5 +4,5 @@ dependencies: - pip install tox tox-pyenv flake8 pre-commit override: - - "git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files" + - "if $(python -V 2>&1 | grep -q 'Python\s3\.6'); then git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files; fi" - pyenv local 2.7.10 3.6.1 From 3a1175d1bd02937c7e87357a9c2d9310bf0ebf3f Mon Sep 17 00:00:00 2001 From: dnomadb Date: Thu, 7 Jun 2018 15:17:39 -0700 Subject: [PATCH 15/16] there is no escaping --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 4fba85f..fac9771 100644 --- a/circle.yml +++ b/circle.yml @@ -4,5 +4,5 @@ dependencies: - pip install tox tox-pyenv flake8 pre-commit override: - - "if $(python -V 2>&1 | grep -q 'Python\s3\.6'); then git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files; fi" + - "if $(python -V 2>&1 | grep -q 'Python 3.6'); then git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files; fi" - pyenv local 2.7.10 3.6.1 From 46e5d4bf5a2be1602d5f60d357be08c43f68e52e Mon Sep 17 00:00:00 2001 From: dnomadb Date: Thu, 7 Jun 2018 15:37:42 -0700 Subject: [PATCH 16/16] run on all files --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index fac9771..1bc9fba 100644 --- a/circle.yml +++ b/circle.yml @@ -4,5 +4,5 @@ dependencies: - pip install tox tox-pyenv flake8 pre-commit override: - - "if $(python -V 2>&1 | grep -q 'Python 3.6'); then git diff-tree --no-commit-id --name-only -r $CIRCLE_SHA1 | xargs pre-commit run --files; fi" + - "if $(python -V 2>&1 | grep -q 'Python 3.6'); then pre-commit run --all-files; fi" - pyenv local 2.7.10 3.6.1