Changeset 830 in lmdz_wrf for trunk/tools/generic_tools.py
- Timestamp:
- Jun 16, 2016, 11:11:04 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r829 r830 30 30 # ijlonlat: Function to provide the imin,jmin imax,jmax of a lon,lat box 31 31 # incomming_flow: Function to determine if a fgrid-flow inflows to the central grid point 32 # index_mat_way: Function to look for a value within a matrix following a sense32 # index_mat_way: Function to look for a value within a matrix following a direction 33 33 # num_chainSnum: Function to pass a value to a `ChainStrNum' number 34 34 # num_split: Function to split a string at each numeric value keeping the number as the last character of each cut … … 7062 7062 #quit() 7063 7063 7064 def subbasin_point(trips, pt ):7064 def subbasin_point(trips, pt, direction): 7065 7065 """ Function to provide sub-basins given a grid point following a matrix of trips 7066 7066 trips= matrix of trips values 7067 7067 1: N, 2: NE, 3: E, 4: SE, 5: S, 6: SW: 7: W, 8: NW 7068 7068 pt= point within the trip matrix 7069 direction= searching direction river-up ('left': clockwise, 'right': anti-clockwise) 7069 7070 """ 7070 7071 fname = 'subbasin_point' … … 7095 7096 Njipt = dictionary_key(subfinished, False) 7096 7097 if Njipt is not None: 7097 # print Njipt, 'points subflow:', ijsubflow[Njipt]7098 7098 for ipt in ijsubflow[Njipt]: 7099 7099 if ijfound[ipt] == False: 7100 7100 jipt = ijsubbasin[ipt] 7101 7101 break 7102 # print ' working from point:', ipt, 'ji pair:', jipt7103 7102 ijfound[ipt] = True 7104 7103 Nij = ipt 7105 7104 else: 7106 7105 # Keep searching since there are grid-points not found! 7107 # print ' ' + fname + ': Keep searching since there are grid-points not found!!'7108 # print ijfound7109 7106 Nij = dictionary_key(ijfound, False) 7110 7107 if Nij is None: … … 7115 7112 parentNjipt = dictionary_key_list(ijsubflow, Nij) 7116 7113 Njipt = chainSnum_levnext(parentNjipt, ijsubflow.keys()) 7117 # print ' ' + fname + "new sub-flow '" + Njipt + "' !!"7118 7114 subfinished[Njipt] = False 7119 7115 Nij = np.max(ijfound.keys()) 7120 7116 7121 # print 'Lluis Nij:', Nij7122 7117 # Looking for which point of the sub-flow retake the search 7123 7118 if Nij == 1: … … 7126 7121 7127 7122 ardtrips = vals_around(trips,jipt) 7128 # print ' ' + fname + 'ardtrips _______'7129 # print ardtrips7130 7123 7131 7124 arrive = incomming_flow(ardtrips) 7132 7125 Narrive = np.sum(arrive) 7133 # print Nij, ' ' + fname + ' Narrive:', Narrive7134 7126 if Narrive == 0: 7135 7127 ijfound[Nij] = True 7136 7128 subfinished[Njipt] = True 7137 7129 else: 7138 # print ' ' + fname + 'arrive _______'7139 # print arrive7140 7130 followvals = np.zeros((3,3), dtype=bool) 7141 7131 followvals = arrive … … 7143 7133 7144 7134 for ifollow in range(Narrive): 7145 # print 'ifollow:',ifollow,'/',Narrive7146 7135 7147 7136 # We only want to work with that ij, which have not yet been found 7148 7137 while np.sum(followvals) != 0: 7149 # print Nij,' Looking for a non-located point in subbasin ________' 7150 # print subbasin[jipt[0]-1:jipt[0]+2,jipt[1]-1:jipt[1]+2] 7151 jifollow = index_mat(followvals, True) 7152 jiequiv = jifollow - [1,1] 7138 7139 # Searching direction river-up. 'left': starting from the left, 'right' starting from the right 7140 if direction == 'left': 7141 jifollow = index_mat_way(followvals, True, 'clockwise6') 7142 elif direction == 'right': 7143 jifollow = index_mat_way(followvals, True, 'anticlockwise6') 7144 7145 jiequiv = jifollow[ifollow] - [1,1] 7153 7146 if subbasin[jipt[0]+jiequiv[0], jipt[1]+jiequiv[1]] == False: 7154 7147 Nij = np.max(ijfound.keys()) + 1 … … 7159 7152 Njipt = chainSnum_levnext(parentNjipt, ijsubflow.keys()) 7160 7153 else: 7154 # First subflow 7161 7155 Njipt = '11' 7162 7156 else: 7163 7157 Njipt = parentNjipt 7164 # print ' ' + fname + "new sub-flow '" + Njipt + "' !!"7165 7158 subfinished[Njipt] = False 7166 7159 subbasin[jipt[0]+jiequiv[0], jipt[1]+jiequiv[1]] = True … … 7179 7172 ijfound[Nij] = True 7180 7173 subfinished[Njipt] = True 7181 # print Nij," subflow '" + Njipt + "' finished!!"7182 7174 break 7183 7175 … … 7187 7179 'the number of trips', TOTtrips,'!!' 7188 7180 quit() 7189 7190 # if ijsubflow.has_key(Njipt):7191 # print "Lluis points of subflow: '" + Njipt + "' _______=", ijsubflow[Njipt]7192 # for isub in ijsubflow[Njipt]:7193 # print ' ' , isub , ':', ijsubbasin[isub], ijfound[isub]7194 # if Nij == 10: print 'Nij = 9:', ijfound[9]7195 7196 # print subbasin7197 # if Nij > 4: quit()7198 7181 7199 7182 return subbasin … … 7366 7349 7367 7350 def index_mat_way(mat,val,way): 7368 """ Function to look for a value within a matrix following a sense7351 """ Function to look for a value within a matrix following a way and direction 7369 7352 mat: matrix 7370 7353 val: value to search 7371 7354 way: way of search 7372 'anticlockwise12': looking in an anti-clockwise sens starting at 12 7373 'clockwise12': looking in an clockwise sens starting at 12 7355 'anticlockwise12': looking in an anti-clockwise direction starting at 12 7356 'anticlockwise6': looking in an anti-clockwise direction starting at 6 7357 'clockwise12': looking in an clockwise direction starting at 12 7358 'clockwise6': looking in an clockwise direction starting at 6 7374 7359 >>> mat = np.arange(20).reshape(4,5) 7375 7360 >>> mat[2,1] = 3 … … 7398 7383 if way == 'anticlockwise12': 7399 7384 # Sorting following a double criteria, first angle and then distance taken from the 7400 # center in the anti-clockwise sensstarting at 127385 # center in the anti-clockwise direction starting at 12 7401 7386 if Ndims > 2: 7402 7387 print errormsg … … 7429 7414 elif way == 'anticlockwise6': 7430 7415 # Sorting following a double criteria, first angle and then distance taken from the 7431 # center in the anti-clockwise sensstarting at 67416 # center in the anti-clockwise direction starting at 6 7432 7417 if Ndims > 2: 7433 7418 print errormsg … … 7460 7445 elif way == 'clockwise12': 7461 7446 # Sorting following a double criteria, first angle and then distance taken from the 7462 # center in the cloc-kwise sensstarting at 127447 # center in the cloc-kwise direction starting at 12 7463 7448 if Ndims > 2: 7464 7449 print errormsg … … 7489 7474 elif way == 'clockwise6': 7490 7475 # Sorting following a double criteria, first angle and then distance taken from the 7491 # center in the clockwise sensstarting at 67476 # center in the clockwise direction starting at 6 7492 7477 if Ndims > 2: 7493 7478 print errormsg … … 7532 7517 return indices 7533 7518 7534 mat = np.arange(20).reshape(4,5)7535 mat[2,1] = 37536 print index_mat_way(mat,3,'anticlockwise6')7537 7538 7519 #quit() 7539 7520
Note: See TracChangeset
for help on using the changeset viewer.