Commits

luoboiqingcai committed a2ee1b4

add logging.info

Comments (0)

Files changed (1)

 Any suggestin is welcome
 TODO: promote the performance using parallel mehod such as threading.
 '''
+
 __authoer__ = 'luoboiqingcai'
 __contact__ = 'sf.cumt@gmail.com'
 __licence__ = 'MIT'
 import logging
 
 logger = logging.getLogger()
-logger.setLevel(logging.WARNING)
+logger.setLevel(logging.INFO)
+logger.addHandler(logging.StreamHandler())
+
 
 def fill_sinks(data):
     '''
     find and fill the sinks
     '''
+    logger.info('filling sinks')
     r_max = len(data)
     c_max = len(data[0])
     for r in xrange(len(data)):
         for c in xrange(len(data[r])):
+            logger.info('current node is:%s'%[r,c])
             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
     '''
     lift plane which includes plane as the result of filling the sinks and the original plane
     '''
+    logger.info('lift sinks or plane nodes')
     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])):
+            logger.info('currentnode:%s'%[r,c])
             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
     x: x distance of each node on column
     y: y distance of each node on row
     '''
+    logger.info('get vect matrix')
     r_max = len(data) # exactly len(data) - 1
     c_max = len(data[0]) # exactly len(data[0]) - 1
     vect_matrix = [[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])):
+            logger.info('current node:%s'%[r,c])
             if r == 0:
                 vect_matrix[r][c] = 7
                 continue
     Given a node location this function will return a list reprenting the water flow from this node to to the end of dem file.
     data: vect_matrix
     '''
+    logger.info('tracking path, the first node is %s'%[r,c])
     if r > r_ax-1 or r < 0 or c>c_ax-1 or c < 0:
         return []
     #if r>5 or r<0 or c>5 or c<0:
     return catchment area of each node in the matrix
     data: vect_matrix
     '''
+    logger.info('count water')
     r_max = len(data) # exactly len(data) - 1
     c_max = len(data[0]) # exactly len(data[0]) - 1
     water_matrix = [[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)):
+            logger.info('current node:%s'%[r,c])
             path = trackpath(data,r,c,r_max,c_max)
             for node in path:
                 water_matrix[node[0]][node[1]] += 1
     '''
     return the bitmap in which 1 means catchment area of this node is larger than threshold and can be considered along the river
     '''
+    logger.info('generating river map')
     r_max = len(data) # exactly len(data) - 1
     c_max = len(data[0]) # exactly len(data[0]) - 1
     rivermap_matrix = [[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])):
+            logger.info('current node:%s'%[r,c])
             if data[r][c] >=threshold:
                 rivermap_matrix[r][c] = 1
     return rivermap_matrix
     '''
     get river paths
     '''
+    logger.info('generate river paths')
     paths = []
     cross_sections = []
     r_max = len(river_map_matrix) # exactly len(data) - 1
     c_max = len(river_map_matrix[0]) # exactly len(data[0]) - 1
     for r in xrange(len(river_map_matrix)):
         for c in xrange(len(river_map_matrix[r])):
+            logger.info('current node:%s'%[r,c])
             if river_map_matrix[r][c]: # node in the river
                 input_nodes = []
                 if r-1 >=0 and c+1 <= c_max-1:
     '''
     determine the water grade on the basis of paths generated from river_paths function
     '''
+    logger.info('generate water grad')
     grads = [[0 for i in range(c_max)] for j in range(r_max)]
     for x in range(len(paths)):
         current_grad = 1