Changeset 2176 in lmdz_wrf for trunk/tools/generic_tools.py
- Timestamp:
- Oct 10, 2018, 4:20:23 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2172 r2176 84 84 # colhex_dec: Function to pas a hexadecimal (#[RR][GG][BB]; 00-64, 0A-FF) color to decimal ([0.,1.]) 85 85 # color_deg: Function to generate a degradation of colors in rgb base 86 # consecutive_list: Function to provide a list of consecutive values 86 87 # contflow: Function to bring back the increment in j,i grid points according to a trip: (inflow directions) 87 88 # create_LateX_figs: Function to create a LaTeX from a folder with multiple plots from different values … … 126 127 # latex_fig_array: Function to add an array of figures to an existing tex file 127 128 # latex_text: Function to transform a text to LaTeX following style rules 129 # Latin_Greek: Function to pass an ASCII latin character to its equivalent greek 128 130 # linearint_weights: Function to provide the weights for a linear interpolation of a value between a couple of values as a weighted distance mean 129 131 # linearint_3x3weights: Function to provide the weights for a linear interpolation of a value inside a 3x3 matrix of values as a weighted distance mean … … 11695 11697 raise TypeError, "expected integer, got %s" % type(input) 11696 11698 if not 0 < input < 4000: 11697 raise ValueError, "Argument must be between 1 and 3999" 11699 raise ValueError, "Argument must be between 1 and 3999" 11698 11700 ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1) 11699 11701 if romanchar == 'U': … … 14370 14372 # print islc, ':', itime, '-', etime, '<>', tvals, '=', tstat[islc] 14371 14373 14374 def Latin_Greek(char): 14375 """ Function to pass an ASCII latin character to its equivalent greek 14376 char: latin character to pass 14377 >>> Latin_Greek('a') 14378 $\alpha$ 14379 >>> Latin_Greek('z') 14380 $\omega$ 14381 """ 14382 fname = 'Latin_Greek' 14383 14384 greekequiv = {'a': '$\\alpha$', 'b': '$\\beta$', 'c': '$\\gamma$', \ 14385 'd': '$\\delta$', 'e': '$\\epsilon$', 'f': '$\\zeta$', 'g': '$\\eta$', \ 14386 'h': '$\\theta$', 'i': '$\\iota$', 'j': '$\\kappa$', 'k': '$\\lambda$', \ 14387 'l': '$\\mu$', 'm': '$\\nu $', 'n': '$\\xi$', 'o': '$\\omicron$', 'p': '$\\pi$',\ 14388 'q': '$\\(san)$', 'r': '$\\(koppa)$', 's': '$\\rho$', 't': '$\\sigma$', \ 14389 'u': '$\\tau$', 'v': '$\\upsilon$', 'w': '$\\phi$', 'x': '$\\chi$', \ 14390 'y': '$\\psi$', 'z': '$\\omega$'} 14391 14392 greek = greekequiv[char] 14393 14394 return greek 14395 14396 def consecutive_list(Nvals, kind): 14397 """ Function to provide a list of consecutive values 14398 Nvals: number of values 14399 kind: kind of values 14400 'ALPHA': list of consecutive characters upper case 14401 'alpha': list of consecutive characters lower case 14402 'greek': list of consecutive greek characters lower case (LaTeX) 14403 'numberF': list of consecutive float numbers 14404 'numberI': list of consecutive integer numbers 14405 'ROMAN': list of consecutive uppercase roman numbers 14406 'roman': list of consecutive lowercase roman numbers 14407 >>> consecutive_list(10, 'ALPHA') 14408 ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] 14409 >>> consecutive_list(10, 'alpha') 14410 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] 14411 >>> consecutive_list(10, 'greek') 14412 ['$\\alpha$', '$\\beta$', '$\\gamma$', '$\\delta$', '$\\epsilon$', '$\\zeta$', '$\\eta$', '$\\theta$', '$\\iota$', '$\\kappa$'] 14413 >>> consecutive_list(10, 'numberI') 14414 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 14415 >>> consecutive_list(10, 'roman') 14416 ['i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x'] 14417 """ 14418 fname = 'consecutive_list' 14419 14420 availkind = ['ALPHA', 'alpha', 'greek', 'numberF', 'numberI', 'ROMAN', 'roman'] 14421 14422 if kind == 'ALPHA': 14423 vals = [] 14424 for ic in range(Nvals): 14425 vals.append(chr(65+ic)) 14426 elif kind == 'alpha': 14427 vals = [] 14428 for ic in range(Nvals): 14429 vals.append(chr(97+ic)) 14430 elif kind == 'greek': 14431 vals = [] 14432 for ic in range(Nvals): 14433 vals.append(Latin_Greek(chr(97+ic))) 14434 elif kind == 'numberF': 14435 vals = list(np.arange(Nvals, drype=np.float)) 14436 elif kind == 'numberI': 14437 vals = range(Nvals) 14438 elif kind == 'ROMAN': 14439 vals = [] 14440 for ic in range(Nvals): 14441 vals.append(int_to_roman(ic+1, 'U')) 14442 elif kind == 'roman': 14443 vals = [] 14444 for ic in range(Nvals): 14445 vals.append(int_to_roman(ic+1, 'l')) 14446 else: 14447 print errormsg 14448 print ' ' + fname + ": kind '" + kind + "' not ready !!" 14449 print ' avaiable ones:', availkind 14450 quit(-1) 14451 14452 return vals 14453 14372 14454 #quit() 14373 14455 14456
Note: See TracChangeset
for help on using the changeset viewer.