Changeset 1848 in lmdz_wrf


Ignore:
Timestamp:
Mar 23, 2018, 2:48:42 PM (7 years ago)
Author:
lfita
Message:

Getting almost done!! with `CFmorzization'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r1847 r1848  
    2269022690          [globattrfilen]: name of ASCII file with the given metadata to be added as global attributes
    2269122691            with a line per attribute [attrname] [value] it has to have at least (underparenthesis for description)
    22692             use '#' for comments:
     22692            use '#' for comments (use '[unknown]' for that values set-up according to content from file:
    2269322693              institute_id [value, use '!' for spaces] (CV)
    2269422694              institution  [value]
     
    2269922699              product [value] (single value: "output")
    2270022700              Conventions [value] (later than CF1.4 if present / single value: "CF-1.4")
    22701               creation_date [YYYY-MM-DDTHH:MM:SSZ] (format according to UNIDATA conventions, same in CMIP5 & CORDEX)
     22701              creation_date [value] ([YYYY-MM-DDTHH:MM:SSZ] format according to UNIDATA conventions, same in CMIP5 & CORDEX)
    2270222702              frequency [value] (same CV as CMIP5 with "sem" in addition; 3hr highest freq. in CORDEX; no "yr")
    2270322703              driving_model_id [value] (CMIP5 institute_id, <CMIP5 institute_id>-<member in CMIP5 CV list of model_id>)
     
    2272622726          NOTE: CF values will be taken from 'variables_values.dat'
    2272722727    """
     22728    import datetime as dt
    2272822729    fname = 'CFmorzization'
    2272922730
     
    2292622927              'Y-m-dTH:M:SZ')
    2292722928            secfreq = gen.CFtime_freq(axisv[0], axisv[1], tunits)
     22929            Sfreq = -1
    2292822930            # Labelling frequency
    2292922931            if np.mod(secfreq, 100 * 365 * 24 * 3600.) == 0.:
    2293022932                Sfreq = str(int(secfreq/(100 * 365 * 24 * 3600.))) + 'C'
    22931             elif np.mod(secfreq, 365 * 24 * 3600.) == 0.:
     22933            elif Sfreq == -1 and np.mod(secfreq, 365 * 24 * 3600.) == 0.:
    2293222934                Sfreq = str(int(secfreq/(365 * 24 * 3600.))) + 'Y'
    22933             elif np.mod(secfreq, 7 * 24 * 3600.) == 0.:
     22935            elif Sfreq == -1 and np.mod(secfreq, 7 * 24 * 3600.) == 0.:
    2293422936                Sfreq = str(int(secfreq/(7 * 24 * 3600.))) + 'W'
    22935             elif np.mod(secfreq, 24 * 3600.) == 0.:
     22937            elif Sfreq == -1 and np.mod(secfreq, 24 * 3600.) == 0.:
    2293622938                Sfreq = str(int(secfreq/(24.*3600.))) + 'D'
    22937             elif np.mod(secfreq,3600.) == 0.:
     22939            elif Sfreq == -1 and np.mod(secfreq,3600.) == 0.:
    2293822940                Sfreq = str(int(secfreq/3600.)) + 'H'
    22939             elif np.mod(secfreq,60.) == 0.:
     22941            elif Sfreq == -1 and np.mod(secfreq,60.) == 0.:
    2294022942                Sfreq = str(int(secfreq/60.)) + 'M'
    22941             else: Sfreq = 'UNKNOWN'
     22943            else:
     22944                # Getting frequency from the global attributes
     22945                Sfreq = gattr['frequency']
     22946            if gattr['frequency'] == '[unknown]': gattr['frequency'] = Sfreq
     22947            print '    frquency in file:', secfreq, 's', Sfreq
     22948
     22949    # Renaming dimensions for 2D lon,lat variable-dimensions
     22950    if len(filedimvals['X'].shape) == 2 or len(filedimvals['Y'].shape) == 2:
     22951        print infmsg
     22952        print '    because Xvals have rank 2:', filedimvals['X'].shape,              \
     22953          'renaming lon,lat dimensions to x,y'
     22954        axv = CFdimvals['X']
     22955        axv['dimn'] = 'x'
     22956        CFdimvals['X'] = axv
     22957        axv = CFdimvals['Y']
     22958        axv['dimn'] = 'y'
     22959        CFdimvals['Y'] = axv
     22960        #axiv = axisinf['X']
     22961        #filecfdimn[axiv[0]] = 'x'
     22962        #axiv = axisinf['Y']
     22963        #filecfdimn[axiv[0]] = 'y'
    2294222964
    2294322965    print 'Values for variables-axes from file ________'
     
    2296822990
    2296922991        CFaxisvardimvals[axn] = cfdimaxes
     22992 
    2297022993    print 'file --> CF equivalencies of dimensions _______'
    2297122994    print filecfdimn
     
    2301323036          '_' + gattr['rcm_version_id'] + '_' + Sfreq + '_' + Sinit + '-' + Sendt +  \
    2301423037          '.nc'
    23015 
    2301623038        onewnc = NetCDFFile(filen,'w')
     23039        now = dt.datetime.now()
     23040        if gattr['creation_date'] == '[unknown]':
     23041            gattr['creation_date'] = now.strftime("%Y-%m-%dT%H:%M:%SZ")
    2301723042        # Definition only of that coordinates from the variable
    2301823043        for axn in varaxes:
Note: See TracChangeset for help on using the changeset viewer.