Changeset 2440 in lmdz_wrf


Ignore:
Timestamp:
Apr 16, 2019, 4:34:27 PM (6 years ago)
Author:
lfita
Message:

Imposing gregorian calendar for non-standard calendars in `get_timee'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r2423 r2440  
    2546825468def get_time(values, ncfile, variable):
    2546925469    """ Function to provide the closest time-step to a given time
    25470       values= [timevalue];[units]
     25470      values= [timevalue];[units];[calendar]
    2547125471        [timevalue]: CF value of time to look for
    2547225472        [units]: CF units of time [Tunit] since [date] ('!' for spaces)
     25473        [calenadar]: CF calendar used by the data
    2547325474      ncfile= file from which provide the information
    2547425475      variable= [timevarn] name of the variable with the CF-times ('WRFtime' for WRF
     
    2548225483        quit()
    2548325484
    25484     expectargs = '[timevalue];[units]'
     25485    expectargs = '[timevalue];[units];[calendar]'
    2548525486    gen.check_arguments(fname, values, expectargs, ';')
    2548625487
    2548725488    timevalue = np.float(values.split(';')[0])
    2548825489    uTunits = values.split(';')[1].replace('!',' ')
     25490    calendar = np.float(values.split(';')[2])
    2548925491
    2549025492    onc = NetCDFFile(ncfile, 'r')
     
    2550025502        otime = onc.variables['Times']
    2550125503        timev0, timeu = compute_WRFtime(otime[:])
     25504        timec = 'gregorian'
    2550225505    else:
    2550325506        otime = onc.variables[variable]
    2550425507        timev0 = otime[:]
    2550525508        timeu = otime.units
    25506 
     25509        timea = otime.ncattrs()
     25510        if gen.searchInlist(timea, 'calendar'):
     25511            timec = otime.calendar
     25512        else:
     25513            print warnmsg
     25514            print '  ' + fname + ": time variable '" + variable + "' without " +     \
     25515              " 'calendar' attribute !!"
     25516            print "    assuming 'gregorian'"
     25517            timec = 'gregorian'
    2550725518    onc.close()
    2550825519
     25520    # Checking calendar consistency
     25521    if calendar != timec:
     25522        print errmsg
     25523        print '  ' + fname + ": different calendars found !!"
     25524        print "    input calendar: '" + calendar + "' calendar in data '" +timec + "'"
     25525        quit(-1)
     25526   
     25527    if calendar == 'noleap' or calendar == '365d':
     25528        # Adding leap days to avoid dephase (thus, imposing 'gregorian' calendar)
     25529        gregtime = gen.impose_gregorian(timev0, uTunits, calendar)
     25530
    2550925531    # Referring to the same units
    25510     reftvals = gen.coincident_CFtimes(timev0, uTunits, timeu)
     25532    reftvals = gen.coincident_CFtimes(gregtime, uTunits, timeu)
    2551125533
    2551225534    # looking for minimum distance
Note: See TracChangeset for help on using the changeset viewer.