Changeset 1351 in lmdz_wrf
- Timestamp:
- Nov 22, 2016, 5:23:21 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/diagnostics.py
r1163 r1351 867 867 parser.add_option("-f", "--netCDF_file", dest="ncfile", help="file to use", metavar="FILE") 868 868 parser.add_option("-d", "--dimensions", dest="dimns", 869 help="[dimtn]@[dtvn],[dimzn]@[dzvn],[...,[dimxn]@[dxvn]], ',' list with the couples [dimDn]@[dDvn], [dimDn], name of the dimension D and name of the variable [dDvn] with the values of the dimension " + comboinf,869 help="[dimtn]@[dtvn],[dimzn]@[dzvn],[...,[dimxn]@[dxvn]], ',' list with the couples [dimDn]@[dDvn], [dimDn], name of the dimension D and name of the variable [dDvn] with the values of the dimension ('WRFtime', for WRF time copmutation)" + comboinf, 870 870 metavar="LABELS") 871 871 parser.add_option("-v", "--variables", dest="varns", … … 878 878 ####### 879 879 availdiags = ['ACRAINTOT', 'accum', 'clt', 'cllmh', 'deaccum', 'LMDZrh', 'mslp', \ 880 'OMEGAw', 'RAINTOT', \880 'OMEGAw', 'RAINTOT', \ 881 881 'rvors', 'td', 'turbulence', 'WRFgeop', 'WRFp', 'WRFrvors', 'ws', 'wds', 'wss', \ 882 882 'WRFheight', 'WRFua', 'WRFva'] … … 890 890 'WRFpos', 'WRFprc', 'WRFprls', 'WRFrh', 'LMDZrh', 'LMDZrhs', 'WRFrhs', 'WRFrvors', \ 891 891 'WRFt', 'WRFtime', 'WRFua', 'WRFva', 'WRFwds', 'WRFwss', 'WRFheight'] 892 893 NONchkvardims = ['WRFtime'] 892 894 893 895 ofile = 'diagnostics.nc' … … 911 913 912 914 ncobj = NetCDFFile(opts.ncfile, 'r') 913 914 # File creation915 newnc = NetCDFFile(ofile,'w')916 917 # dimensions918 dimvalues = dimns.split(',')919 dnames = []920 dvnames = []921 922 for dimval in dimvalues:923 dnames.append(dimval.split('@')[0])924 dvnames.append(dimval.split('@')[1])925 926 # diagnostics to compute927 diags = varns.split(',')928 Ndiags = len(diags)929 915 930 916 # Looking for specific variables that might be use in more than one diagnostic … … 937 923 WRFpos_compute = False 938 924 WRFtime_compute = False 925 926 # File creation 927 newnc = NetCDFFile(ofile,'w') 928 929 # dimensions 930 dimvalues = dimns.split(',') 931 dnames = [] 932 dvnames = [] 933 934 for dimval in dimvalues: 935 dn = dimval.split('@')[0] 936 dnv = dimval.split('@')[1] 937 dnames.append(dn) 938 dvnames.append(dnv) 939 # Is there any dimension-variable which should be computed? 940 if dnv == 'WRFgeop':WRFgeop_compute = True 941 if dnv == 'WRFp': WRFp_compute = True 942 if dnv == 'WRFt': WRFt_compute = True 943 if dnv == 'WRFrh': WRFrh_compute = True 944 if dnv == 'WRFght': WRFght_compute = True 945 if dnv == 'WRFdens': WRFdens_compute = True 946 if dnv == 'WRFpos': WRFpos_compute = True 947 if dnv == 'WRFtime': WRFtime_compute = True 948 949 # diagnostics to compute 950 diags = varns.split(',') 951 Ndiags = len(diags) 939 952 940 953 for idiag in range(Ndiags): … … 960 973 if gen.searchInlist(depvars, 'WRFtime'): WRFtime_compute = True 961 974 975 # Dictionary with the new computed variables to be able to add them 976 dictcompvars = {} 962 977 if WRFgeop_compute: 963 978 print ' ' + main + ': Retrieving geopotential value from WRF as PH + PHB' … … 965 980 WRFgeop = ncobj.variables['PH'][:] + ncobj.variables['PHB'][:] 966 981 982 # Attributes of the variable 983 Vvals = gen.variables_values('WRFgreop') 984 dictcompvars['WRFgeop'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 985 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 986 967 987 if WRFp_compute: 968 988 print ' ' + main + ': Retrieving pressure value from WRF as P + PB' … … 970 990 WRFp = ncobj.variables['P'][:] + ncobj.variables['PB'][:] 971 991 992 # Attributes of the variable 993 Vvals = gen.variables_values('WRFp') 994 dictcompvars['WRFgeop'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 995 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 996 972 997 if WRFght_compute: 973 998 print ' ' + main + ': computing geopotential height from WRF as PH + PHB ...' 974 999 WRFght = ncobj.variables['PH'][:] + ncobj.variables['PHB'][:] 1000 1001 # Attributes of the variable 1002 Vvals = gen.variables_values('WRFght') 1003 dictcompvars['WRFgeop'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 1004 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 975 1005 976 1006 if WRFrh_compute: … … 987 1017 WRFrh = qv/data2 988 1018 1019 # Attributes of the variable 1020 Vvals = gen.variables_values('WRFrh') 1021 dictcompvars['WRFrh'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 1022 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 1023 989 1024 if WRFt_compute: 990 1025 print ' ' + main + ': computing temperature from WRF as inv_potT(T + 300) ...' … … 993 1028 994 1029 WRFt = (ncobj.variables['T'][:] + 300.)*(p/p0)**(2./7.) 1030 1031 # Attributes of the variable 1032 Vvals = gen.variables_values('WRFt') 1033 dictcompvars['WRFt'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 1034 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 995 1035 996 1036 if WRFdens_compute: … … 1016 1056 WRFdens[it,iz,:,:] = levval 1017 1057 WRFdens[it,iz,:,:] = mu[it,:,:]*WRFdens[it,iz,:,:]/grav 1058 1059 # Attributes of the variable 1060 Vvals = gen.variables_values('WRFdens') 1061 dictcompvars['WRFdens'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 1062 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 1018 1063 1019 1064 if WRFpos_compute: … … 1075 1120 1076 1121 tunits = tunitsval + ' since ' + refdateS 1122 1123 # Attributes of the variable 1124 dictcompvars['WRFtime'] = {'name': 'time', 'standard_name': 'time', \ 1125 'long_name': 'time', 'units': tunits, 'calendar': 'gregorian'} 1077 1126 1078 1127 ### ## # … … 1163 1212 diagout, diagoutd, diagoutvd = Forcompute_cllmh(var0,var1,dnames,dvnames) 1164 1213 1214 # Removing the nonChecking variable-dimensions from the initial list 1215 varsadd = [] 1216 for nonvd in NONchkvardims: 1217 if gen.searchInlist(diagoutvd,nonvd): diagoutvd.remove(nonvd) 1218 varsadd.append(nonvd) 1219 1165 1220 ncvar.insert_variable(ncobj, 'cll', diagout[0,:], diagoutd, diagoutvd, newnc) 1166 1221 ncvar.insert_variable(ncobj, 'clm', diagout[1,:], diagoutd, diagoutvd, newnc) … … 1172 1227 var0 = ncobj.variables[depvars] 1173 1228 diagout, diagoutd, diagoutvd = Forcompute_clt(var0,dnames,dvnames) 1229 1230 # Removing the nonChecking variable-dimensions from the initial list 1231 varsadd = [] 1232 for nonvd in NONchkvardims: 1233 if gen.searchInlist(diagoutvd,nonvd): diagoutvd.remove(nonvd) 1234 varsadd.append(nonvd) 1235 1174 1236 ncvar.insert_variable(ncobj, 'clt', diagout, diagoutd, diagoutvd, newnc) 1175 1237 … … 1598 1660 1599 1661 newnc.sync() 1662 # Adding that additional variables required to compute some diagnostics which 1663 # where not in the original file 1664 for vadd in varsadd: 1665 if not gen.searchInlist(newnc.variables.keys(),vadd): 1666 attrs = dictcompvars[vadd] 1667 vvn = attrs['name'] 1668 if not gen.searchInlist(newnc.variables.keys(), vvn): 1669 iidvn = dvnames.index(vadd) 1670 dnn = dnames[iidvn] 1671 if vadd == 'WRFtime': 1672 dvarvals = WRFtime[:] 1673 newvar = newnc.createVariable(vvn, 'f8', (dnn)) 1674 newvar[:] = dvarvals 1675 for attn in attrs.keys(): 1676 if attn != 'name': 1677 attv = attrs[attn] 1678 ncvar.set_attribute(newvar, attn, attv) 1600 1679 1601 1680 # end of diagnostics
Note: See TracChangeset
for help on using the changeset viewer.