Changeset 1480 in lmdz_wrf for trunk


Ignore:
Timestamp:
Mar 31, 2017, 5:51:21 PM (8 years ago)
Author:
lfita
Message:

Adding 'time' awareness on file `netcdf_fold_concatenation_HMT'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r1474 r1480  
    1059210592        [fold]: folder with the location of the netCDF files
    1059310593        [dimname]: dimension along which files should be concatenated
    10594         [tail]: tail of the files to concatenate (optional)
     10594        [vardimname]: name of the dimension variable with the values
    1059510595      [ncfile]= [header],[middle],[tail]
    1059610596        [header] = header of the name of the files to concatenate [ncfile]*[middle]*[tail]
     
    1061310613    fold = values.split(',')[0]
    1061410614    condim = values.split(',')[1]
     10615    vardimname = values.split(',')[2]
    1061510616
    1061610617    HMT = ncfile.split(',')
     
    1063910640        print errormsg
    1064010641        print '  ' + fname + ": files do not have dimensions '" + condim + "' !!!"
     10642        quit(-1)
     10643    if not ncobjs[0].variables.has_key(vardimname):
     10644        print errormsg
     10645        print '  ' + fname + ": files do not have variable '" + vardimname + "' !!!"
    1064110646        quit(-1)
    1064210647
     
    1067710682    newvar = newnc.createVariable('int' + condim, 'i4', tuple(dims))
    1067810683    newvar[:] = range(totcondim)
     10684
     10685# Dimension variable for the concatenation
     10686   
     10687    odimvar = ncobjs[0].variables[vardimname]
     10688    odimvardims = odimvar.dimensions
     10689    odimattrs = odimvar.ncattrs
     10690    for dimn in odimvardims:
     10691        if not gen.searchInlist(newnc.dimensions,dimn):
     10692            Ldim = len(odimvar.dimensions[dimn])
     10693    newvar = newnc.crateVarieble(vardimname, odimvar.dtype, odimvardims)
     10694    for attrn in odimattrs:
     10695        attrv = odimvar.getncattr(attrn)
     10696        newattr = set_attribute(newvar, attrn, attrv)
     10697        if attrn == 'units': urefvals = attrv
     10698
     10699    # Checking units of condimvar
     10700    uvalsecs = urefvals.split(' ')
     10701    if uvalsecs[1] == 'since':
     10702        tunits = True
     10703        if len(uvalsecs) == 4:
     10704            date=uvalsecs[2]
     10705            time=uvalsecs[3]
     10706        else:
     10707            if uvalsecs[2].find('_') != -1:
     10708                date=uvalsecs[2]
     10709                time='00:00:00'
     10710            else:
     10711                date=uvalsecs[2].split('_')[0]
     10712                time=uvalsecs[2].split('_')[1]
     10713        refdate = gen.datetimeStr_datetime(date+'_'+time)
     10714        print warnmsg
     10715        print '  ' + fname + ': concatenating dimension-variable has time units!'
     10716        print '    shifting temporal-values since the date of the first file', refdate
     10717
     10718    for ifile in range(Nfiles):
     10719        slicevartot = []
     10720        objvar = ncobjs[ifile].variables[vardimname]
     10721        for dimn in objvar.dimensions:
     10722            ldimfile = len(ncobjs[ifile].dimensions[dimn])
     10723            if dimn == condim:
     10724                slicevartot.append(slice(begslicetot,begslicetot+ldimfile))
     10725                begslicetot = begslicetot + ldimfile
     10726            else:
     10727                slicevartot.append(slice(0,ldimfile))
     10728            if tunits:
     10729                uvals = objvar.getncattr('units')
     10730                newtimes = gen.coincident_CFtimes(objvar[:], uvals, urefvals)
     10731                newvar[tuple(slicevartot)] = objvar[:]
     10732            else:
     10733                newvar[tuple(slicevartot)] = objvar[:]
     10734            newnc.sync()
    1067910735
    1068010736# Looping variables
Note: See TracChangeset for help on using the changeset viewer.