# # Author: Heresh Fattahi # Copyright 2017 # import isce import isceobj from osgeo import gdal import numpy as np import os def fill(data, invalid=None): """ Replace the value of invalid 'data' cells (indicated by 'invalid') by the value of the nearest valid data cell Input: data: numpy array of any dimension invalid: a binary array of same shape as 'data'. data value are replaced where invalid is True If None (default), use: invalid = np.isnan(data) Output: Return a filled array. """ from scipy import ndimage if invalid is None: invalid = np.isnan(data) ind = ndimage.distance_transform_edt(invalid, return_distances=False, return_indices=True) return data[tuple(ind)] def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName): #masking and Filtering from scipy import ndimage ##Read in the offset file ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly) Offset = ds.GetRasterBand(1).ReadAsArray() ds = None ##Read in the SNR file ds = gdal.Open(snrFile + '.vrt', gdal.GA_ReadOnly) snr = ds.GetRasterBand(1).ReadAsArray() ds = None # Masking the dense offsets based on SNR print ('masking the dense offsets with SNR threshold: ', snrThreshold) Offset[snr