Changeset 1835 in lmdz_wrf for trunk/tools/nc_var_tools.py
- Timestamp:
- Mar 21, 2018, 12:52:34 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1834 r1835 18470 18470 yend = iyy + dimyfrac 18471 18471 Ndy = len(range(yini,yend)) 18472 #Slice tuple 18473 tslc = tuple([slice(tini,tend), slice(0,dimz), slice(yini,yend), \ 18474 slice(0,dimx)]) 18475 tslcx1 = tuple([slice(tini,tend), slice(0,dimz), slice(yini,yend), \ 18476 slice(1,dimx+1)]) 18477 tslcy1= tuple([slice(tini,tend), slice(0,dimz), slice(yini+1,yend+1),\ 18478 slice(0,dimx)]) 18472 18479 18473 18480 if gen.searchInlist(notCHK, vn): 18474 18481 if vn == 'WRFght': 18475 varin = geop[t ini:tend,:,yini:yend,:]18482 varin = geop[tslc] 18476 18483 isgeop = True 18477 18484 varattrs = gen.variables_values('WRFght') … … 18482 18489 elif vn == 'WRFhus': 18483 18490 # specific humidity 18484 varin = qv[t ini:tend,:,yini:yend,:]/(1.+qv[tini:tend,:,yini:yend,:])18491 varin = qv[tslc]/(1.+qv[tslc]) 18485 18492 isgeop = False 18486 18493 varattrs = gen.variables_values('WRFhus') … … 18490 18497 newvarattr['units'] = varattrs[5] 18491 18498 elif vn == 'WRFt': 18492 varin = temp[t ini:tend,:,yini:yend,:]18499 varin = temp[tlsc] 18493 18500 isgeop = False 18494 18501 varattrs = gen.variables_values('WRFt') … … 18501 18508 print infmsg 18502 18509 print ' ' + fname + ': De-staggering x-wind variable !!' 18503 print ' from:', ovarin.shape, 'to', (dimt, dimz, dimy, dimx) 18510 print ' from:',ovarin[tini:tend,:,yini:yend,0:dimx].shape,\ 18511 'to', (Ndt,dimz,Ndy,dimx) 18504 18512 if isFR64: 18505 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float64)18513 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float64) 18506 18514 else: 18507 varin = np.zeros((Ndt, dimz, Ndy, dimx), dtype=np.float) 18508 varin[tini:tend,:,yini:yend,:] = \ 18509 0.5*(ovarin[tini:tend,:,yini:yend,0:dimx] + \ 18510 ovarin[tini:tend,:,yini:yend,1:dimx+1]) 18515 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float) 18516 varin[:] = 0.5*(ovarin[tslc] + ovarin[tslcx1]) 18511 18517 18512 18518 # Not pro, but less memory problems! … … 18539 18545 # Not pro, but less memory problems! 18540 18546 for it in range(tini,tend): 18541 varin0[it,:,yini:yend,:] = \ 18542 0.5*(ovarin[it,:,yini:yend,0:dimx] + \ 18547 varin0[it-tini,:,:,:]=0.5*(ovarin[it,:,yini:yend,0:dimx]+\ 18543 18548 ovarin[it,:,yini:yend,1:dimx+1]) 18544 varin02[it,:,yini:yend,:] = \ 18545 0.5*(ovarin2[it,:,yini:yend,:] + \ 18549 varin02[it-tini,:,:,:] = 0.5*(ovarin2[it,:,yini:yend,:]+ \ 18546 18550 ovarin2[it,:,yini+1:yend+1,:]) 18547 18551 for iz in range(dimz): 18548 varin[tini:tend,iz,yini:yend,:] = \ 18549 varin0[tini:tend,iz,yini:yend,:]* \ 18552 varin[:,iz,:,:] = varin0[tini:tend,iz,yini:yend,:]* \ 18550 18553 ocosa[tini:tend,yini:yend,:] - \ 18551 18554 varin02[tini:tend,iz,yini:yend,:]* \ … … 18563 18566 print ' from:', ovarin.shape, 'to', (dimt,dimz,dimy,dimx) 18564 18567 if isFR64: 18565 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float64)18568 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float64) 18566 18569 else: 18567 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float)18570 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float) 18568 18571 # Not pro, but less memory problems! 18569 18572 for it in range(tini,tend): 18570 varin[it ,:,yini:yend,:] = 0.5*(ovarin[it,:,yini:yend,:]+\18573 varin[it-tini,:,:,:] = 0.5*(ovarin[it,:,yini:yend,:] + \ 18571 18574 ovarin[it,:,yini+1:yend+1,:]) 18572 18575 isgeop = False … … 18596 18599 # Not pro, but less memory problems! 18597 18600 for it in range(tini,tend): 18598 varin0[it,:,yini:yend,:] = \ 18599 0.5*(ovarin[it,:,yini:yend,0:dimx] + \ 18601 varin0[it-tini,:,:,:]=0.5*(ovarin[it,:,yini:yend,0:dimx]+\ 18600 18602 ovarin[it,:,yini:yend,1:dimx+1]) 18601 varin02[it,:,yini:yend,:] = \ 18602 0.5*(ovarin2[it,:,yini:yend,:] + \ 18603 varin02[it-tini,:,:,:] = 0.5*(ovarin2[it,:,yini:yend,:]+ \ 18603 18604 ovarin2[it,:,yini+1:yend+1,:]) 18604 18605 for iz in range(dimz): 18605 varin[tini:tend,iz,yini:yend,:] = \ 18606 varin0[tini:tend,iz,yini:yend,:]* \ 18606 varin[:,iz,:,:] = varin0[tini:tend,iz,yini:yend,:]* \ 18607 18607 osina[tini:tend,yini:yend,:] + \ 18608 18608 varin02[tini:tend,iz,yini:yend,:]* \ … … 18625 18625 # Not pro, but less memory problems! 18626 18626 for it in range(tini,tend): 18627 varin[it,:,yini:yend,:] = \ 18628 0.5*(ovarin[it,0:dimz,yini:yend,:] + \ 18627 varin[it-tini,:,:,:]=0.5*(ovarin[it,0:dimz,yini:yend,:]+ \ 18629 18628 ovarin[it,1:dimz+1,yini:yend,:]) 18630 18629 isgeop = False … … 18635 18634 newvarattr['units'] = varattrs[5] 18636 18635 elif vn == 'pres': 18637 varin = pres[t ini:tend,:,yini:yend,:]18636 varin = pres[tslc] 18638 18637 isgeop = False 18639 18638 varattrs = gen.variables_values('pres') … … 18646 18645 ovarin = onc.variables[vn] 18647 18646 varinf = variable_inf(ovarin) 18648 varin = ovarin[t ini:tend,:,yini:yend,:]18647 varin = ovarin[tslc] 18649 18648 # de-staggering 18650 18649 #print ' Lluis:', ovarin.dimensions,'unsDIM', unstaggerDIM, 'CFdim:', CFdimvs … … 18668 18667 fill_value=gen.fillValueF) 18669 18668 varint = varin.transpose() 18670 prest = pres[t ini:tend,:,yini:yend,:].transpose()18669 prest = pres[tslc].transpose() 18671 18670 psfct = psfc[tini:tend,yini:yend,:].transpose() 18672 18671 hgtt = hgt[yini:yend,:].transpose() 18673 tempt = temp[t ini:tend,:,yini:yend,:].transpose()18674 qvt = qv[t ini:tend,:,yini:yend,:].transpose()18672 tempt = temp[tslc].transpose() 18673 qvt = qv[tslc].transpose() 18675 18674 varinterp = fin.module_forinterpolate.interp( data_in=varint, \ 18676 18675 pres_field=prest, interp_levels=interplevs, psfc=psfct, \ … … 18722 18721 print ' from:', ovarin.shape, 'to', (dimt, dimz, dimy, dimx) 18723 18722 if isFR64: 18724 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float64)18723 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float64) 18725 18724 else: 18726 varin = np.zeros((Ndt, dimz, Ndy, dimx), dtype=np.float) 18727 varin[tini:tend,:,yini:yend,:] = \ 18728 0.5*(ovarin[tini:tend,:,yini:yend,0:dimx] + \ 18725 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float) 18726 varin[:] = 0.5*(ovarin[tini:tend,:,yini:yend,0:dimx] + \ 18729 18727 ovarin[tini:tend,:,yini:yend,1:dimx+1]) 18730 18728 … … 18758 18756 # Not pro, but less memory problems! 18759 18757 for it in range(tini,tend): 18760 varin0[it,:,yini:yend,:] = \ 18761 0.5*(ovarin[it,:,yini:yend,0:dimx] + \ 18758 varin0[it-tend,:,:,:]=0.5*(ovarin[it,:,yini:yend,0:dimx]+\ 18762 18759 ovarin[it,:,yini:yend,1:dimx+1]) 18763 18760 varin02[it,:,yini:yend,:] = \ … … 18765 18762 ovarin2[it,:,yini+1:yend+1,:]) 18766 18763 for iz in range(dimz): 18767 varin[tini:tend,iz,yini:yend,:] = \ 18768 varin0[tini:tend,iz,yini:yend,:]* \ 18764 varin[:,iz,:,:] = varin0[tini:tend,iz,yini:yend,:]* \ 18769 18765 ocosa[tini:tend,yini:yend,:] - \ 18770 18766 varin02[tini:tend,iz,yini:yend,:]* \ … … 18782 18778 print ' from:', ovarin.shape, 'to', (dimt,dimz,dimy,dimx) 18783 18779 if isFR64: 18784 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float64)18780 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float64) 18785 18781 else: 18786 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float)18782 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float) 18787 18783 # Not pro, but less memory problems! 18788 18784 for it in range(tini,tend): 18789 varin[it ,:,yini:yend,:] = 0.5*(ovarin[it,:,yini:yend,:]+\18785 varin[it-tini,:,:,:] = 0.5*(ovarin[it,:,yini:yend,:] + \ 18790 18786 ovarin[it,:,yini+1:yend+1,:]) 18791 18787 isgeop = False … … 18815 18811 # Not pro, but less memory problems! 18816 18812 for it in range(tini,tend): 18817 varin0[it,:,yini:yend,:] = \ 18818 0.5*(ovarin[it,:,yini:yend,0:dimx] + \ 18813 varin0[it-tini,:,:,:]=0.5*(ovarin[it,:,yini:yend,0:dimx]+\ 18819 18814 ovarin[it,:,yini:yend,1:dimx+1]) 18820 varin02[it,:,yini:yend,:] = \ 18821 0.5*(ovarin2[it,:,yini:yend,:] + \ 18815 varin02[it-tini,:,:,:] = 0.5*(ovarin2[it,:,yini:yend,:]+ \ 18822 18816 ovarin2[it,:,yini+1:yend+1,:]) 18823 18817 for iz in range(dimz): 18824 varin[tini:tend,iz,yini:yend,:] = \ 18825 varin0[tini:tend,iz,yini:yend,:]* \ 18818 varin[:,iz,:,:] = varin0[tini:tend,iz,yini:yend,:]* \ 18826 18819 osina[tini:tend,yini:yend,:] + \ 18827 18820 varin02[tini:tend,iz,yini:yend,:]* \ … … 18844 18837 # Not pro, but less memory problems! 18845 18838 for it in range(tini,tend): 18846 varin[it,:,yini:yend,:] = \ 18847 0.5*(ovarin[it,0:dimz,yini:yend,:] + \ 18839 varin[it-tini,:,:,:]=0.5*(ovarin[it,0:dimz,yini:yend,:]+ \ 18848 18840 ovarin[it,1:dimz+1,yini:yend,:]) 18849 18841 isgeop = False … … 18942 18934 print ' from:', ovarin.shape, 'to', (dimt, dimz, dimy, dimx) 18943 18935 if isFR64: 18944 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float64)18936 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float64) 18945 18937 else: 18946 varin = np.zeros((Ndt, dimz, Ndy, dimx), dtype=np.float) 18947 varin[tini:tend,:,yini:yend,:] = \ 18948 0.5*(ovarin[tini:tend,:,yini:yend,0:dimx] + \ 18938 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float) 18939 varin[:] = 0.5*(ovarin[tini:tend,:,yini:yend,0:dimx] + \ 18949 18940 ovarin[tini:tend,:,yini:yend,1:dimx+1]) 18950 18941 … … 18978 18969 # Not pro, but less memory problems! 18979 18970 for it in range(tini,tend): 18980 varin0[it,:,yini:yend,:] = \ 18981 0.5*(ovarin[it,:,yini:yend,0:dimx] + \ 18971 varin0[it-tini,:,:,:]=0.5*(ovarin[it,:,yini:yend,0:dimx]+\ 18982 18972 ovarin[it,:,yini:yend,1:dimx+1]) 18983 varin02[it,:,yini:yend,:] = \ 18984 0.5*(ovarin2[it,:,yini:yend,:] + \ 18973 varin02[it-tini,:,:,:] = 0.5*(ovarin2[it,:,yini:yend,:]+ \ 18985 18974 ovarin2[it,:,yini+1:yend+1,:]) 18986 18975 for iz in range(dimz): 18987 varin[tini:tend,iz,yini:yend,:] = \ 18988 varin0[tini:tend,iz,yini:yend,:]* \ 18976 varin[:,iz,:,:] = varin0[tini:tend,iz,yini:yend,:]* \ 18989 18977 ocosa[tini:tend,yini:yend,:] - \ 18990 18978 varin02[tini:tend,iz,yini:yend,:]* \ … … 19002 18990 print ' from:', ovarin.shape, 'to', (dimt,dimz,dimy,dimx) 19003 18991 if isFR64: 19004 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float64)18992 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float64) 19005 18993 else: 19006 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float)18994 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float) 19007 18995 # Not pro, but less memory problems! 19008 18996 for it in range(tini,tend): 19009 varin[it ,:,yini:yend,:] = 0.5*(ovarin[it,:,yini:yend,:]+\18997 varin[it-tini,:,:,:] = 0.5*(ovarin[it,:,yini:yend,:] + \ 19010 18998 ovarin[it,:,yini+1:yend+1,:]) 19011 18999 isgeop = False … … 19035 19023 # Not pro, but less memory problems! 19036 19024 for it in range(tini,tend): 19037 varin0[it,:,yini:yend,:] = \ 19038 0.5*(ovarin[it,:,yini:yend,0:dimx] + \ 19025 varin0[it-tini,:,:,:]=0.5*(ovarin[it,:,yini:yend,0:dimx]+\ 19039 19026 ovarin[it,:,yini:yend,1:dimx+1]) 19040 varin02[it,:,yini:yend,:] = \ 19041 0.5*(ovarin2[it,:,yini:yend,:] + \ 19027 varin02[it-tini,:,:,:] = 0.5*(ovarin2[it,:,yini:yend,:]+ \ 19042 19028 ovarin2[it,:,yini+1:yend+1,:]) 19043 19029 for iz in range(dimz): 19044 varin[tini:tend,iz,yini:yend,:] = \ 19045 varin0[tini:tend,iz,yini:yend,:]* \ 19030 varin[:,iz,:,:] = varin0[tini:tend,iz,yini:yend,:]* \ 19046 19031 osina[tini:tend,yini:yend,:] + \ 19047 19032 varin02[tini:tend,iz,yini:yend,:]* \ … … 19064 19049 # Not pro, but less memory problems! 19065 19050 for it in range(tini,tend): 19066 varin[it,:,yini:yend,:] = \ 19067 0.5*(ovarin[it,0:dimz,yini:yend,:] + \ 19051 varin[it-tini,:,:,:]=0.5*(ovarin[it,0:dimz,yini:yend,:]+ \ 19068 19052 ovarin[it,1:dimz+1,yini:yend,:]) 19069 19053 isgeop = False … … 19158 19142 print ' from:', ovarin.shape, 'to', (dimt, dimz, dimy, dimx) 19159 19143 if isFR64: 19160 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float64)19144 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float64) 19161 19145 else: 19162 varin = np.zeros((Ndt, dimz, Ndy, dimx), dtype=np.float) 19163 varin[tini:tend,:,yini:yend,:] = \ 19164 0.5*(ovarin[tini:tend,:,yini:yend,0:dimx] + \ 19146 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float) 19147 varin[:] = 0.5*(ovarin[tini:tend,:,yini:yend,0:dimx] + \ 19165 19148 ovarin[tini:tend,:,yini:yend,1:dimx+1]) 19166 19149 … … 19194 19177 # Not pro, but less memory problems! 19195 19178 for it in range(tini,tend): 19196 varin0[it,:,yini:yend,:] = \ 19197 0.5*(ovarin[it,:,yini:yend,0:dimx] + \ 19179 varin0[it-tini,:,:,:]=0.5*(ovarin[it,:,yini:yend,0:dimx]+\ 19198 19180 ovarin[it,:,yini:yend,1:dimx+1]) 19199 varin02[it,:,yini:yend,:] = \ 19200 0.5*(ovarin2[it,:,yini:yend,:] + \ 19181 varin02[it-tini,:,:,:] = 0.5*(ovarin2[it,:,yini:yend,:]+ \ 19201 19182 ovarin2[it,:,yini+1:yend+1,:]) 19202 19183 for iz in range(dimz): 19203 varin[tini:tend,iz,yini:yend,:] = \ 19204 varin0[tini:tend,iz,yini:yend,:]* \ 19184 varin[:,iz,:,:] = varin0[tini:tend,iz,yini:yend,:]* \ 19205 19185 ocosa[tini:tend,yini:yend,:] - \ 19206 19186 varin02[tini:tend,iz,yini:yend,:]* \ … … 19218 19198 print ' from:', ovarin.shape, 'to', (dimt,dimz,dimy,dimx) 19219 19199 if isFR64: 19220 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float64)19200 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float64) 19221 19201 else: 19222 varin = np.zeros((Ndt, dimz, Ndy,dimx), dtype=np.float)19202 varin = np.zeros((Ndt,dimz,Ndy,dimx), dtype=np.float) 19223 19203 # Not pro, but less memory problems! 19224 19204 for it in range(tini,tend): 19225 varin[it,:, yini:yend,:] = 0.5*(ovarin[it,:,yini:yend,:]+\19205 varin[it,:,:,:] = 0.5*(ovarin[it,:,yini:yend,:] + \ 19226 19206 ovarin[it,:,yini+1:yend+1,:]) 19227 19207 isgeop = False … … 19251 19231 # Not pro, but less memory problems! 19252 19232 for it in range(tini,tend): 19253 varin0[it,:,yini:yend,:] = \ 19254 0.5*(ovarin[it,:,yini:yend,0:dimx] + \ 19233 varin0[it-tini,:,:,:]=0.5*(ovarin[it,:,yini:yend,0:dimx]+\ 19255 19234 ovarin[it,:,yini:yend,1:dimx+1]) 19256 varin02[it,:,yini:yend,:] = \ 19257 0.5*(ovarin2[it,:,yini:yend,:] + \ 19235 varin02[it-tini,:,:,:] = 0.5*(ovarin2[it,:,yini:yend,:]+ \ 19258 19236 ovarin2[it,:,yini+1:yend+1,:]) 19259 19237 for iz in range(dimz): 19260 varin[tini:tend,iz,yini:yend,:] = \ 19261 varin0[tini:tend,iz,yini:yend,:]* \ 19238 varin[:,iz,:,:] = varin0[tini:tend,iz,yini:yend,:]* \ 19262 19239 osina[tini:tend,yini:yend,:] + \ 19263 19240 varin02[tini:tend,iz,yini:yend,:]* \ … … 19280 19257 # Not pro, but less memory problems! 19281 19258 for it in range(tini,tend): 19282 varin[it,:,yini:yend,:] = \ 19283 0.5*(ovarin[it,0:dimz,yini:yend,:] + \ 19259 varin[it-tini,:,:,:]=0.5*(ovarin[it,0:dimz,yini:yend,:]+ \ 19284 19260 ovarin[it,1:dimz+1,yini:yend,:]) 19285 19261 isgeop = False
Note: See TracChangeset
for help on using the changeset viewer.