- Timestamp:
- Jul 13, 2019, 9:52:45 PM (5 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/diag_tools.py
r2675 r2678 1624 1624 dyst = dys.transpose() 1625 1625 1626 print ' ' + fname + ' Lluis shapes dzs', dzs.shape, 'dz:', dz1627 1628 1626 pxdiab, pydiab, pzdiab, pxdef, pydef, pzdef, pxtilt, pytilt, pzdiv, pf = \ 1629 1627 fdin.module_fordiagnostics.compute_frontogenesis(theta=thetat, ua=uat, \ … … 1646 1644 quit(-1) 1647 1645 1648 return xdiab, ydiab, zdiab, xdef, ydef, zdef, xtilt, ytilt, zdiv, f 1646 return xdiab, ydiab, zdiab, xdef, ydef, zdef, xtilt, ytilt, zdiv, f, frontdims, frontvdims 1649 1647 1650 1648 ####### ###### ##### #### ### ## # END Fortran diagnostics -
trunk/tools/diagnostics.py
r2675 r2678 104 104 NONcheckingvars = ['accum', 'cllmh', 'deaccum', 'face', 'LONLATdxdy', \ 105 105 'params', 'reglonlatbnds', 'TSrhs', 'TStd', 'TSwds', 'TSwss', \ 106 'UNua', 'UNva', 'UNwa', \ 106 107 'WRFbils', 'WRFbnds', \ 107 108 'WRFclivi', 'WRFclwvi', 'WRFdens', 'WRFdx', 'WRFdxdy', 'WRFdxdywps', 'WRFdy', \ … … 206 207 if dnv == 'WRFdxdywps':WRFdxdywps_compute = True 207 208 if dnv == 'LONLATdxdy':LONLATdxdy_compute = True 209 if dnv[0:4] == 'UNua': 210 UNua_compute = True 211 vUnua = dnv.split(',')[1] 212 if dnv[0:4] == 'UNva': 213 UNva_compute = True 214 vUnva = dnv.split(',')[1] 215 if dnv[0:4] == 'UNwa': 216 UNwa_compute = True 217 vUnwa = dnv.split(',')[1] 208 218 209 219 # diagnostics to compute … … 223 233 if depvars == 'WRFtime': WRFtime_compute = True 224 234 if depvars == 'WRFz': WRFz_compute = True 235 if depvars == 'WRFdx': WRFdx_compute = True 236 if depvars == 'WRFdy': WRFdy_compute = True 237 if depvars == 'WRFdz': WRFdz_compute = True 238 if depvars == 'WRFdxdy': WRFdxdy_compute = True 239 if depvars == 'WRFdxdywps': WRFdxdywps_compute = True 240 if depvars == 'LONLATdxdy': LONLATdxdy_compute = True 241 if depvars[0:4] == 'UNua': 242 UNua_compute = True 243 vUnua = dnv.split(',')[1] 244 if depvars[0:4] == 'UNva': 245 UNva_compute = True 246 vUnva = dnv.split(',')[1] 247 if depvars[0:4] == 'UNwa': 248 UNwa_compute = True 249 vUnwa = dnv.split(',')[1] 225 250 else: 226 251 depvars = diags[idiag].split('|')[1].split('@') … … 240 265 if gen.searchInlist(depvars, 'WRFdxdywps'): WRFdxdywps_compute = True 241 266 if gen.searchInlist(depvars, 'LONLATdxdy'): LONLATdxdy_compute = True 267 if gen.searchInlist_Strsec(depvars, 0, 3, 'UNua'): 268 UNua_compute = True 269 vals, ind = gen.search_sec_list(depvars,'UNua') 270 dnv = depvars[ind[0]] 271 vUNua = dnv.split(':')[1] 272 if gen.searchInlist_Strsec(depvars, 0, 3, 'UNva'): 273 UNva_compute = True 274 vals, ind = gen.search_sec_list(depvars,'UNva') 275 dnv = depvars[ind[0]] 276 vUNva = dnv.split(':')[1] 277 if gen.searchInlist_Strsec(depvars, 0, 3, 'UNwa'): 278 UNwa_compute = True 279 vals, ind = gen.search_sec_list(depvars,'UNwa') 280 dnv = depvars[ind[0]] 281 vUNwa = dnv.split(':')[1] 242 282 243 283 # Dictionary with the new computed variables to be able to add them … … 379 419 refdateS = yrref + '-' + monref + '-' + dayref + ' ' + horref + ':' + minref + \ 380 420 ':' + secref 381 382 421 383 422 if len(timeobj.shape) == 2: … … 537 576 # Attributes of the variable 538 577 Vvals = gen.variables_values('WRFdx') 539 dictcompvars['WRFdx'] = {'name': Vvals[0], 'standard_name': Vvals[1], 578 dictcompvars['WRFdx'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 540 579 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 541 580 Vvals = gen.variables_values('WRFdy') 542 dictcompvars['WRFdy'] = {'name': Vvals[0], 'standard_name': Vvals[1], 581 dictcompvars['WRFdy'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 543 582 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 544 583 Vvals = gen.variables_values('WRFds') 545 dictcompvars['WRFds'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 584 dictcompvars['WRFds'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 585 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 586 587 if UNua_compute: 588 print ' ' + main + ": un-staggering '" + vUNua + "': as 0.5*(ua[0:dimx-1]+" + \ 589 "ua[1:dimx])" 590 vunua = ncobj.variables[vUNua][:] 591 dimv = ncobj.variables[vUNua].shape 592 593 dimx = dimv[3] 594 dimy = dimv[2] 595 dimz = dimv[1] 596 dimt = dimv[0] 597 598 undimx = 'unx' 599 600 unua = np.zeros((dimt,dimz,dimy,dimx-1), dtype=np.float) 601 unua[...,0:dimx-1] = 0.5*(vunua[...,1:dimx]+vunua[...,0:dimx-1]) 602 603 # Attributes of the variable 604 Vvals = gen.variables_values('ua') 605 dictcompvars['unua'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 606 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 607 608 if UNva_compute: 609 print ' ' + main + ": un-staggering '" + vUNva + "': as 0.5*(va[0:dimy-1]+" + \ 610 "va[1:dimy])" 611 vunva = ncobj.variables[vUNva][:] 612 dimv = ncobj.variables[vUNva].shape 613 614 dimx = dimv[3] 615 dimy = dimv[2] 616 dimz = dimv[1] 617 dimt = dimv[0] 618 619 undimy = 'uny' 620 621 unva = np.zeros((dimt,dimz,dimy-1,dimx), dtype=np.float) 622 unva[...,0:dimy-1,:] = 0.5*(vunva[...,1:dimy,:]+vunva[...,0:dimy-1,:]) 623 624 # Attributes of the variable 625 Vvals = gen.variables_values('va') 626 dictcompvars['unva'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 627 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 628 629 if UNwa_compute: 630 print ' ' + main + ": un-staggering '" + vUNwa + "': as 0.5*(wa[0:dimz-1]+" + \ 631 "wa[1:dimz])" 632 vunwa = ncobj.variables[vUNwa][:] 633 dimv = ncobj.variables[vUNwa].shape 634 635 dimx = dimv[3] 636 dimy = dimv[2] 637 dimz = dimv[1] 638 dimt = dimv[0] 639 640 undimz = 'unz' 641 642 unwa = np.zeros((dimt,dimz-1,dimy,dimx), dtype=np.float) 643 unwa[...,0:dimz-1,:,:] = 0.5*(vunwa[...,1:dimz,:,:]+vunwa[...,0:dimz-1,:,:]) 644 645 # Attributes of the variable 646 Vvals = gen.variables_values('wa') 647 dictcompvars['unwa'] = {'name': Vvals[0], 'standard_name': Vvals[1], \ 546 648 'long_name': Vvals[4].replace('|',' '), 'units': Vvals[5]} 547 649 … … 881 983 # frontogenesis (theta, ua, va, wa, press, dxs, dys, dzs, time) 882 984 elif diagn == 'frontogenesis': 883 884 985 if depvars[0] == 'WRFt': var0 = WRFt 885 986 else: var0 = ncobj.variables[depvars[0]][:] … … 888 989 dz = var0.shape[1] 889 990 dt = var0.shape[0] 890 var1 = ncobj.variables[depvars[1]][:] 891 var2 = ncobj.variables[depvars[2]][:] 892 var3 = ncobj.variables[depvars[3]][:] 991 if depvars[1][0:4] == 'UNua': var1 = unua 992 else: var1 = ncobj.variables[depvars[1]][:] 993 if depvars[2][0:4] == 'UNva': var2 = unva 994 else: var2 = ncobj.variables[depvars[2]][:] 995 if depvars[3][0:4] == 'UNwa': var3 = unwa 996 else: var3 = ncobj.variables[depvars[3]][:] 893 997 if depvars[4] == 'WRFp': var4 = WRFp 894 998 else: var4 = ncobj.variables[depvars[4]] … … 909 1013 var4, var5, var6, var7, var8, dnames, dvnames) 910 1014 1015 # Removing the nonChecking variable-dimensions from the initial list 1016 varsadd = [] 1017 diagoutvd = list(dvnames) 1018 for nonvd in NONchkvardims: 1019 if gen.searchInlist(dvnames,nonvd): diagoutvd.remove(nonvd) 1020 varsadd.append(nonvd) 1021 911 1022 ncvar.insert_variable(ncobj, 'diabh', diag1, diagoutd, diagoutvd, newnc, \ 912 1023 gen.fillValueF) 913 ovar = newnc.variables['diabh'] 1024 newnc.renameVariable('diabh', 'xdiabh') 1025 newnc.sync() 1026 ovar = newnc.variables['xdiabh'] 914 1027 stdn = ovar.getncattr('standard_name') 915 1028 ovar.setncattr('standard_name', 'x'+stdn) … … 921 1034 ncvar.insert_variable(ncobj, 'diabh', diag2, diagoutd, diagoutvd, newnc, \ 922 1035 gen.fillValueF) 923 ovar = newnc.variables['diabh'] 1036 newnc.renameVariable('diabh', 'ydiabh') 1037 newnc.sync() 1038 ovar = newnc.variables['ydiabh'] 924 1039 stdn = ovar.getncattr('standard_name') 925 1040 ovar.setncattr('standard_name', 'y'+stdn) … … 931 1046 ncvar.insert_variable(ncobj, 'diabh', diag3, diagoutd, diagoutvd, newnc, \ 932 1047 gen.fillValueF) 933 ovar = newnc.variables['diabh'] 1048 newnc.renameVariable('diabh', 'zdiabh') 1049 newnc.sync() 1050 ovar = newnc.variables['zdiabh'] 934 1051 stdn = ovar.getncattr('standard_name') 935 1052 ovar.setncattr('standard_name', 'z'+stdn) … … 942 1059 ncvar.insert_variable(ncobj, 'def', diag4, diagoutd, diagoutvd, newnc, \ 943 1060 gen.fillValueF) 944 ovar = newnc.variables['def'] 1061 newnc.renameVariable('def', 'xdef') 1062 newnc.sync() 1063 ovar = newnc.variables['xdef'] 945 1064 stdn = ovar.getncattr('standard_name') 946 1065 ovar.setncattr('standard_name', 'thetax'+stdn) … … 952 1071 ncvar.insert_variable(ncobj, 'def', diag5, diagoutd, diagoutvd, newnc, \ 953 1072 gen.fillValueF) 954 ovar = newnc.variables['def'] 1073 newnc.renameVariable('def', 'ydef') 1074 newnc.sync() 1075 ovar = newnc.variables['ydef'] 955 1076 stdn = ovar.getncattr('standard_name') 956 1077 ovar.setncattr('standard_name', 'thetay'+stdn) … … 962 1083 ncvar.insert_variable(ncobj, 'def', diag6, diagoutd, diagoutvd, newnc, \ 963 1084 gen.fillValueF) 964 ovar = newnc.variables['def'] 1085 newnc.renameVariable('def', 'zdef') 1086 newnc.sync() 1087 ovar = newnc.variables['zdef'] 965 1088 stdn = ovar.getncattr('standard_name') 966 1089 ovar.setncattr('standard_name', 'thetaz'+stdn) … … 973 1096 ncvar.insert_variable(ncobj, 'tilt', diag7, diagoutd, diagoutvd, newnc, \ 974 1097 gen.fillValueF) 975 ovar = newnc.variables['tilt'] 1098 newnc.renameVariable('tilt', 'xtilt') 1099 newnc.sync() 1100 ovar = newnc.variables['xtilt'] 976 1101 stdn = ovar.getncattr('standard_name') 977 1102 ovar.setncattr('standard_name', 'thetax'+stdn) … … 984 1109 ncvar.insert_variable(ncobj, 'tilt', diag8, diagoutd, diagoutvd, newnc, \ 985 1110 gen.fillValueF) 986 ovar = newnc.variables['tilt'] 1111 newnc.renameVariable('tilt', 'ytilt') 1112 newnc.sync() 1113 ovar = newnc.variables['ytilt'] 987 1114 stdn = ovar.getncattr('standard_name') 988 1115 ovar.setncattr('standard_name', 'thetay'+stdn) … … 995 1122 ncvar.insert_variable(ncobj, 'div', diag9, diagoutd, diagoutvd, newnc, \ 996 1123 gen.fillValueF) 997 ovar = newnc.variables['div'] 1124 newnc.renameVariable('div', 'zdiv') 1125 newnc.sync() 1126 ovar = newnc.variables['zdiv'] 998 1127 stdn = ovar.getncattr('standard_name') 999 1128 ovar.setncattr('standard_name', 'thetaz'+stdn) … … 1007 1136 newvar = newnc.createVariable('e', 'i', ('e')) 1008 1137 newvar[:] = range(3) 1009 ncvar. newvar.basicvardef(newvar, 'component', 'axis component: x, y, z', '-')1138 ncvar.basicvardef(newvar, 'component', 'axis component: x, y, z', '-') 1010 1139 newnc.sync() 1011 1140
Note: See TracChangeset
for help on using the changeset viewer.