Changeset 2482 in lmdz_wrf


Ignore:
Timestamp:
Apr 29, 2019, 8:35:45 PM (7 years ago)
Author:
lfita
Message:

Improving `gen_impose_gregorian' by making use of 'CFtimeU_inf' class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2481 r2482  
    23362336    availcalendar = ['noleap', '365d', '365_day']
    23372337
    2338     lTunits = Tunits.split(' ')
    2339     NTunits = len(lTunits)
    2340     Tu = lTunits[0]
    2341 
    2342     if NTunits < 4:
    2343         print infmsg
    2344         print '  ' + fname + ": CF-time units without time, adding '00:00:00' !!"
    2345         Srefdate = lTunits[2] + ' 00:00:00'
    2346     else:
    2347         Srefdate = lTunits[2] + ' ' + lTunits[3]
    2348     refdate = [int(Srefdate[0:4]), int(Srefdate[5:7]), int(Srefdate[8:10]),          \
    2349       int(Srefdate[11:13]), int(Srefdate[14:16]), int(Srefdate[17:19]) ]
     2338    timeinf = CFtimeU_inf(Tunits)
     2339
     2340    refdate = timeinf.refdate
     2341    Tu = timeinf.Tunits
    23502342
    23512343    if type(timev) == type(range(2)):
     
    23672359        quit(-1)
    23682360
    2369     if Tu == 'weeks':
    2370         timevdays = timev * 7
    2371     elif Tu == 'days':
    2372         timevdays = timev * 1.
    2373     elif Tu == 'hours':
    2374         timevdays = timev / 24.
    2375     elif Tu == 'minutes':
    2376         timevdays = timev / (24.*60.)
    2377     elif Tu == 'seconds':
    2378         timevdays = timev / (24.*3600.)
    2379     else:
    2380         print errormsg
    2381         print '  ' + fname + ": CF time units '" + Tu + "' not ready !!"
    2382         print '    available ones:', availTu
    2383         quit(-1)
     2361    # Transforming to days
     2362    factordays = timeinf.utodays
     2363    timevdays = timev * factordays
    23842364
    23852365    newtimes = np.zeros((dimt), dtype=np.float64)
    2386 
    2387     refdays = juliandate(refdate[0], refdate[1], refdate[2], refdate[3], refdate[4], refdate[5])
    2388 
    2389     yrref = refdate[0]
     2366    refdays = timeinf.refdatejuliand
     2367    yrref = timeinf.refdatemat[0]
    23902368    if cal == 'noleap' or cal == '365d' or cal == '365_day':
    23912369        for it in range(dimt):
     
    24092387       
    24102388    # Re-transforming to the original units
    2411     if Tu == 'weeks':
    2412         newtimes = newtimes/(7.)
    2413     elif Tu == 'days':
    2414         newtimes = newtimes*1.
    2415     elif Tu == 'hours':
    2416         newtimes = newtimes*60.
    2417     elif Tu == 'minutes':
    2418         newtimes = newtimes*24.*3600.
     2389    newtimes = newtimes/factordays
    24192390
    24202391    return newtimes
Note: See TracChangeset for help on using the changeset viewer.