Changeset 1864 in lmdz_wrf


Ignore:
Timestamp:
Mar 26, 2018, 7:31:53 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `new_p_dim' in 'CFvariables.dat'
  • `extrafiles': in ' CFmorzization'
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/CFvariables.dat

    r1863 r1864  
    11# File with the values of actions to be done for specific CF variables
    2 # [cfvarname] [action] [newdimension] [newvardim] [newvarvaluesdim]
     2# [cfvarname] [action] [values]
    33#   [action] ________
    4 #     new_z_dim: add a z dimension named [newdimension] with an associated variable-dimension [newvardim] with value [newvarvaluesdim]
     4#     new_z_dim: add a height dimension named [newdimension] with an associated variable-dimension [newvardim] with value [newvarvaluesdim]
     5#       # [cfvarname] new_z_dim [newdimension] [newvardim] [newvarvaluesdim]
     6#     new_p_dim: add a pressure dimension named [newdimension] with an associated variable-dimension [newvardim] with value [newvarvaluesdim]
     7#       # [cfvarname] new_p_dim [newdimension] [newvardim] [newvarvaluesdim]
    58#
     9#   [newvarvaluesdim] _______
     10#     [number]: direct value to use
     11#     Fromfile,[varn]: value to be taken from variable [varn] present in file
    612huss new_z_dim height height 2.
    713tas new_z_dim height height 2.
    814uas new_z_dim height height 10.
    915vas new_z_dim height height 10.
     16hus new_z_dim pressure pressure 'FROMfile,press'
     17ta new_z_dim pressure pressure 'FROMfile,press'
     18ua new_z_dim pressure pressure 'FROMfile,press'
     19va new_z_dim pressure pressure 'FROMfile,press'
     20wa new_z_dim pressure pressure 'FROMfile,press'
     21zg new_z_dim pressure pressure 'FROMfile,press'
    1022
  • trunk/tools/nc_var_tools.py

    r1863 r1864  
    2286622866#quit()
    2286722867
    22868 def projection2D_information(PROJn, AXinf, projinf, dx, dy, onc):
     22868def projection2D_information(PROJn, AXinf, projinf, dx, dy, oncs):
    2286922869    """ Function to get the basic information of the 2D-projection: new dimensions, variables, ...
    2287022870      Reproducing: class Projection from wrfncxnj.py
     
    2287222872        AXinf: dictionary with the informatino of the axes 'X', 'Y', 'Z', 'T'
    2287322873        projinf: dictionary with all the information of the projection
    22874         onc= netCDF object from which retrieve the information
     22874        oncs= netCDF objects from which retrieve the information
    2287522875      Returns:
    2287622876        newdim: dictionary new dimensions to be added {dimn1: dimlength1, ..., dimnN: dimlengthN}
     
    2298122981        newvar['rlon'] = ['grid_longitude', 'longitude in rotated pole grid',        \
    2298222982          'degrees']
    22983         if not gen.searchInlist(onc.variables.keys(),projinf['fileXrefvals'][0]):
     22983        found = Flase
     22984        fileNs = ''
     22985        for ionc in range(len(oncs)):
     22986            onc = oncs[ionc]
     22987            fileNs = fileNs + onc.filepath + ', '
     22988            if gen.searchInlist(onc.variables.keys(),projinf['fileXrefvals'][0]):
     22989                oXvar = onc.variables[projinf['fileXvals'][0]]
     22990                break
     22991        if not found:
    2298422992            print errormsg
    22985             print '  ' + fname + ": file does not have variable with X ref values '"+\
    22986               projinf['fileXrefvals'][0] + "' !!"
     22993            print '  ' + fname + ": files: " + fileNs + " do not have variable " +   \
     22994              "with X ref values '" + projinf['fileXrefvals'][0] + "' !!"
    2298722995            print '    available ones:', onc.variables.keys()
    2298822996            quit(-1)
    22989         oXvar = onc.variables[projinf['fileXvals'][0]]
    2299022997        if len(oXvar.shape) == 3:
    2299122998            newvarv['rlon'] = oXvar[0,0,:]
     
    2309123098    return newdim, newvar, newvarv, nonCFattr
    2309223099
    23093 def CFvars(cfvarn, vardims, varvalues, outnc):
     23100def CFvars(cfvarn, innc, vardims, varvalues, outnc):
    2309423101    """ Function to adapt a given variable and file following CF-standards
    2309523102      NOTE: reading information from 'CFvariables.dat'
    2309623103        cfvarn= provided CF name of the variabale
     23104        innc= netCDF object with input
    2309723105        vardims= dimensions of the variable
    2309823106        varvalues= values of the variable
     
    2312523133        action = CFactions[0]
    2312623134
    23127         # Adding z-dimension
    23128         if action == 'new_z_dim':
     23135        # Adding p-dimension
     23136        if action == 'new_p_dim':
    2312923137            newdim = CFactions[1]
    2313023138            newvdim = CFactions[2]
    23131             newvvar = np.float(CFactions[3])
     23139            if CFactions[3].find('FROMfile') == -1:
     23140                newvvar = np.float(CFactions[3])
     23141            else:
     23142                vn = CFactinos[3].split[0]
     23143                if not innc.variables.has_key(vn):
     23144                    print errormsg
     23145                    print '  ' + fname + ": input file does not have variable '" + vn\
     23146                      + "' !!"
     23147                    print '    available ones:', innc.variables.keys()
     23148                    quit(-1)
     23149                ovar = innc.variables[vn]
     23150                # Assuming all the same value!
     23151                var1D = ovar.flatten()
     23152                newvvar = var1D[0]
     23153            outnc.createDimension(newdim, 1)
     23154            dimvals = gen.CFcorValues(newdim)
     23155            if not gen.searchInlist(outnc.dimensions, newdim):
     23156                newdim = outnc.createDimension(newdim, 1)
     23157            if not outnc.variables.has_key(newvdim):
     23158                newvar = outnc.createVariable(newvdim, 'f8', (newdim))
     23159                basicvardef(newvar, dimvals['stdn'], dimvals['longname'],            \
     23160                  dimvals['units'])
     23161                newvar[:] = newvvar
     23162                for ivn in dimvals.keys():
     23163                    if ivn != 'dimn' and ivn != 'stdn' and ivn != 'longname' and \
     23164                      ivn != 'units' and ivn != 'maxrank' and ivn != 'length':
     23165                        set_attribute(newvar,ivn,dimvals[ivn])
     23166            newvdn = []
     23167            newvshape = []
     23168            idim = 0
     23169            for vdn in vardims:
     23170                if vdn == 'time':
     23171                    newvdn.append(vdn)
     23172                    newvshape.append(varvalues.shape[idim])
     23173                    newvdn.append(newdim)
     23174                    newvshape.append(1)
     23175                else:
     23176                    newvdn.append(vdn)
     23177                    newvshape.append(varvalues.shape[idim])
     23178                idim = idim + 1
     23179            newvarvalues = np.zeros(tuple(newvshape), dtype=np.float)
     23180            newvarvalues[:,0,:,:] = varvalues
     23181
     23182        # Adding z-dimension
     23183        elif action == 'new_z_dim':
     23184            newdim = CFactions[1]
     23185            newvdim = CFactions[2]
     23186            if CFactions[3].find('FROMfile') == -1:
     23187                newvvar = np.float(CFactions[3])
     23188            else:
     23189                vn = CFactinos[3].split[0]
     23190                if not innc.variables.has_key(vn):
     23191                    print errormsg
     23192                    print '  ' + fname + ": input file does not have variable '" + vn\
     23193                      + "' !!"
     23194                    print '    available ones:', innc.variables.keys()
     23195                    quit(-1)
     23196                ovar = innc.variables[vn]
     23197                # Assuming all the same value!
     23198                var1D = ovar.flatten()
     23199                newvvar = var1D[0]
    2313223200            outnc.createDimension(newdim, 1)
    2313323201            dimvals = gen.CFcorValues(newdim)
     
    2317523243          (http://cmip-pcmdi.llnl.gov/cmip5/output_req.html#metadata)
    2317623244
    23177         values=[dimvarns]:[globattrfile]:[projectfile]
     23245        values=[dimvarns]:[globattrfile]:[projectfile]:[extrafiles]
    2317823246          [dimvarns]: ',' separated list for identification of axes, dimensions and
    2317923247            variable-dimensions as '[AXIS]|[dimn]|[vardimn]'
     
    2322023288               y_resoltuion [value] (resolution along y-axis)
    2322123289               proj_units [value] (units of the resoltion of the projection)
     23290          [extrafiles]: ',' list of netCDF files to be used if any additional variable is needed (use 'None' for any)
    2322223291        ncfile= netCDF file to use
    2322323292        variable= ',' list of [varfn]@[method]@[Tbnds] to CF transform. A separated file will be
    2322423293          created for each variable
    2322523294          use [varfn]@instantaneous@None for instantaneous values
    23226           NOTE: CF values will be taken from 'variables_values.dat'
     23295          NOTE: CF values will be taken from 'variables_values.dat' and 'CFvariables.dat' for fine tunning
    2322723296            [varfn]: name of the variable inside the file
    2322823297            [method]: cell_method of the variable ('!' for spaces) uing, standard CF description:
     
    2324723316        quit()
    2324823317
    23249     expectargs = '[dimvarns]:[globattrfilen]:[projectfile]'
     23318    expectargs = '[dimvarns]:[globattrfilen]:[projectfile]:[extrafiles]'
    2325023319    gen.check_arguments(fname, values, expectargs, ':')
    2325123320
     
    2325323322    globalattrfilen = values.split(':')[1]
    2325423323    projfilen = values.split(':')[2]
     23324    extrafiles = values.split(':')[3].split(',')
     23325
     23326    exonc = []
     23327    if extrafiles[0] != 'None':
     23328        for fln in extrafiles:
     23329            if not os.path.isfile(fln):
     23330                print errormsg
     23331                print '  '+fname+"': netCDF extra file '" +fln+ "' does not exist !!"
     23332                quit(-1)
     23333            else:
     23334                exonc.append(NetCDFFile(fln,'r'))
    2325523335
    2325623336    # CF Mandatory global attributes
     
    2349623576    if len(filedimvals['X'].shape) == 2 or len(filedimvals['Y'].shape) == 2:
    2349723577        newDim, newVar, newVARv, nonCFproj = projection2D_information(gattr['grid'], \
    23498           CFdimvals, pattr, filedimvals['X'].shape[1], filedimvals['X'].shape[0], onc)
     23578          CFdimvals, pattr, filedimvals['X'].shape[1], filedimvals['X'].shape[0],    \
     23579          exonc + [onc])
    2349923580
    2350023581    if len(newDim.keys()) > 0:
     
    2364523726                elif cdn == 'time': print ' '
    2364623727                else: coorv.append(cdn)
    23647             newVdims, newVvalues = CFvars(cfvarn, CFvardims, ovar[:], onewnc)
     23728            newVdims, newVvalues = CFvars(cfvarn, onc, CFvardims, ovar[:], onewnc)
    2364823729            if newVdims is None:
    2364923730                newvar=onewnc.createVariable(cfvarn, 'f4', tuple(CFvardims),         \
Note: See TracChangeset for help on using the changeset viewer.