Changeset 805 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 3, 2016, 9:23:18 AM (9 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic.py
r803 r805 15 15 # Character to split passed values 16 16 cS = ',' 17 # Character to split serie of values 18 cV = '@' 17 19 # List of available operations 18 operations=['unitsDate'] 20 operations=['grid_combinations', 'PolyArea', 'rmNOnum', \ 21 'significant_decomposition', 'squared_radial', \ 22 'unitsDate'] 19 23 24 ## e.g. # generic.py -o grid_combinations -S 1,2 25 ## e.g. # generic.py -o PolyArea -S -0.5@0.5@0.5@-0.5,0.5@0.5@-0.5@-0.5 26 ## e.g. # generic.py -o rmNOnum -S LMD123IPSL 27 ## e.g. # generic.py -o significant_decomposition -S 3.576,-2 20 28 ## e.g. # generic.py -o secondsDate -S '19490101000000,19760217082932,second' 29 ## e.g. # generic.py -o squared_radial -S 3 21 30 22 31 operationnames = "'" + gen.numVector_String(operations, "', '") + "'" 32 valuesinf = "'" + cS + "' list of values to use according to the operation ('" + cV +\ 33 "' for list of values)" 23 34 24 35 parser = OptionParser() … … 26 37 choices=operations, help="operation to make: " + operationnames, metavar="OPER") 27 38 parser.add_option("-S", "--valueS (when applicable)", dest="values", 28 help= "'" + cS + "' list of values to use according to the operation", metavar="VALUES")39 help=valuesinf, metavar="VALUES") 29 40 (opts, args) = parser.parse_args() 30 41 … … 41 52 print opern + '_______ ______ _____ ____ ___ __ _' 42 53 print getattr(object, opern).__doc__ 54 55 elif oper == 'grid_combinations': 56 Nvals = 2 57 vals = opts.values.split(cS) 58 if vals[0] == 'h': 59 print gen.grid_combinations.__doc__ 60 quit(-1) 61 else: 62 if len(vals) != Nvals: 63 print errormsg 64 print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ 65 len(vals), ' has passed!!' 66 print gen.grid_combinations.__doc__ 67 quit(-1) 68 69 print gen.grid_combinations(np.int(vals[0]), np.int(vals[1])) 70 71 elif oper == 'PolyArea': 72 Nvals = 2 73 vals = opts.values.split(cS) 74 if vals[0] == 'h': 75 print gen.PolyArea.__doc__ 76 quit(-1) 77 else: 78 if len(vals) != Nvals: 79 print errormsg 80 print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ 81 len(vals), ' has passed!!' 82 print gen.PolyArea.__doc__ 83 quit(-1) 84 xvals = np.array(vals[0].split(cV), dtype=np.float) 85 yvals = np.array(vals[1].split(cV), dtype=np.float) 86 87 print gen.PolyArea(xvals, yvals) 88 89 elif oper == 'rmNOnum': 90 Nvals = 1 91 vals = opts.values.split(cS) 92 if vals[0] == 'h': 93 print gen.rmNOnum.__doc__ 94 quit(-1) 95 else: 96 if len(vals) != Nvals: 97 print errormsg 98 print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ 99 len(vals), ' has passed!!' 100 print gen.rmNOnum.__doc__ 101 quit(-1) 102 print gen.rmNOnum(vals[0]) 103 104 elif oper == 'significant_decomposition': 105 Nvals = 2 106 vals = opts.values.split(cS) 107 if vals[0] == 'h': 108 print gen.significant_decomposition.__doc__ 109 quit(-1) 110 else: 111 if len(vals) != Nvals: 112 print errormsg 113 print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ 114 len(vals), ' has passed!!' 115 print gen.significant_decomposition.__doc__ 116 quit(-1) 117 print gen.significant_decomposition(np.float(vals[0]), int(vals[1])) 118 119 elif oper == 'squared_radial': 120 Nvals = 1 121 vals = opts.values.split(cS) 122 if vals[0] == 'h': 123 print gen.squared_radial.__doc__ 124 quit(-1) 125 else: 126 if len(vals) != Nvals: 127 print errormsg 128 print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ 129 len(vals), ' has passed!!' 130 print gen.squared_radial.__doc__ 131 quit(-1) 132 print gen.squared_radial(int(vals[0])) 133 43 134 elif oper == 'unitsDate': 44 135 Nvals = 3 … … 48 139 quit(-1) 49 140 else: 50 if len(vals) != Nvals and vals[0] != 'h':141 if len(vals) != Nvals: 51 142 print errormsg 52 143 print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ -
trunk/tools/generic_tools.py
r804 r805 5677 5677 """ 5678 5678 fname = 'squared_radial' 5679 if Npt == 'h': 5680 print fname + '_____________________________________________________________' 5681 print squared_radial.__doc__ 5682 quit() 5679 5683 5680 5684 radii = [] … … 5744 5748 """ 5745 5749 fname = 'fillvalue_kind' 5750 if vartype == 'h': 5751 print fname + '_____________________________________________________________' 5752 print fillvalue_kind.__doc__ 5753 quit() 5746 5754 5747 5755 if vartype == type('c'): … … 6267 6275 1.0 6268 6276 """ 6277 fname = 'PolyArea' 6278 6269 6279 return 0.5*np.abs(np.dot(x,np.roll(y,1))-np.dot(y,np.roll(x,1))) 6270 6280 … … 6349 6359 while diff > 0.: 6350 6360 pot = np.floor(np.log10(diff)) 6361 if pot < minpot: break 6351 6362 potv = np.int(diff/(10.**pot)) 6352 6363 # print 'Lluis:',np.log10(diff), pot,':',10.**pot,':',diff/(10.**pot),'.',potv,'.',potv*10.**pot,diff … … 6354 6365 potencies.append(pot) 6355 6366 potval.append(potv) 6356 if pot < -minpot: break6357 6367 iipot = iipot + 1 6358 6368 … … 6371 6381 import datetime as dt 6372 6382 fname = 'unitsDate' 6373 6374 if refdate == 'h':6375 print fname + '_____________________________________________________________'6376 print unitsDate.__doc__6377 quit()6378 6383 6379 6384 yrref=int(refdate[0:4])
Note: See TracChangeset
for help on using the changeset viewer.