Changeset 1088 in lmdz_wrf for trunk


Ignore:
Timestamp:
Sep 9, 2016, 5:31:47 PM (9 years ago)
Author:
lfita
Message:

Adding CFRefTime in `LMDZ_toCF'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r1083 r1088  
    1673716737    return
    1673816738
    16739 def LMDZ_toCF(ncfile):
     16739def LMDZ_toCF(values,ncfile):
    1674016740    """ Function to pass a LMDZ original file to CF-conventions
     16741      values= [CFtimeUnits]
     16742        [CFtimeUnits]: [tunits] since [YYYYMMDDHHMISS], CF time-units to which variable time should be used ('!' for spaces)
    1674116743      ncfile= file to transform
    16742       variables= variables to transform
    1674316744    """
    1674416745    fname = 'LMDZ_toCF'
     
    1674816749        print LMDZ_toCF.__doc__
    1674916750        quit()
     16751
     16752    CFT = values.replace('!',' ')
    1675016753
    1675116754    ofile = 'CF_LMDZ.nc'
     
    1676016763        print fname + ": renaming variable 'pres' as 'p' !!"
    1676116764        newname = ncf.renameVariable('pres','p')
     16765    ncf.sync()
     16766
     16767    # Re-aranging time-axis
     16768    tvaro = ncf.variables['time_counter']
     16769    tvals = tvaro[:]
     16770    tunits = tvaro.getncattr('units')
     16771
     16772    RefDate = CFT.split(' ')[2]
     16773    RefDateS = RefDate[0:4] + '-' + RefDate[4:6] + '-' + RefDate[6:8] + ' ' +        \
     16774      RefDate[8:10] + ':' + RefDate[10:12] + ':' + RefDate[12:14]
     16775    CFtimeUnits = ' '.join(CFT.split(' ')[0:2]) + ' '+ RefDateS
     16776
     16777    newtvals = gen.coincident_CFtimes(tvals, CFtimeUnits, tunits)
     16778    tvaro[:] = newtvals
     16779    newattr = set_attribute(tvaro, 'units', CFtimeUnits)
     16780    newattr = set_attribute(tvaro, 'time_origin', CFtimeUnits)
     16781
    1676216782    ncf.sync()
    1676316783
Note: See TracChangeset for help on using the changeset viewer.