# dem_waters_extractor

committed 1daef48

finish testing lift

# demfunctions.py

` #-*- encoding:utf-8 -*-`
` `
` import math`
`+import copy`
` `
` def fill_sinks(data):`
`     r_max = len(data)`
`             if r == 0 or r == r_max-1 or c == 0 or c == c_max-1:`
`                 continue`
`             s0,s1,s2,s3,s4,s5,s6,s7 = [True for i in range(8)] # all the border is highter than this node`
`-            if r-1>0 and c+1<=c_max-1:`
`+            if r-1>=0 and c+1<=c_max-1:`
`                 s0 = data[r][c] <= data[r-1][c+1]`
`                 print 'x0'`
`                 print data[r-1][c+1]`
`                 s3 = data[r][c] <= data[r+1][c]`
`                 print 'x3'`
`                 print data[r+1][c]`
`-            if r+1<=r_max-1 and c-1>0:`
`+            if r+1<=r_max-1 and c-1>=0:`
`                 s4 = data[r][c] <= data[r+1][c-1]`
`                 print 'x4'`
`                 print data[r+1][c-1]`
`-            if c-1>0:`
`+            if c-1>=0:`
`                 s5 = data[r][c] <= data[r][c-1]`
`                 print 'x5'`
`                 print data[r][c-1]`
`-            if r-1>0 and c-1>0:`
`+            if r-1>=0 and c-1>=0:`
`                 s6 = data[r][c] <= data[r-1][c-1]`
`                 print 'x6'`
`                 print data[r-1][c-1]`
`-            if r-1>0:`
`+            if r-1>=0:`
`                 s7 = data[r][c] <= data[r-1][c]`
`                 print 'x7'`
`                 print data[r-1][c]`
`                 print '==================================='`
`                 print 'center point:r:%s,c:%s'%(r,c)`
`                 print '==================================='`
`-                len_ = 1`
`+                len_ = 0`
`                 marks = [[r,c]]`
`                 hidden_outset_min = None`
`                 border = []`
`                     print 'center point:r:%s,c:%s'%(r,c)`
`                     print 'len_:%s'%len_`
`                     print '___'`
`+                    len_ += 1`
`                     for i in range(len_+1):`
`                         if r+len_ <= r_max-1 and c+i <=c_max-1:`
`                             tem = [r+len_,c+i]`
`                             if tem not in border:`
`                                 border.append(tem)`
`                     print 'border:%s'%border`
`-                    if len(border) == 0:`
`+                    if len(border) < 8*len_:`
`                         print 'center node: %s.\n the end of dem for this center node.\n this node is assumed to be a biggggggg sink'%[r,c]`
`                         break`
`                     hidden_outset = []`
`                         # mark belonging to sink area`
`                         marks.append(node)`
`                     if len(hidden_outset) > 0:`
`-                        #enlarge window`
`                         print 'current hidden_outset number:%s'%len(hidden_outset)`
`                     else:`
`-                        len_ += 1`
`                         continue`
`                     hidden_outset_min = hidden_outset[0]`
`                     for node in (hidden_outset):`
`                     next_border_e = 0 # escape while loop`
`                     for node in border:`
`                         if data[node[0]][node[1]] < hidden_outset_min:`
`-                            len_ += 1`
`                             next_border_e = 1`
`                             break`
`                     if next_border_e == 0:`
`                                 data[node[0]][node[1]] = hidden_outset_min`
`                     else:`
`                         print "plane"`
`-                elif len(border) > 0:`
`-                    print 'sink on the border of the dem file'`
`-                else:`
`-                    print 'too large sink'`
`     return data`
` `
`-def lift(data,data_modified,p):`
`+def lift(data,p):`
`     r_max = len(data)`
`     c_max = len(data[0])`
`+    lifted = copy.deepcopy(data)`
`+    modified = False`
`     for r in xrange(len(data)):`
`         for c in xrange(len(data[r])):`
`-            s0,s1,s2,s3,s4,s5,s6,s7 = [True for i in range(8)] # all the border is highter than this node`
`-            if r-1>0 and c+1<=c_max-1:`
`+            if r == 0 or r == r_max-1 or c == 0 or c == c_max-1:`
`+                continue`
`+            s0,s1,s2,s3,s4,s5,s6,s7 = [True for i in range(8)] # all the border is highter than or equal to this node`
`+            if r-1>=0 and c+1<=c_max-1:`
`                 s0 = data[r][c] <= data[r-1][c+1]`
`             if c+1<=c_max-1:`
`                 s1 = data[r][c] <= data[r][c+1]`
`                 s2 = data[r][c] <= data[r+1][c+1]`
`             if r+1<=r_max-1:`
`                 s3 = data[r][c] <= data[r+1][c]`
`-            if r+1<=r_max-1 and c-1>0:`
`+            if r+1<=r_max-1 and c-1>=0:`
`                 s4 = data[r][c] <= data[r+1][c-1]`
`-            if c-1>0:`
`+            if c-1>=0:`
`                 s5 = data[r][c] <= data[r][c-1]`
`-            if r-1>0 and c-1>0:`
`+            if r-1>=0 and c-1>=0:`
`                 s6 = data[r][c] <= data[r-1][c-1]`
`-            if r-1>0:`
`+            if r-1>=0:`
`                 s7 = data[r][c] <= data[r-1][c]`
`-            if False not in [s0,s1,s2,s3,s4,s5,s6,s7]: # sink`
`-                data_modified[r][c] += p`
`+            if False not in [s0,s1,s2,s3,s4,s5,s6,s7]: # sink or plane`
`+                lifted[r][c] += p`
`+                modified = True`
`+    if modified == False:`
`+        return lifted`
`     print 'life return'`
`-    return data_modified`
`+    return lift(lifted,p)`
` `
` def get_vect_martrix(data,x,y):`
`     '''`

# test.py

`             [1,2,3,3,3,3,4,8,6],`
`             [1,1,2,3,3,4,5,7,8]]`
`     data_modified = fill_sinks(data)`
`-    return lift(data,data_modified,0.01)`
`+    return lift(data,0.1)`
` `
` print test_lift()`
` `
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.