Changeset 1520 in lmdz_wrf


Ignore:
Timestamp:
Apr 12, 2017, 12:58:12 AM (8 years ago)
Author:
lfita
Message:

Adding to `matoperations': 'repl', 'replbig', 'repless'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1513 r1520  
    1016610166        'pot': powering with matB (matA ** matB)
    1016710167        'potc',[modval1]: [val] ** [modval1]
     10168        'repl',[modval1]: replace values of matA with values from matB except matB = [modval1]
     10169        'replbig',[modval1]: replace values of matA with values from matB except matB > [modval1]
     10170        'repless',[modval1]: replace values of matA with values from matB except matB < [modval1]
    1016810171        'sub': substracting matB to matA (matA - matB)
    1016910172        'subc',[modval1]: remove [modval1]
     
    1029310296    Lopn = {'add': '+', 'addc': '+', 'div': '/', 'divc': '/', 'inv': '^(-1)',        \
    1029410297      'lowthres': '<', 'mul': '*', 'mulc': '*', 'pot': '^', 'potc': '^',             \
    10295       'sub': '-', 'subc': '-', 'upthres': '<'}
     10298      'repl': 'repl_excpt', 'replbig': 'repl_excpt_bigger',                          \
     10299      'repless': 'repl_excpt_less', 'sub': '-', 'subc': '-', 'upthres': '<'}
     10300    # Operations by constant value
    1029610301    Lopnc = {'addc': '+', 'divc': '/', 'inv': '^{-1)', 'mulc': '*', 'potc': '^',     \
    10297       'subc': '-'}
    10298 
     10302      'repl': 'repl_excpt', 'replbig': 'repl_excpt_bigger',                          \
     10303      'repless': 'repl_excpt_less', 'subc': '-'}
     10304
     10305    # Available operations
    1029910306    opavail = ['add', 'addc', 'centerderiv', 'div', 'divc', 'forwrdderiv', 'inv',    \
    10300       'lowthres', 'lowthres@oper', 'mul', 'mulc', 'pot', 'potc', 'sub', 'subc',      \
    10301       'upthres', 'upthres@oper']
     10307      'lowthres', 'lowthres@oper', 'mul', 'mulc', 'pot', 'potc', 'repl', 'replbig',  \
     10308      'repless', 'sub', 'subc', 'upthres', 'upthres@oper']
    1030210309    opavailc = ['addc', 'divc', 'inv', 'mulc', 'potc', 'subc']
    1030310310
     
    1038710394        value1 = retype(opN.split(',')[1], valtype)
    1038810395        Lopn['potc'] = '^' + str(value1)         
     10396    elif opN[0:4] == 'repl' and opN.split(',')[0] == 'repl':
     10397        opn = 'repl'
     10398        value1 = retype(opN.split(',')[1], valtype)
     10399        Lopn['repl'] = 'repl_excpt(' + str(value1) + ')'
     10400    elif opN[0:7] == 'replbig':
     10401        opn = 'replbig'
     10402        value1 = retype(opN.split(',')[1], valtype)
     10403        Lopn['replbig'] = 'repl_excpt(<' + str(value1) + ')'
     10404    elif opN[0:7] == 'repless':
     10405        opn = 'repless'
     10406        value1 = retype(opN.split(',')[1], valtype)
     10407        Lopn['repless'] = 'repl_excpt(>' + str(value1) + ')'
    1038910408    elif opN[0:4] == 'subc':
    1039010409        opn = 'subc'
     
    1058710606    elif opn == 'potc':
    1058810607        newmat = matA ** value1
     10608    elif opn == 'repl':
     10609        newmat = np.where(matB == value1, matA, matB)
     10610    elif opn == 'replbig':
     10611        newmat = np.where(matB > value1, matA, matB)
     10612    elif opn == 'repless':
     10613        newmat = np.where(matB < value1, matA, matB)
    1058910614    elif opn == 'sub':
    1059010615        newmat = matA - matB
Note: See TracChangeset for help on using the changeset viewer.