Changeset 911 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 20, 2016, 1:40:59 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r904 r911 41 41 # significant_decomposition: Function to decompose a given number by its signifcant potencies 42 42 # singleline_printing_class: Function to print all the values of a given class in a single line to be parseavel 43 # stagger_unstagger: Function to de-stagger a variable 43 44 # str_list: Function to obtain a list from a string givin a split character 44 45 # subbasin_point: Function to provide sub-basins given a grid point following a matrix of trips … … 463 464 if totunits == 'second': 464 465 itime = dt.datetime(int(iyrS),int(imoS),int(idaS),int(ihoS),int(imiS),int(iseS)) 465 print 'Lluis ', edate[12:15], '00'466 466 if edate[12:15] != '00': 467 467 etime = dt.datetime(int(eyrS), int(emoS), int(edaS), int(ehoS), int(emiS), int(eseS)+1) … … 628 628 CFvar_DIAGvar(varn) 629 629 [varn]= CF name of the variable 630 >>> CFvar_ MODvar('pr')630 >>> CFvar_DIAGvar('pr') 631 631 {'RAINTOT': ['RAINC', 'RAINNC']} 632 >>> CFvar_ MODvar('hurs')632 >>> CFvar_DIAGvar('hurs') 633 633 {'TSrhs': ['psfc', 't', 'q'], 'LMDZrhs': ['psol', 't2m', 'q2m'], 'WRFrhs': ['PSFC', 'T2', 'Q2']} 634 634 """ … … 6442 6442 # quit(-1) 6443 6443 if np.mod(iptpos,fracs) == 0: 6444 print 'Lluis syncronizing!'6445 6444 onc.sync() 6446 6445 if out: … … 7866 7865 return listv 7867 7866 7867 def stagger_unstagger(varv, dndims, udims): 7868 """ Function to de-stagger a variable 7869 varv= values of the variable to de-stagger 7870 dndims = dn[x/y/z/t] list of the names of the dimenions of the variable 7871 udims = ud[x/y/z/t] unstaggered dictionary with the dimenions of the variable 7872 7873 >>> mat = np.arange((20), dtype=np.float).reshape(5,4) 7874 >>> dmat = ['dystaggered','dx'] 7875 >>> unstagdims = {'dy': 4, 'dx': 4} 7876 >>> stagger_unstagger(mat, dmat, unstagdims) 7877 [[ 2. 3. 4. 5.] 7878 [ 6. 7. 8. 9.] 7879 [ 10. 11. 12. 13.] 7880 [ 14. 15. 16. 17.]] 7881 """ 7882 fname = 'stagger_unstagger' 7883 7884 udndims = list(udims.keys()) 7885 7886 idim = 0 7887 vdstaggered = {} 7888 newdims = [] 7889 7890 idim = 0 7891 for vd in dndims: 7892 idim = dndims.index(vd) 7893 if searchInlist(udndims, vd): 7894 if varv.shape[idim] - 1 == udims[vd]: 7895 vdstaggered[vd] = varv.shape[idim] - 1 7896 else: 7897 vdstaggered[vd] = varv.shape[idim] 7898 else: 7899 vdstaggered[vd] = varv.shape[idim] - 1 7900 print ' ' + fname + ": new dimension '" + vd + "' with length :", \ 7901 varv.shape[idim], 'as staggered dim' 7902 newdims.append(vdstaggered[vd]) 7903 7904 if len(vdstaggered) > 1: 7905 destagger_varv = np.zeros(tuple(newdims), dtype=np.float) 7906 7907 ndim = 0 7908 upstagslc = [] 7909 downstagslc = [] 7910 for vd in vdstaggered.keys(): 7911 idim = dndims.index(vd) 7912 if vdstaggered[vd] != varv.shape[idim]: 7913 upstagslc.append(slice(1,varv.shape[idim])) 7914 downstagslc.append(slice(0,varv.shape[idim]-1)) 7915 else: 7916 upstagslc.append(slice(0,varv.shape[idim])) 7917 downstagslc.append(slice(0,varv.shape[idim])) 7918 destagger_varv = 0.5*(varv[tuple(upstagslc)] + varv[tuple(downstagslc)]) 7919 7920 return destagger_varv 7921 else: 7922 return varv 7923 7868 7924 #quit() 7869 7925
Note: See TracChangeset
for help on using the changeset viewer.