Changeset 2480 in lmdz_wrf for trunk/tools
- Timestamp:
- Apr 29, 2019, 5:25:58 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
-
generic_tools.py (modified) (2 diffs)
-
nc_var_tools.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2479 r2480 16627 16627 # Getting year, month and day 16628 16628 Nyears = int(tvals[it] / dyear) 16629 yd = int(refdate[0] + Nyears) 16630 jd = tvals[it] - Nyears*dyear 16629 if tvals[it] > 0.: 16630 yd = int(refdate[0] + Nyears) 16631 jd = tvals[it] - Nyears*dyear 16632 else: 16633 yd = int(refdate[0] + Nyears) - 1 16634 jd = 360 + (tvals[it] - Nyears*dyear) 16635 16631 16636 md = int(jd/30) + 1 16632 16637 dd = int(jd - (md-1)*30) 16633 16634 16638 # Getting hour, minute, second 16635 16639 tt = jd - int(jd) 16640 16636 16641 tsecs = tt*24.*3600. 16637 16642 hh = int(tsecs/(3600.)) … … 16642 16647 Nd_regmon = days_month(yd,md) 16643 16648 dd = int(dd*Nd_regmon/30.) 16644 ddt = dt.datetime(yd,md,dd,hh,mi,int(ss)) - inftunits.refdateDT16645 16649 juliand = juliandate(yd,md,dd,hh,mi,ss) 16646 newtvals[it] = juliand - inftunits.refdatejuliand + 1 16650 newtvals[it] = juliand - inftunits.refdatejuliand + 1. 16647 16651 # Transforming to original units 16648 16652 newtvals[it] = newtvals[it]/inftunits.utodays -
trunk/tools/nc_var_tools.py
r2478 r2480 31388 31388 lats = np.arange(latSW-ddy2,latNE+ddy2,ddy) 31389 31389 31390 print 'Lluis shapes lons:', lons.shape, 'lats:', lats.shape31391 31390 # Sorting lon/lat_bounds 31392 31391 lon_bnds = np.zeros((dimx,2), dtype=np.float64) … … 31583 31582 print ' available ones:', ovar.dimensions 31584 31583 quit(-1) 31585 idimt = ovar.dimensions.index [operation[1]]31584 idimt = ovar.dimensions.index(operation[1]) 31586 31585 dimt = ovarshape[idimt] 31587 slices = provide_slices(ovar.dimensions, ovarshape, [operation[1]])31586 slices = gen.provide_slices(ovar.dimensions, ovarshape, [operation[1]]) 31588 31587 minv = gen.typemod(operation[2], ovar.dtype) 31589 31588 maxv = gen.typemod(operation[3], ovar.dtype) 31590 31589 31591 31590 # First centered values 31592 shapecirc = list(ovarshape) 31593 shapecirc = shapecirc.pop(idimt) 31591 shapecirc = [] 31592 for iv in range(len(ovarshape)): 31593 if iv != idimt: shapecirc.append(ovarshape[iv]) 31594 31594 circ = np.zeros(tuple(shapecirc), dtype=ovar.dtype) 31595 if shapecirc == 2: 31596 ccircx = circ.shape[1]/2. 31597 ccircy = circ.shape[0]/2. 31595 rankcirc = len(shapecirc) 31596 if rankcirc == 2: 31597 dimx = circ.shape[1] 31598 dimy = circ.shape[0] 31599 ccircx = dimx/2. 31600 ccircy = dimy/2. 31598 31601 norm = np.sqrt(ccircx**2 + ccircy**2) 31599 31602 for iy in range(dimy): 31600 31603 for ix in range(dimx): 31601 31604 circ[iy,ix] = np.sqrt((ix*1.-ccircx)**2 + (iy*1.-ccircy)**2)/norm 31602 elif shapecirc == 3: 31603 ccircx = circ.shape[2]/2. 31604 ccircy = circ.shape[1]/2. 31605 ccircz = circ.shape[0]/2. 31605 elif rankcirc == 3: 31606 dimx = circ.shape[2] 31607 dimy = circ.shape[1] 31608 dimz = circ.shape[0] 31609 ccircx = dimx/2. 31610 ccircy = dimy/2. 31611 ccircz = dimz/2. 31606 31612 norm = np.sqrt(ccircx**2 + ccircy**2 + ccircz**2) 31607 31613 for iz in range(dimz): … … 31612 31618 else: 31613 31619 print errormsg 31614 print ' ' + fname + ": shape of variable without time:", circ.shape, +\31620 print ' ' + fname + ": rank of variable without time:", circ.shape, \ 31615 31621 'not ready !!' 31616 31622 print ' available ones: 2D, 3D' … … 31624 31630 rangev = np.arange(maxv, minv-dt, dt) 31625 31631 31626 vals = np.zeros( varshape, dtype=ovar.dtype)31632 vals = np.zeros(ovarshape, dtype=ovar.dtype) 31627 31633 31628 31634 for it in range(dimt): 31629 vals[tuple(slices)] = circ*rangev[it] 31635 circv = circ*rangev[it] 31636 vals[tuple(slices[it])] = circv[:] 31630 31637 ovar[:] = vals 31631 31638 … … 31816 31823 return 31817 31824 31818 timesv = [56649.5, 56680, 56710.5, 56741, 56771.5, 56802.5, 56833, 56863.5, 56894, 56924.5] 31819 dimt = len(timesv) 31820 values='lon|360,lat|180,time|None@' + str(dimt) + ':global' 31821 varsS='tas#time;lat;lon#f#None,time#time#f8#units|days!since!1850-01-01!00:00:00|S' 31822 CFfile_creation(values, 'CFtest.nc', varsS) 31823 fname = 'timev1850-2005.dat' 31824 of = open(fname, 'w') 31825 for tv in timesv: 31826 of.write(str(tv) + '\n') 31827 of.close() 31828 setvar_asciivalues(fname, 'CFtest.nc', 'time') 31829 fill_varNCfile('random,0.,10.','CFtest.nc','tas') 31830 31831 values="setCalendar;setRefDate,19491201000000;setTunits,hours" 31832 varaddattr('calendar|noleap', 'CFtest.nc', 'time') 31833 CFfile_fixTime(values, 'CFtest.nc', 'time') 31825 #timesv = [56649.5, 56680, 56710.5, 56741, 56771.5, 56802.5, 56833, 56863.5, 56894, 56924.5] 31826 #timesv = np.arange(15.5,315.5,30.) - 360. 31827 #dimt = len(timesv) 31828 #values='lon|360,lat|180,time|None@' + str(dimt) + ':global' 31829 #varsS='tas#time;lat;lon#f#None,time#time#f8#units|days!since!1850-01-01!00:00:00|S' 31830 #CFfile_creation(values, 'CFtest.nc', varsS) 31831 #fname = 'timev1850-2005.dat' 31832 #of = open(fname, 'w') 31833 #for tv in timesv: 31834 # of.write(str(tv) + '\n') 31835 #of.close() 31836 #setvar_asciivalues(fname, 'CFtest.nc', 'time') 31837 #fill_varNCfile('centeredevol,time,0.,10.','CFtest.nc','tas') 31838 31839 #values="setCalendar;setRefDate,19491201000000;setTunits,hours" 31840 #varaddattr('calendar|360d', 'CFtest.nc', 'time') 31841 #CFfile_fixTime(values, 'CFtest.nc', 'time') 31834 31842 31835 31843 #quit()
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/LMDZ_WRF/chrome/site/your_project_logo.png)