def test_rescale(arr, ndv, dst_dtype): if dst_dtype == np.__dict__['uint16']: assert np.array_equal( _rescale(arr, ndv, dst_dtype), np.concatenate( [ (arr).astype(dst_dtype), _simple_mask( arr.astype(dst_dtype), (ndv, ndv, ndv) ).reshape(1, arr.shape[1], arr.shape[2]) ] ) ) else: assert np.array_equal( _rescale(arr, ndv, dst_dtype), np.concatenate( [ (arr / 257.0).astype(dst_dtype), _simple_mask( arr.astype(dst_dtype), (ndv, ndv, ndv) ).reshape(1, arr.shape[1], arr.shape[2]) ] ) )
def test_simple_mask(data, ndv): '''Exact nodata masking''' nd = np.iinfo(data.dtype).max assert np.array_equal( _simple_mask(data, ndv), np.invert(np.all(np.dstack(data) == ndv, axis=2)).astype(data.dtype) * nd)
def test_simple_mask(data, ndv): '''Exact nodata masking''' nd = np.iinfo(data.dtype).max assert np.array_equal( _simple_mask(data, ndv), np.invert( np.all( np.dstack(data) == ndv, axis=2 ) ).astype(data.dtype) * nd)
def test_rescale(arr, ndv, dst_dtype): if dst_dtype == np.__dict__['uint16']: assert np.array_equal( _rescale(arr, ndv, dst_dtype), np.concatenate([ (arr).astype(dst_dtype), _simple_mask(arr.astype(dst_dtype), (ndv, ndv, ndv)).reshape(1, arr.shape[1], arr.shape[2]) ])) else: assert np.array_equal( _rescale(arr, ndv, dst_dtype), np.concatenate([ (arr / 257.0).astype(dst_dtype), _simple_mask(arr.astype(dst_dtype), (ndv, ndv, ndv)).reshape(1, arr.shape[1], arr.shape[2]) ]))