Commits

luoboiqingcai committed cf10ec3

finish testing get_vect_martix

  • Participants
  • Parent commits 1daef48

Comments (0)

Files changed (2)

File demfunctions.py

     vect_martix = [[0 for c in range(c_max)] for r in range(r_max)]
     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 == 0:
+                vect_martix[r][c] = 7
+                continue
+            if r == r_max-1:
+                vect_martix[r][c] = 3
+                continue
+            if c == 0:
+                vect_martix[r][c] = 5
+                continue
+            if c == c_max-1:
+                vect_martix[r][c] = 1
+                continue
             v0,v1,v2,v3,v4,v5,v6,v7 = [0 for i in range(8)]
-            if r-1>0 and c+1<=c_max-1:
-                s0 = data[r][c] <= data[r-1][c+1]
+            if r-1>=0 and c+1<=c_max-1:
                 v0 = (data[r][c]-data[r-1][c+1])/math.pow(x**2+y**2,0.5)
             if c+1<=c_max-1:
-                s1 = data[r][c] <= data[r][c+1]
                 v1 = (data[r][c]-data[r][c+1])/x
             if r+1<=r_max-1 and c+1<=c_max-1:
-                s2 = data[r][c] <= data[r+1][c+1]
                 v2 = (data[r][c]-data[r+1][c+1])/math.pow(x**2+y**2,0.5)
             if r+1<=r_max-1:
-                s3 = data[r][c] <= data[r+1][c]
                 v3 = (data[r][c]-data[r+1][c])/y
             if r+1<=r_max-1 and c-1>0:
-                s4 = data[r][c] <= data[r+1][c-1]
                 v4 = (data[r][c]-data[r+1][c-1])/math.pow(x**2+y**2,0.5)
-            if c-1>0:
-                s5 = data[r][c] <= data[r][c-1]
+            if c-1>=0:
                 v5 = (data[r][c]-data[r][c-1])/x
-            if r-1>0 and c-1>0:
-                s6 = data[r][c] <= data[r-1][c-1]
+            if r-1>=0 and c-1>=0:
                 v6 = (data[r][c]-data[r-1][c-1])/math.pow(x**2+y**2,0.5)
-            if r-1>0:
-                s7 = data[r][c] <= data[r-1][c]
+            if r-1>=0:
                 v7 = (data[r][c]-data[r-1][c])/y
-            if False not in [s0,s1,s2,s3,s4,s5,s6,s7]: # sink
-                pass
             which = 0
             v_max = max([v0,v1,v2,v3,v4,v5,v6,v7])
+            print 'v_max:%s'%v_max
             for i in [v0,v1,v2,v3,v4,v5,v6,v7]:
                 if v_max == i:
                     break
 #
 #print test_fill_sinks()
 
-def test_lift():
+#def test_lift():
+#    data = [[1,1,3,4,5,5,7,5,4],
+#            [1,2,4,4,4,4,6,5,3],
+#            [4,4,3,4,3,3,6,7,5],
+#            [3,3,2,3,2,2,4,6,7],
+#            [1,2,2,2,1,2,3,4,5],
+#            [3,3,2,1,1,2,3,6,6],
+#            [2,3,3,1,1,2,5,7,8],
+#            [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_modified,0.1)
+#
+#print test_lift()
+
+def test_get_vect_martrix():
     data = [[1,1,3,4,5,5,7,5,4],
             [1,2,4,4,4,4,6,5,3],
             [4,4,3,4,3,3,6,7,5],
             [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,0.1)
+    data_lifted = lift(data_modified,1e-5)
+    return get_vect_martrix(data_lifted,1,1)
 
-print test_lift()
-
-#def test_get_vect_martrix():
-#    data = [[1,1,3,4,5,5,7,5,4],
-#            [1,2,4,4,4,4,6,5,3],
-#            [4,4,3,4,3,3,6,7,5],
-#            [3,3,2,3,2,2,4,6,7],
-#            [1,2,2,2,1,2,3,4,5],
-#            [3,3,2,1,1,2,3,6,6],
-#            [2,3,3,1,1,2,5,7,8],
-#            [1,2,3,3,3,3,4,8,6],
-#            [1,1,2,3,3,4,5,7,8]]
-#    data_modified = fill_sinks(data)
-#    data_lifted = lift(data,data_modified,1e-5)
-#    return get_vect_martrix(data_lifted,1,1)
-#
-#print test_get_vect_martrix()
+print test_get_vect_martrix()
 
 #def test_count_water():
 #    data = [[1,1,3,4,5,5,7,5,4],