Changeset 1868 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Mar 26, 2018, 10:59:24 PM (7 years ago)
Author:
lfita
Message:

Fixing a variety of issues to make it happen with the use of multiple input files in CFmorzization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r1867 r1868  
    2286722867#quit()
    2286822868
    22869 def getvar_listonc(varn, listoc):
     22869def getvar_listonc(varn, fns, listoc):
    2287022870    """ Function to get a variable object from a list of netCDF file object
    2287122871      varn= name of the variable to be found
     22872      fns= list with the name of the files
    2287222873      listoc= list of NetCDF file objects
    2287322874    """
     
    2287522876
    2287622877    allfs = {}
    22877     fns = []
    2287822878    for ioc in range(len(listoc)):
    2287922879        oc = listoc[ioc]
    22880         allfs[oc.filepath] = [oc.dimensions, oc.variables.keys()]
    22881         fns.append(oc.filepath)
     22880        # Seems that ObjNetcdf.filepath() requires netcdf >= 4.1.2....
     22881        #  Thus avoiding to use the functionality
     22882        #allfs[oc.filepath()] = ...
     22883        allfs[fns[ioc]] = [oc.dimensions, oc.variables.keys()]
    2288222884
    2288322885    # Looping for all files
     
    2288522887    for ioc in range(len(listoc)):
    2288622888        oc = listoc[ioc]
    22887         oncvars = allfs[ioc]
     22889        # Seems that ObjNetcdf.filepath() requires netcdf >= 4.1.2....
     22890        #  Thus avoiding to use the functionality
     22891        oncvars = allfs[fns[ioc]]
    2288822892        oncvars.sort()
    2288922893        if oc.variables.has_key(varn):
     
    2289422898    if not found:
    2289522899        print errormsg
    22896         print '  ' + fname + "': any netcdf file '" + allfs.keys() + "' contain " + \
     22900        print '  ' + fname + "': any netcdf file '" + ','.join(fns) + "' contain " + \
    2289722901          "variable '" + varn + "' !!"
    2289822902        print '    available ones _______'
     
    2290222906            listoc[ioc].close()
    2290322907            ioc = ioc + 1
    22904             quit(-1)
     22908        quit(-1)
    2290522909
    2290622910    return ov
    2290722911
    22908 def projection2D_information(PROJn, AXinf, projinf, dx, dy, oncs):
     22912def projection2D_information(PROJn, AXinf, projinf, dx, dy, Fns, oncs):
    2290922913    """ Function to get the basic information of the 2D-projection: new dimensions, variables, ...
    2291022914      Reproducing: class Projection from wrfncxnj.py
    2291122915        PROJn= name of the projection
    22912         AXinf: dictionary with the informatino of the axes 'X', 'Y', 'Z', 'T'
    22913         projinf: dictionary with all the information of the projection
     22916        AXinf= dictionary with the informatino of the axes 'X', 'Y', 'Z', 'T'
     22917        projinf= dictionary with all the information of the projection
     22918        Fns= list with the name of the files
    2291422919        oncs= list of netCDF objects from which retrieve the information
    2291522920      Returns:
     
    2292122926    fname = 'projection2D_information'
    2292222927
    22923     availproj = ['Lambert_Conformal', 'Rotated_Pole', 'Mercator']
     22928    availproj = ['Lambert_Conformal', 'Rotated_Pole/Rotate_Latituded_Longitude',     \
     22929      'Mercator']
    2292422930
    2292522931    # Explanation of certain attributes in projection file
     
    2299723003        AXinf['Y'] = axv
    2299823004
    22999     elif PROJn == "Rotated_Pole":
     23005    elif PROJn == "Rotated_Pole" or PROJn == 'Rotated_Latitude_Longitude':
    2300023006        proj_attr = ["grid_mapping_name", "grid_north_pole_latitude",                \
    2300123007          "grid_north_pole_longitude", 'fileXvals', 'fileYvals']
     
    2302223028          'degrees']
    2302323029
    23024         ovar = getvar_listonc(projinf['fileXvals'][0], oncs)
     23030        ovar = getvar_listonc(projinf['fileXvals'][0], Fns, oncs)
    2302523031        oXvar = ovar[0]
    2302623032        if len(oXvar.shape) == 3:
     
    2304323049        newdim['rlat'] = dy
    2304423050        newvar['rlat'] = ['grid_latitude', 'latitude in rotated pole grid', 'degrees']
    23045         ovar = getvar_listonc(projinf['fileYvals'][0], oncs)
     23051        ovar = getvar_listonc(projinf['fileYvals'][0], Fns, oncs)
    2304623052        oYvar = ovar[0]
    2304723053        if len(oYvar.shape) == 3:
     
    2311623122    else:
    2311723123        print errormsg
    23118         print '  ' + fname + ": projection '" + + "' not ready !!"
     23124        print '  ' + fname + ": projection '" + PROJn + "' not ready !!"
    2311923125        print '    available ones:', availproj
    2312023126        quit(-1)
     
    2343623442
    2343723443    # Joining all netCDF files
    23438     allonc = exonc + [onc]
     23444    allonc = [onc] + exonc
     23445    afNs = [ncfile] + extrafiles
    2343923446    allfileNs = {}
    2344023447    for ionc in range(len(allonc)):
    2344123448        onc = allonc[ionc]
    23442         allfileNs[onc.filepath] = [onc.dimensions.keys(), onc.variables.keys()]
     23449        allfileNs[afNs[ionc]] = [onc.dimensions.keys(), onc.variables.keys()]
    2344323450
    2344423451    # Creation of new file name
     
    2347623483        # Axis values from file
    2347723484        if vardimn != 'WRFtime':
    23478             oaxisv = getvar_listonc(vardimn, allloncs)
     23485            oaxisv = getvar_listonc(vardimn, afNs, allonc)
    2347923486        else:
    2348023487            print infmsg
    2348123488            print '    ' + fname + ": creation of variable 'time' from WRF 'Times' !!"
    23482             odimvar = getvar_listonc('Times', allloncs)
     23489            odimvar = getvar_listonc('Times', afNs, allonc)
    2348323490            timewrfv = odimvar[:]
    2348423491            refT = gen.datetimeStr_conversion(gattr['basetime'], 'Y-m-dTH:M:SZ',     \
     
    2359923606        newDim, newVar, newVARv, nonCFproj = projection2D_information(gattr['grid'], \
    2360023607          CFdimvals, pattr, filedimvals['X'].shape[1], filedimvals['X'].shape[0],    \
    23601           alloncs)
     23608          afNs, allonc)
    2360223609
    2360323610    if len(newDim.keys()) > 0:
Note: See TracChangeset for help on using the changeset viewer.