Changeset 479 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 12, 2015, 11:42:21 AM (10 years ago)
Author:
lfita
Message:

Adding `low/upthres@oper' on 'valmod' tomake an operation according to thresholds

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r469 r479  
    870870          lowthres: if [val] < [modval1]; val = [modval2]
    871871          upthres: if [val] > [modval1]; val = [modval2]
     872          lowthres@oper: if [val] < [modval1]; val = [oper] (operation as [modval2],[modval3])
     873          upthres@oper: if [val] > [modval1]; val = [oper] (operation as [modval2],[modval3])
    872874          potc: [val] ** [modval1]
    873875    """
     
    897899        varVal2 = np.where(varVal[:] > float(valsS[1]), float(valsS[2]), varVal[:])
    898900        varVal[:] = varVal2
     901    elif modins == 'lowthres@oper':
     902        if valS[2] == 'sumc': varVal2 = np.where(varVal[:] < float(valsS[1]),        \
     903           varVal[:] + float(valsS[2]), varVal[:])
     904        elif valS[2] == 'subc': varVal2 = np.where(varVal[:] < float(valsS[1]),      \
     905           varVal[:] - float(valsS[2]), varVal[:])
     906        elif valS[2] == 'mulc': varVal2 = np.where(varVal[:] < float(valsS[1]),      \
     907           varVal[:] * float(valsS[2]), varVal[:])
     908        elif valS[2] == 'divc': varVal2 = np.where(varVal[:] < float(valsS[1]),      \
     909           varVal[:] / float(valsS[2]), varVal[:])
     910        elif valS[2] == 'potc': varVal2 = np.where(varVal[:] < float(valsS[1]),      \
     911           varVal[:] ** float(valsS[2]), varVal[:])
     912        else:
     913            print errormsg
     914            print '  ' + fname + ": Operation to modify values '" + modins +         \
     915              "' is not defined !!'
     916            quit(-1)
     917    elif modins == 'upthres@oper':
     918        if valS[2] == 'sumc': varVal2 = np.where(varVal[:] > float(valsS[1]),        \
     919           varVal[:] + float(valsS[2]), varVal[:])
     920        elif valS[2] == 'subc': varVal2 = np.where(varVal[:] > float(valsS[1]),      \
     921           varVal[:] - float(valsS[2]), varVal[:])
     922        elif valS[2] == 'mulc': varVal2 = np.where(varVal[:] > float(valsS[1]),      \
     923           varVal[:] * float(valsS[2]), varVal[:])
     924        elif valS[2] == 'divc': varVal2 = np.where(varVal[:] > float(valsS[1]),      \
     925           varVal[:] / float(valsS[2]), varVal[:])
     926        elif valS[2] == 'potc': varVal2 = np.where(varVal[:] > float(valsS[1]),      \
     927           varVal[:] ** float(valsS[2]), varVal[:])
     928        else:
     929            print errormsg
     930            print '  ' + fname + ": Operation to modify values '" + modins +         \
     931              "' is not defined !!'
     932            quit(-1)
    899933    elif modins == 'potc':
    900934        varVal[:] = varVal[:] ** modval
    901935    else:
    902936        print errormsg
    903         print '  valmodoper: Operation to modify values ' + modins + ' is not defined !!!'
    904         print errormsg
     937        print '  ' + fname + ": Operation to modify values '" + modins +             \
     938          "' is not defined !!'
    905939        quit(-1)
    906940
Note: See TracChangeset for help on using the changeset viewer.