From 83acc2e1dc3d4abd4e0392e401802137a4402b1b Mon Sep 17 00:00:00 2001 From: David de Meij Date: Tue, 15 Mar 2022 16:26:01 +0100 Subject: [PATCH] Return False, None if the mask for a certain tile contains no valid pixels. --- s2p/initialization.py | 2 ++ s2p/masking.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/s2p/initialization.py b/s2p/initialization.py index 7e147294..fab72d95 100644 --- a/s2p/initialization.py +++ b/s2p/initialization.py @@ -308,6 +308,8 @@ def is_this_tile_useful(x, y, w, h, images_sizes): wat_msk = cfg['images'][0]['wat'] mask = masking.image_tile_mask(x, y, w, h, roi_msk, cld_msk, wat_msk, images_sizes[0], cfg['border_margin']) + if not mask.any(): + return False, None return True, mask diff --git a/s2p/masking.py b/s2p/masking.py index 46cc0943..414d7e72 100644 --- a/s2p/masking.py +++ b/s2p/masking.py @@ -69,6 +69,8 @@ def image_tile_mask(x, y, w, h, roi_gml=None, cld_gml=None, raster_mask=None, with rasterio.open(raster_mask, 'r') as f: mask = np.logical_and(mask, f.read(window=((y, y+h), (x, x+w)), boundless=True).squeeze()) + if not mask.any(): + return mask # image borders mask if img_shape is not None: