Changeset 649 in lmdz_wrf for trunk/tools
- Timestamp:
- Sep 23, 2015, 11:24:45 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/diagnostics.py
r643 r649 77 77 # Mathematical operators 78 78 ## 79 def compute_accum(varv, dimns, dimvns): 80 """ Function to compute the accumulation of a variable 81 compute_accum(varv, dimnames, dimvns) 82 [varv]= values to accum (assuming [t,]) 83 [dimns]= list of the name of the dimensions of the [varv] 84 [dimvns]= list of the name of the variables with the values of the 85 dimensions of [varv] 86 """ 87 fname = 'compute_accum' 88 89 deacdims = dimns[:] 90 deacvdims = dimvns[:] 91 92 slicei = [] 93 slicee = [] 94 95 Ndims = len(varv.shape) 96 for iid in range(0,Ndims): 97 slicei.append(slice(0,varv.shape[iid])) 98 slicee.append(slice(0,varv.shape[iid])) 99 100 slicee[0] = np.arange(varv.shape[0]) 101 slicei[0] = np.arange(varv.shape[0]) 102 slicei[0][1:varv.shape[0]] = np.arange(varv.shape[0]-1) 103 104 vari = varv[tuple(slicei)] 105 vare = varv[tuple(slicee)] 106 107 ac = vari*0. 108 for it in range(1,varv.shape[0]): 109 ac[it,] = ac[it-1,] + vare[it,] 110 111 return ac, deacdims, deacvdims 112 79 113 def compute_deaccum(varv, dimns, dimvns): 80 114 """ Function to compute the deaccumulation of a variable … … 761 795 ## MAIN 762 796 ####### 763 availdiags = ['ACRAINTOT', 'clt', 'cllmh', 'deaccum', 'LMDZrh', 'mslp', 'RAINTOT', \ 797 availdiags = ['ACRAINTOT', 'accum', 'clt', 'cllmh', 'deaccum', 'LMDZrh', 'mslp', \ 798 'OMEGAw', 'RAINTOT', \ 764 799 'rvors', 'td', 'turbulence', 'WRFrvors', 'wds', 'wss'] 800 801 methods = ['accum', 'deaccum'] 765 802 766 803 # Variables not to check … … 931 968 depvars = diags[idiag].split('|')[1].split('@') 932 969 if depvars[0] == 'deaccum': diag='deaccum' 970 if depvars[0] == 'accum': diag='accum' 933 971 for depv in depvars: 934 972 if not ncobj.variables.has_key(depv) and not \ 935 ncvar.searchInlist(NONcheckingvars, depv) and depvars[0] != 'deaccum': 973 ncvar.searchInlist(NONcheckingvars, depv) and \ 974 not ncvar.searchInlist(methods, depv): 936 975 print errormsg 937 976 print ' ' + main + ": file '" + opts.ncfile + \ … … 941 980 depvars = diags[idiag].split('|')[1] 942 981 if not ncobj.variables.has_key(depvars) and not \ 943 ncvar.searchInlist(NONcheckingvars, depvars) and depvars[0] != 'deaccum': 944 print errormsg 982 ncvar.searchInlist(NONcheckingvars, depvars) and \ 983 not ncvar.searchInlist(methods, depvars): 984 print errormsg, 'Lluis',methods 945 985 print ' ' + main + ": file '" + opts.ncfile + \ 946 986 "' does not have variable '" + depvars + "' !!" … … 959 999 dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) 960 1000 961 ncvar.insert_variable(ncobj, 'acpr', diagout, dnamesvar, dvnamesvar, newnc) 1001 ncvar.insert_variable(ncobj, 'pracc', diagout, dnamesvar, dvnamesvar, newnc) 1002 1003 # accum: acumulation of any variable as (Variable, time [as [tunits] 1004 # from/since ....], newvarname) 1005 elif diag == 'accum': 1006 1007 var0 = ncobj.variables[depvars[0]] 1008 var1 = ncobj.variables[depvars[1]] 1009 1010 dnamesvar = var0.dimensions 1011 dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) 1012 1013 diagout, diagoutd, diagoutvd = compute_accum(var0,dnamesvar,dvnamesvar) 1014 1015 CFvarn = ncvar.variables_values(depvars[0])[0] 1016 1017 # Removing the flux 1018 if depvars[1] == 'XTIME': 1019 dtimeunits = var1.getncattr('description') 1020 tunits = dtimeunits.split(' ')[0] 1021 else: 1022 dtimeunits = var1.getncattr('units') 1023 tunits = dtimeunits.split(' ')[0] 1024 1025 dtime = (var1[1] - var1[0])*timeunits_seconds(tunits) 1026 1027 ncvar.insert_variable(ncobj, CFvarn + 'acc', diagout*dtime, diagoutd, diagoutvd, newnc) 962 1028 963 1029 # cllmh with cldfra, pres
Note: See TracChangeset
for help on using the changeset viewer.