lib.filtlib module

Library of spatial filters for 2D NumPy arrays

pygeotools.lib.filtlib.abs_range_fltr_lowresDEM(dem_fn, refdem_fn, pad=30)[source]
pygeotools.lib.filtlib.absrange_fltr(dem, rangelim)[source]

Absolute range filter

pygeotools.lib.filtlib.bandpass(dem, size1=None, size2=None)[source]
pygeotools.lib.filtlib.butter(dt_list, val, lowpass=1.0)[source]

This is framework for a butterworth bandpass for 1D data

Needs to be cleaned up and generalized

pygeotools.lib.filtlib.butter_low(dt_list, val, lowpass=1.0)[source]
pygeotools.lib.filtlib.circular_mask(size)[source]

Create a circular mask for an array

Useful when sampling rasters for a laser shot

pygeotools.lib.filtlib.dz_fltr(dem_fn, refdem_fn, perc=None, rangelim=(0, 30), smooth=False)[source]

Absolute elevation difference range filter using values from a source raster file and a reference raster file

pygeotools.lib.filtlib.dz_fltr_ma(dem, refdem, perc=None, rangelim=(0, 30), smooth=False)[source]

Absolute elevation difference range filter using values from a source array and a reference array

pygeotools.lib.filtlib.erode_edge(dem, iterations=1)[source]

Erode pixels near nodata

pygeotools.lib.filtlib.freq_filt(bma)[source]

This is a framework for 2D FFT filtering. It has not be tested or finished - might be a dead end

See separate utility freq_analysis.py

pygeotools.lib.filtlib.gauss_fltr(dem, sigma=1)[source]
pygeotools.lib.filtlib.gauss_fltr_astropy(dem, size=None, sigma=None, origmask=False, fill_interior=False)[source]

Astropy gaussian filter properly handles convolution with NaN

http://stackoverflow.com/questions/23832852/by-which-measures-should-i-set-the-size-of-my-gaussian-filter-in-matlab

width1 = 3; sigma1 = (width1-1) / 6; Specify width for smallest feature of interest and determine sigma appropriately

sigma is width of 1 std in pixels (not multiplier)

scipy and astropy both use cutoff of 4*sigma on either side of kernel - 99.994%

3*sigma on either side of kernel - 99.7%

If sigma is specified, filter width will be a multiple of 8 times sigma

Alternatively, specify filter size, then compute sigma: sigma = (size - 1) / 8.

If size is < the required width for 6-8 sigma, need to use different mode to create kernel

mode ‘oversample’ and ‘center’ are essentially identical for sigma 1, but very different for sigma 0.3

The sigma/size calculations below should work for non-integer sigma

pygeotools.lib.filtlib.gauss_fltr_opencv(dem, size=3, sigma=1)[source]

OpenCV Gaussian filter Still propagates NaN values

pygeotools.lib.filtlib.gauss_fltr_pyramid(dem, size=None, full=False, origmask=False)[source]

Pyaramidal downsampling approach for gaussian smoothing Avoids the need for large kernels, very fast Needs testing

pygeotools.lib.filtlib.gaussfill(dem, size=3, newmask=None)[source]

Gaussian filter with filling

pygeotools.lib.filtlib.highpass(dem, size=None, sigma=None)[source]
pygeotools.lib.filtlib.lowpass(dem, size=None, sigma=None)[source]
pygeotools.lib.filtlib.mad_fltr(dem, n=3)[source]

Median absolute deviation * factor filter

Robust outlier removal

pygeotools.lib.filtlib.median_fltr(dem, fsize=7, origmask=False)[source]

Scipy.ndimage median filter

Does not properly handle NaN

pygeotools.lib.filtlib.median_fltr_opencv(dem, size=3, iterations=1)[source]

OpenCV median filter

pygeotools.lib.filtlib.median_fltr_skimage(dem, radius=3, erode=1, origmask=False)[source]

Older skimage.filter.median_filter

This smooths, removes noise and fills in nodata areas with median of valid pixels! Effectively an inpainting routine

pygeotools.lib.filtlib.perc_fltr(dem, perc=(1.0, 99.0))[source]

Percentile filter

pygeotools.lib.filtlib.range_fltr(dem, rangelim)[source]

Range filter (helper function)

pygeotools.lib.filtlib.remove_islands(dem, iterations=1)[source]

Remove isolated pixels

pygeotools.lib.filtlib.rolling_fltr(dem, f=<Mock id='140637716130256'>, size=3, circular=True, origmask=False)[source]

General rolling filter (default operator is median filter)

Can input any function f

Efficient for smaller arrays, correclty handles NaN, fills gaps

pygeotools.lib.filtlib.sigma_fltr(dem, n=3)[source]

sigma * factor filter

Useful for outlier removal

These are min/max percentile ranges for different sigma values: 1: 15.865, 84.135 2: 2.275, 97.725 3: 0.135, 99.865

pygeotools.lib.filtlib.slope_fltr_ds(dem_ds, slopelim=(0, 40))[source]
pygeotools.lib.filtlib.slope_fltr_fn(dem_fn, slopelim=(0, 40))[source]
pygeotools.lib.filtlib.uniform_fltr(dem, fsize=7)[source]

Uniform (mean) filter

Note: suffers from significant ringing