Changeset 1896 in lmdz_wrf
- Timestamp:
- Apr 6, 2018, 9:08:28 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic.py
r1757 r1896 39 39 # variables_values: Function to provide values to plot the different variables values from ASCII file 40 40 # wdismean: Function to compute the mean value weighted to its 4 distances 41 # WRFsetup: Function to check the set-up of a WRF model namelist or from any other model 42 41 43 # Character to split passed values 42 43 44 cS = ',' 44 # Character to split serie of values45 # Character to split a serie of values 45 46 cV = '@' 46 47 # Character for spaces … … 54 55 'rmNOnum', 'running_mean', \ 55 56 'significant_decomposition', 'squared_radial', \ 56 'table_tex_file', 'unitsDate', 'variables_values', 'wdismean' ]57 'table_tex_file', 'unitsDate', 'variables_values', 'wdismean', 'WRFsetup'] 57 58 58 59 hundredvals = '0' … … 81 82 ## e.g. # generic.py -o variables_values -S 'hus' 82 83 ## e.g. # generic.py -o wdismean -S 0.005@0.005,0.@1.@2.@3. 84 ## e.g. # python /home/lluis/PyNCplot/generic.py -o WRFsetup -S ../UBA/namelist.input,basic,textabrow 83 85 84 86 operationnames = "'" + gen.numVector_String(operations, "', '") + "'" … … 402 404 print gen.wdismean(vals0, vals1) 403 405 406 elif oper == 'WRFsetup': 407 Nvals = 3 408 vals = opts.values.split(cS) 409 if vals[0] == 'h': 410 print gen.WRFsetup.__doc__ 411 quit(-1) 412 else: 413 if len(vals) != Nvals: 414 print errormsg 415 print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ 416 len(vals), ' has passed!!' 417 print gen.WRFsetup.__doc__ 418 quit(-1) 419 vals0 = vals[0] 420 vals1 = vals[1] 421 vals2 = vals[2] 422 423 print gen.WRFsetup(vals0, vals1, vals2) 424 -
trunk/tools/generic_tools.py
r1893 r1896 153 153 # vals_around: Function to provide the 3x3 values around a given j,i point 154 154 # xtrm_nx: Function to provide the extreme (a percentage above min,max) of a series of values 155 # WRFsetup: Function to check the set-up of a WRF model namelist or from any other model 155 156 156 157 def searchInlist(listname, nameFind): … … 12817 12818 #print CFtime_freq(521438., 521439., 'hours since 1950-01-01_00:00:00') 12818 12819 12820 def WRFsetup(namelistn, params='basic', output='twopoints@'): 12821 """ Function to check the set-up of a WRF model namelist or from any other model 12822 namelistn= file name of the 'namelist.input' 12823 params= parameters to check 12824 'basic': a pre-determined list of basic parameters (default) 12825 'specific',[listparams]: a given ':' separated list of parameters to check 12826 output= kind of format of the output 12827 'textabcol': a LaTeX-table column formated 12828 'textabrow': a LaTeX-table row formated 12829 'twopoints@': as ':' separated list of values [attrn]@[attrv]:... (default) 12830 WRFsetup('namelist.input') 12831 """ 12832 fname = 'WRFsetup' 12833 availparams = ['basic', 'specific,[listparams]'] 12834 availoutput = ['textabcol', 'textabrow', 'twopoints@'] 12835 12836 if params == 'basic': 12837 lookparams = { \ 12838 'time_control': ['start_year', 'start_month', 'start_day', 'start_hour', \ 12839 'start_minute', 'start_second', 'end_year', 'end_month', 'end_day', \ 12840 'end_hour', 'end_minute', 'end_second', 'history_interval', \ 12841 'frames_per_outfile', 'restart', 'restart_interval_h'], \ 12842 'domains': ['time_step', 'max_dom', 'e_we', 'e_sn', 'e_vert', \ 12843 'p_top_requested', 'dx', 'dy', 'parent_grid_ratio', \ 12844 'parent_time_step_ratio', 'feedback'], \ 12845 'physics': ['mp_physics', 'ra_lw_physics', 'ra_sw_physics', 'radt', \ 12846 'sf_sfclay_physics', 'sf_surface_physics', 'bl_pbl_physics', 'bldt', \ 12847 'cu_physics', 'cudt', 'shcu_physics', 'sst_update'], \ 12848 'fdda': [], \ 12849 'dynamics': ['w_damping', 'diff_opt', 'km_opt', 'diff_6th_opt', \ 12850 'diff_6th_factor', 'damp_opt', 'zdamp', 'dampcoef', 'khdif', 'kvdif', \ 12851 'moist_adv_opt', 'scalar_adv_opt'], \ 12852 'bdy_control': ['spec_bdy_width', 'relax_zone'], \ 12853 'IFexist': ['eta_levels']} 12854 12855 secnames = ['time_control', 'domains', 'physics', 'fdda', 'dynamics', \ 12856 'bdy_control'] 12857 12858 elif params[0:8] == 'specific': 12859 secnames = ['specific'] 12860 lparns = params.split(',')[1].split(':') 12861 lpns = [] 12862 for lp in lparns: lpns.append(lp) 12863 lookparams = {'specific': lpns} 12864 else: 12865 print errormsg 12866 print ' ' + fname + ": parameters to check '" + params + "' not ready !!" 12867 print ' available ones:', availparams 12868 quit(-1) 12869 12870 onf = open(namelistn, 'r') 12871 fparams = {} 12872 pvals = '' 12873 for line in onf: 12874 if line[0:1] != '#' and len(line) > 1 and line.find('&') == -1 and \ 12875 line.find('/') == -1: 12876 if line.find('=') != -1: 12877 if len(pvals) != 0: 12878 fparams[paramn] = pvals 12879 ilvals = line.replace('\n', '').replace('\t','').split('=') 12880 paramn = ilvals[0].replace(' ','') 12881 pvals = ilvals[1].replace(' ','') 12882 else: 12883 ilvals = line.replace('\n', '').replace('\t','').replace(' ', '') 12884 pvals = pvals + ilvals 12885 12886 outl = '' 12887 ipar = 0 12888 for secn in secnames: 12889 print secn + "&" 12890 psec = lookparams[secn] 12891 for ps in psec: 12892 if not fparams.has_key(ps): 12893 print errormsg 12894 print ' ' + fname + ": provided namelist file '" + namelistn + \ 12895 "' has not parameter '" + ps + "' !!" 12896 quit(-1) 12897 12898 # output 12899 if output == 'textabcol': 12900 if ipar == 0: outl = ps.replace('_', '\\_') + ' & ' + \ 12901 fparams[ps].replace('_', '\\_') + ' \\\\' 12902 else: outl = outl + '\n' + ps.replace('_', '\\_') +' & '+ \ 12903 fparams[ps].replace('_', '\\_') + ' \\\\' 12904 elif output == 'textabrow': 12905 if ipar == 0: 12906 outl1 = '{\\bfseries{' + ps.replace('_', '\\_') + '}}' 12907 outl2 = fparams[ps].replace('_', '\\_') 12908 else: 12909 outl1 = outl1 + ' & {\\bfseries{' + ps.replace('_', '\\_') + '}}' 12910 outl2 = outl2 + ' & ' + fparams[ps].replace('_', '\\_') 12911 elif output == 'twopoints@': 12912 if ipar == 0: outl = ps + '@' + fparams[ps] 12913 else: outl = outl + ':' + ps + '@' + fparams[ps] 12914 else: 12915 print errormsg 12916 print ' ' + fname + ": kind of output '" + output + "' not ready !!" 12917 print ' available ones:', availoutput 12918 quit(-1) 12919 ipar=ipar+1 12920 12921 # Additional parameters (if they exist) 12922 if params == 'basic': 12923 psec = lookparams['IFexist'] 12924 for ps in psec: 12925 if fparams.has_key(ps): 12926 if output == 'textabcol': 12927 outl = outl + '\n' + ps.replace('_', '\\_') +' & '+ \ 12928 fparams[ps].replace('_', '\\_') + ' \\\\' 12929 elif output == 'textabrow': 12930 outl1 = outl1 + ' & {\\bfseries{' + ps.replace('_', '\\_') + '}}' 12931 outl2 = outl2 + ' & ' + fparams[ps].replace('_', '\\_') 12932 elif output == 'twopoints@': 12933 outl = outl + ':' + ps + '@' + fparams[ps] 12934 12935 if output == 'textabrow': 12936 outl = outl1 + ' \\\\\n' + outl2 12937 12938 return outl 12939 12940 #print WRFsetup('/home/lluis/estudios/RELAMPAGO/SimCoor/UBA/namelist.input', 'specific,start_year:end_year', 'textabcol') 12941 12819 12942 #quit() 12820 12943 12821 12944 12945
Note: See TracChangeset
for help on using the changeset viewer.