def _default_fuser(dst: np.ndarray, src: np.ndarray, dst_nodata) -> None: """ Overwrite only those pixels in `dst` with `src` that are "not valid" For every pixel in dst that equals to dst_nodata replace it with pixel from src. """ np.copyto(dst, src, where=invalid_mask(dst, dst_nodata))
def test_valid_mask(): xx = np.zeros((4, 8), dtype='float32') mm = valid_mask(xx, 0) assert mm.dtype == 'bool' assert mm.shape == xx.shape assert not mm.all() assert not mm.any() nn = invalid_mask(xx, 0) assert nn.dtype == 'bool' assert nn.shape == xx.shape assert nn.all() assert nn.any() mm = valid_mask(xx, 13) assert mm.dtype == 'bool' assert mm.shape == xx.shape assert mm.all() nn = invalid_mask(xx, 13) assert nn.dtype == 'bool' assert nn.shape == xx.shape assert not nn.any() mm = valid_mask(xx, None) assert mm.dtype == 'bool' assert mm.shape == xx.shape assert mm.all() nn = invalid_mask(xx, None) assert nn.dtype == 'bool' assert nn.shape == xx.shape assert not nn.any() mm = valid_mask(xx, np.nan) assert mm.dtype == 'bool' assert mm.shape == xx.shape assert mm.all() nn = invalid_mask(xx, np.nan) assert nn.dtype == 'bool' assert nn.shape == xx.shape assert not nn.any() xx[0, 0] = np.nan mm = valid_mask(xx, np.nan) assert not mm[0, 0] assert mm.sum() == (4 * 8 - 1) nn = invalid_mask(xx, np.nan) assert nn[0, 0] assert nn.sum() == 1