Changeset 2480 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Apr 29, 2019, 5:25:58 PM (7 years ago)
Author:
lfita
Message:

Working version of CFfile_fixTime' and from360d_reg' with negative time values

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2479 r2480  
    1662716627            # Getting year, month and day
    1662816628            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
    1663116636            md = int(jd/30) + 1
    1663216637            dd = int(jd - (md-1)*30)
    16633 
    1663416638            # Getting hour, minute, second
    1663516639            tt = jd - int(jd)
     16640
    1663616641            tsecs = tt*24.*3600.
    1663716642            hh = int(tsecs/(3600.))
     
    1664216647            Nd_regmon = days_month(yd,md)
    1664316648            dd = int(dd*Nd_regmon/30.)
    16644             ddt = dt.datetime(yd,md,dd,hh,mi,int(ss)) - inftunits.refdateDT
    1664516649            juliand = juliandate(yd,md,dd,hh,mi,ss)
    16646             newtvals[it] = juliand - inftunits.refdatejuliand + 1
     16650            newtvals[it] = juliand - inftunits.refdatejuliand + 1.
    1664716651            # Transforming to original units
    1664816652            newtvals[it] = newtvals[it]/inftunits.utodays
  • trunk/tools/nc_var_tools.py

    r2478 r2480  
    3138831388        lats = np.arange(latSW-ddy2,latNE+ddy2,ddy)
    3138931389
    31390     print 'Lluis shapes lons:', lons.shape, 'lats:', lats.shape
    3139131390    # Sorting lon/lat_bounds
    3139231391    lon_bnds = np.zeros((dimx,2), dtype=np.float64)
     
    3158331582            print '    available ones:', ovar.dimensions
    3158431583            quit(-1)
    31585         idimt = ovar.dimensions.index[operation[1]]
     31584        idimt = ovar.dimensions.index(operation[1])
    3158631585        dimt = ovarshape[idimt]
    31587         slices = provide_slices(ovar.dimensions, ovarshape, [operation[1]])
     31586        slices = gen.provide_slices(ovar.dimensions, ovarshape, [operation[1]])
    3158831587        minv = gen.typemod(operation[2], ovar.dtype)
    3158931588        maxv = gen.typemod(operation[3], ovar.dtype)
    3159031589
    3159131590        # 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])
    3159431594        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.
    3159831601            norm = np.sqrt(ccircx**2 + ccircy**2)
    3159931602            for iy in range(dimy):
    3160031603                for ix in range(dimx):
    3160131604                    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.
    3160631612            norm = np.sqrt(ccircx**2 + ccircy**2 + ccircz**2)
    3160731613            for iz in range(dimz):
     
    3161231618        else:
    3161331619            print errormsg
    31614             print '  ' + fname + ": shape of variable without time:", circ.shape, +  \
     31620            print '  ' + fname + ": rank of variable without time:", circ.shape,     \
    3161531621              'not ready !!'
    3161631622            print '   available ones: 2D, 3D'
     
    3162431630            rangev = np.arange(maxv, minv-dt, dt)
    3162531631
    31626         vals = np.zeros(varshape, dtype=ovar.dtype)
     31632        vals = np.zeros(ovarshape, dtype=ovar.dtype)
    3162731633
    3162831634        for it in range(dimt):
    31629             vals[tuple(slices)] = circ*rangev[it]
     31635            circv = circ*rangev[it]
     31636            vals[tuple(slices[it])] = circv[:]
    3163031637        ovar[:] = vals
    3163131638
     
    3181631823    return
    3181731824
    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')
    3183431842
    3183531843#quit()
Note: See TracChangeset for help on using the changeset viewer.