Changeset 508 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 17, 2015, 4:14:44 PM (10 years ago)
Author:
lfita
Message:

Working version of `DatesFiles?'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var.py

    r507 r508  
    8484
    8585# Operations which file name is not a real file
    86 NotCheckingFile = ['file_creation', 'list_operations', 'netcdf_concatenation', 'netcdf_fold_concatenation']
     86NotCheckingFile = ['DatesFiles', 'file_creation', 'list_operations',                 \
     87  'netcdf_concatenation', 'netcdf_fold_concatenation']
    8788
    8889####### ###### ##### #### ### ## #
  • trunk/tools/nc_var_tools.py

    r507 r508  
    1587515875    """
    1587615876    import subprocess as sub
     15877    import datetime as dt
    1587715878    fname='DatesFiles'
    1587815879
     
    1588415885    arguments = '[dates],[fold]'
    1588515886    check_arguments(fname, len(values.split(',')), arguments, ',',                   \
    15886       len(argumenst.split(',')))
    15887 
    15888     dates = values.split(',')[0].split(',')
     15887      len(arguments.split(',')))
     15888
     15889    dates = values.split(',')[0].split(':')
    1588915890    fold = values.split(',')[1]
    1589015891
     
    1589315894
    1589415895    print '  ' + fname +': looking on:',Nfiles,'files'
    15895     print confiles
    1589615896
    1589715897# Opening all files and getting times
    1589815898    ncobjs = {}
    1589915899    for filen in confiles:
    15900         print 'charging: ',filen
    1590115900        filename = fold + '/' + filen
    15902         ncf = NetCDFFile(fname, 'r')
     15901        ncf = NetCDFFile(filename, 'r')
     15902        datesv = []
    1590315903        if varn == 'WRFt':
    1590415904            fdates = ncf.variables['Times'][:]
    15905             datesv = datetimeStr_conversion(fdates, 'WRFdatetime', 'YmdHMS')
     15905            for it in range(fdates.shape[0]):
     15906                datesv.append(datetimeStr_conversion(fdates[it,:], 'WRFdatetime',    \
     15907                  'YmdHMS'))
    1590615908        else:
    1590715909            tunits = ncf.variables[varn].getncattr('units')
    1590815910            fdates = ncf.variables[varn][:]
    15909             datesv = datetimeStr_conversion(fdates, 'cfTime,' + tunits , 'YmdHMS')
    15910 
    15911         ncobjs[fname] = datesv
    15912    
    15913     founddates = {}
    15914     for dt in dates:
     15911            for it in range(fdates.shape[0]):
     15912                datesv.append(datetimeStr_conversion(fdates[it], 'cfTime,' + tunits ,\
     15913                   'YmdHMS'))
     15914
     15915        ncobjs[filename] = datesv
     15916        ncf.close()
     15917
     15918# Computing time-step inside files (assuming regular)
     15919        if filen == confiles[0]:
     15920            ini=datesv[0]
     15921            end=datesv[1]
     15922
     15923            iniT = dt.datetime.strptime(ini,'%Y%m%d%H%M%S')
     15924            endT = dt.datetime.strptime(end,'%Y%m%d%H%M%S')
     15925
     15926            DT = endT - iniT
     15927            diffT = DT.total_seconds()
     15928            print '  ' + fname + ': seconds between time-steps in files:', diffT
     15929
     15930    Efounddates = {}
     15931    Cfounddates = {}
     15932    for dtv in dates:
     15933        foundclosest = False
    1591515934        for fn in ncobjs.keys():
    15916             if searchInlist(ncobjs[fn], dt):
    15917                 founddates[dt] = fn
    15918                 istep = ncobjs[fn].index(dt)
    15919 
    15920                 print fname + ':',dt,fn,istep
    15921 
     15935            if searchInlist(ncobjs[fn], dtv):
     15936                founddates[dtv] = fn
     15937                istep = ncobjs[fn].index(dtv)
     15938
     15939                print fname + 'Exact:',dtv,fn,istep,'(date, filname, time-step)'
     15940                Efounddates[dtv] = [dtv,fn,istep]
     15941
     15942            for it in ncobjs[fn]:
     15943                iniT = dt.datetime.strptime(it,'%Y%m%d%H%M%S')
     15944                endT = dt.datetime.strptime(dtv,'%Y%m%d%H%M%S')
     15945
     15946                DT = endT - iniT
     15947                diffitv = DT.total_seconds()
     15948
     15949                if diffT > DT.total_seconds():
     15950                    istep = ncobjs[fn].index(it)
     15951                    print fname + 'Closest:',dtv,fn,it,diffitv,'(date, filname, ' +  \
     15952                      'time-step, distance in seconds)'
     15953                    Cfounddates[dtv] = [dtv,fn,istep,diffitv]
     15954                    foundclosest = True
     15955                    break
     15956
     15957            if foundclosest: break
    1592215958    return
    1592315959
Note: See TracChangeset for help on using the changeset viewer.