5/12/2015© 2009 Raymond P. Jefferis III Lect Geographic Information Processing Data Analysis Watersheds Gradient path - Valleys - Ridges Flow analysis Contours Chester County, PA Watersheds, Chester County Board of Commissioners
5/12/2015© 2009 Raymond P. Jefferis III Lect Computing Watersheds Gradient-following –Locating valleys –Locating ridges
5/12/2015© 2009 Raymond P. Jefferis III Lect Gradient-Following Methods Spatial derivatives computed in both x- and y-directions Vector addition of derivatives produces gradient vectors Negative gradients point “down” Positive gradients point “up” Follow gradients to valleys or peaks
5/12/2015© 2009 Raymond P. Jefferis III Lect Data Preparation Gradient-following methods become “stuck” at local minima DTED Level 2 data has had pockets filled [filled DEM data] Use digital filtering to smooth contours before computing gradients. Gaussian filtering is best for band-limited random noise.
5/12/2015© 2009 Raymond P. Jefferis III Lect Following the Gradient Perform Gaussian filtering of data Compute gradient at all points, using Savitsky and Golay (or other) filter Start at any point Move in direction of desired gradient Stop when gradient is zero (This can be minimum or maximum point)
5/12/2015© 2009 Raymond P. Jefferis III Lect Notes Two derivatives computed for each point –x-direction derivative –y-direction derivative Gradient is vector sum of x- and y- derivative at each point (Result will have Magnitude and Direction)
5/12/2015© 2009 Raymond P. Jefferis III Lect Gradient Computation For data field, f(x,y), the gradient vector is a vector of spatial derivatives defined as: Where,
5/12/2015© 2009 Raymond P. Jefferis III Lect Note Geographic pixels are of finite extent (not infinitesimal), thus the gradients must be computed by finite difference methods that only approximate the derivative definitions above.
5/12/2015© 2009 Raymond P. Jefferis III Lect Computational Notes G x can be computed by convolution, using a kernel that gives the x-gradient G y can be computed by convolution, using a kernel that gives the y-gradient The actual gradient is vector sum of these (See next slide for polar coordinate vector)
5/12/2015© 2009 Raymond P. Jefferis III Lect Derivative Magnitude and Direction Can produce gradient vector at each point.
5/12/2015© 2009 Raymond P. Jefferis III Lect Computing Gradients Nearest neighbor differencing –Follows the finite approximation –Amplifies data noise (no smoothing) Convolution –Uses special kernels –Can do smoothing of entire image –Rapid computations (parallel processing)
5/12/2015© 2009 Raymond P. Jefferis III Lect Problems with Gradient Methods Local minima –Gradient gets “stuck” in a local minimum –Level 2 DTED data should eliminate this –Filter data for smooth contours Data resolution limits –Resolution of 1 meter makes valleys flat –Adds Uniform random noise –Results in big “puddles” (See following:)
5/12/2015© 2009 Raymond P. Jefferis III Lect Altitude Resolution Problem Gradient-following result Filtering: 7x7 Gaussian convolute Altitude resolution: 1 meter Note flat areas where gradient cannot be resolved (black)
5/12/2015© 2009 Raymond P. Jefferis III Lect Solutions More smoothing (15x15 convolute) [use Gaussian convolution kernel] Use 11x11 convolute for derivatives More complex descent algorithms Using surveyed stream/river data and connecting descending flows to these streams/rivers
5/12/2015© 2009 Raymond P. Jefferis III Lect Malvern Gradient Vectors Heights convolution filtered Gaussian filter 15 x 15 kernel Gradients by convolution Savitsky & Golay 11 x 11 kernels Gradients shown at every 7th point
5/12/2015© 2009 Raymond P. Jefferis III Lect Note Inspect Savitsky & Golay derivative convolution kernels at this point. (Handout)
5/12/2015© 2009 Raymond P. Jefferis III Lect Savitsky & Golay Kernels Polynomial based User selects polynomial type –Quadratic,Cubic, Quartic, Quintic, etc. User selects number of terms –Number of data points used in filter calculation –Varies degree of smoothing (more points means more smoothing - more information used from surrounding points for each point at which derivative is calculated)
5/12/2015© 2009 Raymond P. Jefferis III Lect x15 Gaussian Filter Kernel Array[c, 16, 16]; n = 15; sm = ; c = {{1, 2, 3, 5, 6, 7, 8, 9, 8, 7, 6, 5, 3, 2, 1}, {2, 3, 5, 8, 10, 13, 14, 15, 14, 13, 10, 8, 5, 3, 2}, {3, 5, 8, 12, 16, 20, 22, 23, 22, 20, 16, 12, 8, 5, 3}, {5, 8, 12, 18, 23, 29, 32, 34, 32, 29, 23, 18, 12, 8, 5}, {6, 10, 16, 23, 31, 38, 43, 45, 43, 38, 31, 23, 16, 10, 6}, {7, 13, 20, 29, 38, 47, 53, 55, 53, 47, 38, 29, 20, 13, 7}, {8, 14, 22, 32, 43, 53, 60, 62, 60, 53, 43, 32, 22, 14, 8}, {9, 15, 23, 34, 45, 55, 62, 65, 62, 55, 45, 34, 23, 15, 9}, {8, 14, 22, 32, 43, 53, 60, 62, 60, 53, 43, 32, 22, 14, 8}, {7, 13, 20, 29, 38, 47, 53, 55, 53, 47, 38, 29, 20, 13, 7}, {6, 10, 16, 23, 31, 38, 43, 45, 43, 38, 31, 23, 16, 10, 6}, {5, 8, 12, 18, 23, 29, 32, 34, 32, 29, 23, 18, 12, 8, 5}, {3, 5, 8, 12, 16, 20, 22, 23, 22, 20, 16, 12, 8, 5, 3}, {2, 3, 5, 8, 10, 13, 14, 15, 14, 13, 10, 8, 5, 3, 2}, {1, 2, 3, 5, 6, 7, 8, 9, 8, 7, 6, 5, 3, 2, 1}}/sm;
5/12/2015© 2009 Raymond P. Jefferis III Lect Derivative Kernels (S & G) Array[cx, 12, 12]; n = 11; sm = 110.0; cx = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}/sm; Array[cy, 12, 12]; n = 11; sm = 110.0; cy = {{0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, -2, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0}}/sm;
5/12/2015© 2009 Raymond P. Jefferis III Lect Finding Valleys Smooth data, using Gaussian convolution filtering Compute gradient at all points, using Savitsky & Golay derivative kernel Select starting points Follow gradient downward Stop when gradient is zero or path reverses
5/12/2015© 2009 Raymond P. Jefferis III Lect Malvern Flow Tracks Heights convolution filtered Gaussian filter 15 x 15 kernel Gradients by convolution Savitsky & Golay 11 x 11 kernel Tracks follow gradients, starting from every 8th pixel
5/12/2015© 2009 Raymond P. Jefferis III Lect Gradient-Following Code For[jx = 7, jx < nx - 10, jx += 5,{ For[jy = 7, jy < ny - 10, jy += 5, { kx = jx; ky = jy; exit = False; While[ kx > 6 && ky > 6 && kx < (nx - 10) && ky < (ny - 10) && ! Exit, zr = gx[[kx - 6, ky - 6]]; zi = gy[[kx - 6, ky - 6]]; zc = 1.0*RandomInteger[{-1, 1}] + ArcTan[zi, zr]/Degree; If[zc < 0.0, zc = zc]; rzc = 1 + Mod[(Round[zc/22.5](*+RandomInteger[{-1,1}]*)), 16]; vec = dxy[[rzc]]; kx = kx +vec[[1]]; ky = ky + vec[[2]]; If[((kx < 1) || (ky < 1) || y[[ kx, ky]] < 0.0), exit = True]; y[[ kx, ky]] = -1.0; sd[[ kx + 7, ky + 7]] = -1.0; ]; }] }]
5/12/2015© 2009 Raymond P. Jefferis III Lect Possible Applications Watershed analysis Finding wetlands Predicting path of HAZMAT spill Back-tracing contaminants to source(s)
5/12/2015© 2009 Raymond P. Jefferis III Lect Visualization
5/12/2015© 2009 Raymond P. Jefferis III Lect Flow Analysis Gradients direct flow to adjacent cells Flows merge and add (volumetric flow) Show on plot when flow volume exceeds a given threshold Note - Possible improvement: Add to altitude as flow volume increases May require re-computation of gradients
5/12/2015© 2009 Raymond P. Jefferis III Lect Merging Flows Set starting point flow to unity Move one pixel along gradient Merge, adding flows Plot when flow > threshhold
5/12/2015© 2009 Raymond P. Jefferis III Lect Finding Ridge Lines Smooth data, using Gaussian convolution kernel Compute gradients at all points, using Savitsky & Golay derivative kernel Select starting points Follow against gradient to ridge line
5/12/2015© 2009 Raymond P. Jefferis III Lect Malvern Ridge Lines Ridge lines found by following gradient backward to maximum Starting point every 5 pixels.
5/12/2015© 2009 Raymond P. Jefferis III Lect Gradient-Following Code For[jx = 7, jx 6 && ky > 6 && kx < (nx - 10) && ky < (ny - 10) && ! exit, zr = gx[[kx - 6, ky - 6]]; zi = gy[[kx - 6, ky - 6]]; zc = 1.0*RandomInteger[{-1, 1}] + ArcTan[zi, zr]/Degree; If[zc < 0.0, zc = zc]; rzc = 1 + Mod[(Round[zc/22.5](*+RandomInteger[{-1,1}]*)), 16]; vec = dxy[[rzc]]; kx = kx - vec[[1]]; ky = ky - vec[[2]]; If[((kx < 1) || (ky < 1) || y[[ kx, ky]] < 0.0), exit = True]; y[[ kx, ky]] = -1.0; sd[[ kx + 7, ky + 7]] = -1.0; ]; }] }]
5/12/2015© 2009 Raymond P. Jefferis III Lect Possible Application Locating watershed ridge lines Locating source of contamination
5/12/2015© 2009 Raymond P. Jefferis III Lect Max., Min., and Curvature Gradient minimum and maximum points - Filter: S&G 15-point - Point selection; Gradient < 0.4 Curvature > 240
5/12/2015© 2009 Raymond P. Jefferis III Lect Contours Contour map after Gaussian filtering Malvern Quadrangle USGS DEM Data Contours appear as horizontal slices through topography. Contour spacing can be controlled by software.
5/12/2015© 2009 Raymond P. Jefferis III Lect Data Preparation Bad data points are removed Data is smoothed (Gaussian filter) Contour interval is selected (or specific contour set is selected) Color scheme is selected
5/12/2015© 2009 Raymond P. Jefferis III Lect Plotting Contours ListContourPlot[y, AspectRatio -> / , Contours -> {40, 80, 120, 160, 200, 240, 280, 320}, ColorFunction -> "Topographic"] Notes: Contours produced at indicated heights (meters). Aspect ratio corrects image for latitude Other color functions possible
5/12/2015© 2009 Raymond P. Jefferis III Lect Contour Plot Problems Digital filtering required to insure smooth contours BEWARE! Contour plots require a LOT of memory in computer.
5/12/2015© 2009 Raymond P. Jefferis III Lect Discussion