Changeset 830 in lmdz_wrf for trunk/tools/generic_tools.py


Ignore:
Timestamp:
Jun 16, 2016, 11:11:04 AM (9 years ago)
Author:
lfita
Message:

Cleaning spurious useless comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r829 r830  
    3030# ijlonlat: Function to provide the imin,jmin imax,jmax of a lon,lat box
    3131# 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 sense
     32# index_mat_way: Function to look for a value within a matrix following a direction
    3333# num_chainSnum: Function to pass a value to a `ChainStrNum' number
    3434# num_split: Function to split a string at each numeric value keeping the number as the last character of each cut
     
    70627062#quit()
    70637063
    7064 def subbasin_point(trips, pt):
     7064def subbasin_point(trips, pt, direction):
    70657065    """ Function to provide sub-basins given a grid point following a matrix of trips
    70667066      trips= matrix of trips values
    70677067        1: N,  2: NE,  3: E,  4: SE,  5: S,  6: SW:  7: W,  8: NW
    70687068      pt= point within the trip matrix
     7069      direction= searching direction river-up ('left': clockwise, 'right': anti-clockwise)
    70697070    """
    70707071    fname = 'subbasin_point'
     
    70957096        Njipt = dictionary_key(subfinished, False)
    70967097        if Njipt is not None:
    7097 #            print Njipt, 'points subflow:', ijsubflow[Njipt]
    70987098            for ipt in ijsubflow[Njipt]:
    70997099                if ijfound[ipt] == False:
    71007100                    jipt = ijsubbasin[ipt]
    71017101                    break
    7102 #            print '  working from point:', ipt, 'ji pair:', jipt
    71037102            ijfound[ipt] = True
    71047103            Nij = ipt
    71057104        else:
    71067105# Keep searching since there are grid-points not found!
    7107 #            print '  ' + fname + ': Keep searching since there are grid-points not found!!'
    7108 #            print ijfound
    71097106            Nij = dictionary_key(ijfound, False)
    71107107            if Nij is None:
     
    71157112            parentNjipt = dictionary_key_list(ijsubflow, Nij)
    71167113            Njipt = chainSnum_levnext(parentNjipt, ijsubflow.keys())
    7117 #            print '  ' + fname + "new sub-flow '" + Njipt + "' !!"
    71187114            subfinished[Njipt] = False
    71197115            Nij = np.max(ijfound.keys())
    71207116
    7121 #        print 'Lluis Nij:', Nij
    71227117# Looking for which point of the sub-flow retake the search
    71237118        if Nij == 1:
     
    71267121
    71277122        ardtrips = vals_around(trips,jipt)
    7128 #        print '  ' + fname + 'ardtrips _______'
    7129 #        print ardtrips
    71307123
    71317124        arrive = incomming_flow(ardtrips)
    71327125        Narrive = np.sum(arrive)
    7133 #        print Nij, '  ' + fname + ' Narrive:', Narrive
    71347126        if Narrive == 0:
    71357127            ijfound[Nij] = True
    71367128            subfinished[Njipt] = True
    71377129        else:
    7138 #            print '  ' + fname + 'arrive _______'
    7139 #            print arrive
    71407130            followvals = np.zeros((3,3), dtype=bool)
    71417131            followvals = arrive
     
    71437133
    71447134            for ifollow in range(Narrive):
    7145 #                print 'ifollow:',ifollow,'/',Narrive
    71467135
    71477136# We only want to work with that ij, which have not yet been found
    71487137                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]
    71537146                    if subbasin[jipt[0]+jiequiv[0], jipt[1]+jiequiv[1]] == False:
    71547147                        Nij = np.max(ijfound.keys()) + 1
     
    71597152                                Njipt = chainSnum_levnext(parentNjipt, ijsubflow.keys())
    71607153                            else:
     7154                                # First subflow
    71617155                                Njipt = '11'
    71627156                        else:
    71637157                            Njipt = parentNjipt
    7164 #                        print '  ' + fname + "new sub-flow '" + Njipt + "' !!"
    71657158                        subfinished[Njipt] = False
    71667159                        subbasin[jipt[0]+jiequiv[0], jipt[1]+jiequiv[1]] = True
     
    71797172                            ijfound[Nij] = True
    71807173                            subfinished[Njipt] = True
    7181 #                            print Nij,"  subflow '" + Njipt + "' finished!!"
    71827174                            break
    71837175
     
    71877179                      'the number of trips', TOTtrips,'!!'
    71887180                    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 subbasin
    7197 #        if Nij > 4: quit()
    71987181
    71997182    return subbasin
     
    73667349
    73677350def index_mat_way(mat,val,way):
    7368     """ Function to look for a value within a matrix following a sense
     7351    """ Function to look for a value within a matrix following a way and direction
    73697352      mat: matrix
    73707353      val: value to search
    73717354      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
    73747359    >>> mat = np.arange(20).reshape(4,5)
    73757360    >>> mat[2,1] = 3
     
    73987383    if way == 'anticlockwise12':
    73997384# Sorting following a double criteria, first angle and then distance taken from the
    7400 #   center in the anti-clockwise sens starting at 12
     7385#   center in the anti-clockwise direction starting at 12
    74017386        if Ndims > 2:
    74027387            print errormsg
     
    74297414    elif way == 'anticlockwise6':
    74307415# Sorting following a double criteria, first angle and then distance taken from the
    7431 #   center in the anti-clockwise sens starting at 6
     7416#   center in the anti-clockwise direction starting at 6
    74327417        if Ndims > 2:
    74337418            print errormsg
     
    74607445    elif way == 'clockwise12':
    74617446# Sorting following a double criteria, first angle and then distance taken from the
    7462 #   center in the cloc-kwise sens starting at 12
     7447#   center in the cloc-kwise direction starting at 12
    74637448        if Ndims > 2:
    74647449            print errormsg
     
    74897474    elif way == 'clockwise6':
    74907475# Sorting following a double criteria, first angle and then distance taken from the
    7491 #   center in the clockwise sens starting at 6
     7476#   center in the clockwise direction starting at 6
    74927477        if Ndims > 2:
    74937478            print errormsg
     
    75327517    return indices
    75337518
    7534 mat = np.arange(20).reshape(4,5)
    7535 mat[2,1] = 3
    7536 print index_mat_way(mat,3,'anticlockwise6')
    7537 
    75387519#quit()
    75397520
Note: See TracChangeset for help on using the changeset viewer.