{"id":159,"date":"2007-10-02T07:00:22","date_gmt":"2007-10-02T11:00:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2007\/10\/02\/upslope-area-influence-dependence-maps\/"},"modified":"2019-10-23T15:18:55","modified_gmt":"2019-10-23T19:18:55","slug":"upslope-area-influence-dependence-maps","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2007\/10\/02\/upslope-area-influence-dependence-maps\/","title":{"rendered":"Upslope area &#8211; influence and dependence maps"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>In my <a href=\"https:\/\/blogs.mathworks.com\/steve\/2007\/08\/07\/upslope-area-flow-matrix\/\">August 7th post<\/a> on upslope area, I showed how to construct and solve the flow matrix to determine the upslope area for every pixel in a digital\r\n      elevation model (DEM).  In addition, the flow matrix can be used to compute both the <i>influence map<\/i> and the <i>dependence map<\/i>.\r\n   <\/p>\r\n   <p>The influence map shows where water starting from a particular pixel will drain. The dependence map shows which uphill pixels\r\n      drain through a particular pixel.  Let's look at how to compute these from the flow matrix.\r\n   <\/p>\r\n   <p>Recall the form of the flow equation for a particular pixel: The upslope area of a pixel equals 1 plus a weighted fraction\r\n      of the upslope area of each of its neighbors.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/159\/upslope_area_maps_eq96125.png\"> <\/p>\r\n   <p>The 1 term comes from assuming each pixel contributes an equal volume to the overall flow across the terrain.  Think of it\r\n      as rain falling equally on each pixel.  To compute the influence map, then, we just have to modify our set of equations so\r\n      that the 1 term appears only for the pixel or pixels of interest.  Fortunately, that only affects the right-hand side of the\r\n      equation, not the flow matrix itself.  So solving for the influence map a particular pixel looks almost like solving for upslope\r\n      area for all pixels.\r\n   <\/p>\r\n   <p>Here's an example from the Milford, Massachusetts DEM that I've used before:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">s = load(<span style=\"color: #A020F0\">'milford_ma_dem'<\/span>);\r\nE = s.Zc;\r\nimshow(E, [])\r\nlimits = [160 220 215 270];\r\naxis(limits);\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\nplot(169, 227, <span style=\"color: #A020F0\">'*'<\/span>)\r\nhold <span style=\"color: #A020F0\">off<\/span>\r\ntitle(<span style=\"color: #A020F0\">'Pixel near the top of Peppercorn Hill'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/159\/upslope_area_maps_01.jpg\"> <p>Find the flow directions and flow matrix using dem_flow and flow_matrix from my <a title=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=15818&amp;objectType=FILE (link no longer works)\">upslope area toolbox<\/a> on MATLAB Central:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">R = dem_flow(E);\r\nT = flow_matrix(E, R);<\/pre><p>Make a vector for the right-hand side that has a single 1 corresponding to the (227,169) pixel:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">[M, N] = size(E);\r\nrhs = zeros(numel(E), 1);\r\nidx = (169-1)*M + 227;\r\nrhs(idx) = 1;<\/pre><p>Solve for the influence map:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">I = T \\ rhs;\r\nI = reshape(I, M, N);\r\nimshow(I,[])\r\naxis(limits);\r\ntitle(<span style=\"color: #A020F0\">'Influence map'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/159\/upslope_area_maps_02.jpg\"> <p>The influence_map function does all this for you.  I also included a visualization function (vis_map) that superimposes the\r\n      influence (or dependence) map transparently, in green, on top of the original DEM.  The starting pixels are superimposed in\r\n      blue.  Here's what it looks like for our example:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">vis_map(I, E, 227, 169);\r\naxis(limits);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/159\/upslope_area_maps_03.jpg\"> <p>To compute the dependence map, you can't use the flow matrix exactly as is; you have to transpose it. Otherwise, it's very\r\n      similar to the influence map computation.  See the code in dependence_map for the details.\r\n   <\/p>\r\n   <p>Here's an example that computes the dependence map for an entire set of pixels, not just a single pixel.  Specifically, it's\r\n      the dependence map for North Pond:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">plateaus = imerode(E, ones(3, 3)) == E;\r\npond = bwselect(plateaus, 183, 170);\r\nD = dependence_map(E, T, pond);\r\nvis_map(D, E, pond);\r\nxlim([110 240])\r\nylim([80 260])<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/159\/upslope_area_maps_04.jpg\"> <p>Next time I plan to talk about vectorizing the pixel flow direction calculation.<\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_9bd101fecdf84782abdeef3437846407() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='9bd101fecdf84782abdeef3437846407 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 9bd101fecdf84782abdeef3437846407';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Steve Eddins';\r\n        copyright = 'Copyright 2007 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_9bd101fecdf84782abdeef3437846407()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.5<br><\/p>\r\n<\/div>\r\n<!--\r\n9bd101fecdf84782abdeef3437846407 ##### SOURCE BEGIN #####\r\n%%\r\n% In my <https:\/\/blogs.mathworks.com\/steve\/2007\/08\/07\/upslope-area-flow-matrix\/ \r\n% August 7th post> on upslope area, I showed how to construct and\r\n% solve the flow matrix to determine the upslope area for every pixel in a\r\n% digital elevation model (DEM).  In addition, the flow matrix can be used\r\n% to compute both the _influence map_ and the _dependence map_.\r\n%\r\n% The influence map shows where water starting from a particular pixel will\r\n% drain. The dependence map shows which uphill pixels drain through a\r\n% particular pixel.  Let's look at how to compute these from the flow\r\n% matrix.\r\n%\r\n% Recall the form of the flow equation for a particular pixel: The upslope\r\n% area of a pixel equals 1 plus a weighted fraction of the upslope area of\r\n% each of its neighbors.\r\n%\r\n% $$ A_j = 1 + w_1 A_{n_1} + w_2 A_{n_2} + \\ldots + w_8 A_{n_8} $$\r\n%\r\n% The 1 term comes from assuming each pixel contributes an equal volume to\r\n% the overall flow across the terrain.  Think of it as rain falling equally\r\n% on each pixel.  To compute the influence map, then, we just have to\r\n% modify our set of equations so that the 1 term appears only for the pixel\r\n% or pixels of interest.  Fortunately, that only affects the right-hand\r\n% side of the equation, not the flow matrix itself.  So solving for\r\n% the influence map a particular pixel looks almost like solving for\r\n% upslope area for all pixels.\r\n%\r\n% Here's an example from the Milford, Massachusetts DEM that I've used\r\n% before:\r\n% \r\n\r\ns = load('milford_ma_dem');\r\nE = s.Zc;\r\nimshow(E, [])\r\nlimits = [160 220 215 270];\r\naxis(limits);\r\nhold on\r\nplot(169, 227, '*')\r\nhold off\r\ntitle('Pixel near the top of Peppercorn Hill')\r\n\r\n%%\r\n% Find the flow directions and flow matrix using dem_flow and flow_matrix\r\n% from my <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=15818&objectType=FILE \r\n% upslope area toolbox> on MATLAB Central:\r\n\r\nR = dem_flow(E);\r\nT = flow_matrix(E, R);\r\n\r\n%%\r\n% Make a vector for the right-hand side that has a single 1 corresponding\r\n% to the (227,169) pixel:\r\n\r\n[M, N] = size(E);\r\nrhs = zeros(numel(E), 1);\r\nidx = (169-1)*M + 227;\r\nrhs(idx) = 1;\r\n\r\n%%\r\n% Solve for the influence map:\r\n\r\nI = T \\ rhs;\r\nI = reshape(I, M, N);\r\nimshow(I,[])\r\naxis(limits);\r\ntitle('Influence map')\r\n\r\n%%\r\n% The influence_map function does all this for you.  I also included a\r\n% visualization function (vis_map) that superimposes the influence (or\r\n% dependence) map transparently, in green, on top of the original DEM.  The\r\n% starting pixels are superimposed in blue.  Here's what it looks like for\r\n% our example:\r\n\r\nvis_map(I, E, 227, 169);\r\naxis(limits);\r\n\r\n%%\r\n% To compute the dependence map, you can't use the flow matrix exactly as\r\n% is; you have to transpose it. Otherwise, it's very similar to the\r\n% influence map computation.  See the code in dependence_map for the\r\n% details.\r\n%\r\n% Here's an example that computes the dependence map for an entire set of\r\n% pixels, not just a single pixel.  Specifically, it's the dependence map\r\n% for North Pond:\r\n\r\nplateaus = imerode(E, ones(3, 3)) == E;\r\npond = bwselect(plateaus, 183, 170);\r\nD = dependence_map(E, T, pond);\r\nvis_map(D, E, pond);\r\nxlim([110 240])\r\nylim([80 260])\r\n\r\n%%\r\n% Next time I plan to talk about vectorizing the pixel flow direction\r\n% calculation.\r\n\r\n##### SOURCE END ##### 9bd101fecdf84782abdeef3437846407\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   In my August 7th post on upslope area, I showed how to construct and solve the flow matrix to determine the upslope area for every pixel in a digital\r\n      elevation model (DEM).  In addition,... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2007\/10\/02\/upslope-area-influence-dependence-maps\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[50,418,90,246,36,362,68,170,190,52,360,298,130],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/159"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":3564,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/159\/revisions\/3564"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}