Changeset 2287 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jan 24, 2019, 5:10:19 PM (7 years ago)
Author:
lfita
Message:

Getting there with the `compute_slices_stats_areaweighted'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var.py

    r2272 r2287  
    6969## e.g. # nc_var.py -o area_weighted -f 'reference_data.nc:lon;lon;lon_bnds;-1;lat;lat;lat_bnds;-1,get_data.nc:lon;lon;lon_bnds;-1;lat;lat;lat_bnds;-1' -S 'yes:min,max,mean,stddev,count' -v ct_values,xband_values,box_values,mosaic_values
    7070## e.g. # nc_var.py -o area_weighted -f '/media/lluis/ExtDiskC_ext4/bkup/llamp/estudios/dominios/SA150k/geo_em.d01.nc:west_east;XLONG_M;WRFxbnds;-1;south_north;XLAT_M;WRFybnds;-1,/media/lluis/ExtDiskC_ext4/bkup/llamp/estudios/dominios/SA50k/geo_em.d01.nc:west_east;XLONG_M;WRFxbnds;-1;south_north;XLAT_M;WRFybnds;-1' -S 'no:mean' -v HGT_M
     71## e.g. # nc_var.py -o compute_slices_stats_areaweighted -S 'XLONG,-74.,-36.4,4.;XLAT,-63.,19.,4.;HGT,500.,7000.,500.@Time|WRFtime:west_east|XLONG:south_north|XLAT@Time@south_north|lat_bnds,west_east|lon_bnds@Time' -f /home/lluis/PY/wrfout_d01_1995-01-01_00:00:00 -V T2
    7172
    7273from optparse import OptionParser
     
    100101# compute_slices_stats: Function to compute stats of variables of a file splitting variables by
    101102#   slices along sets of ranges for a series of variables
     103# compute_slices_stats_areaweighted: Function to compute stats of variables of a file splitting variables by
     104#   slices along sets of ranges for a series of variables weighting by the area
     105#   covered by each grid (defined as polygon) within the slice
    102106# compute_slice2Dstats: Function to compute stats of variables of a file following slices along 2 variables
    103107# compute_tevolboxtraj: Function to compute tevolboxtraj: temporal evolution at a given point along a box following a trajectory
     
    219223  'compute_opersvarsfiles',                                                          \
    220224  'compute_opervaralltime', 'compute_opervartimes', 'compute_slices_stats',          \
    221   'compute_slice2Dstats',                                                            \
     225  'compute_slices_stats_areaweighted', 'compute_slice2Dstats',                       \
    222226  'compute_tevolboxtraj',                                                            \
    223227  'computevar_model', 'curve_section', 'DatesFiles',                                 \
     
    364368elif oper == 'compute_slices_stats':
    365369    ncvar.compute_slices_stats(opts.values, opts.ncfile, opts.varname)
     370elif oper == 'compute_slices_stats_areaweighted':
     371    ncvar.compute_slices_stats_areaweighted(opts.values, opts.ncfile, opts.varname)
    366372elif oper == 'compute_slice2Dstats':
    367373    ncvar.compute_slice2Dstats(opts.values, opts.ncfile, opts.varname)
  • trunk/tools/nc_var_tools.py

    r2284 r2287  
    5252#   slices along sets of ranges for a series of variables
    5353# compute_slice2Dstats: Function to compute stats of variables of a file following slices along 2 variables
     54# compute_slices_stats: Function to compute stats of variables of a file splitting variables by
     55#   slices along sets of ranges for a series of variables
     56# compute_slices_stats_areaweighted: Function to compute stats of variables of a file splitting variables by
     57#   slices along sets of ranges for a series of variables weighting by the area
     58#   covered by each grid (defined as polygon) within the slice
    5459# computevar_model: Function to provide the way to compute a CF-variable providing its name
    5560# compute_tevolboxtraj: Function to compute tevolboxtraj: temporal evolution at a given point along a box following a trajectory
     
    2789827903        newvar[:] = slcvalsc[:]
    2789927904        basicvardef(newvar, 'slice_'+varn, 'slices for variable ' + varn, vu)
     27905        onewnc.sync()
    2790027906
    2790127907        newvar = onewnc.createVariable('slice_'+varn+'_bnds', 'f', ('slice_'+varn,  \
     
    2790427910        basicvardef(newvar, 'slice_'+varn+'_bnds', 'boundaries of slices for ' +     \
    2790527911          'variable ' + varn, vu)
     27912        onewnc.sync()
    2790627913
    2790727914        slcdims = ['slice_'+varn] + rmdims
     
    2792027927    vardimbndslice = {}
    2792127928
     27929    print 'Lluis slcvarns:', slcvarns
     27930    newslcvarns = []
    2792227931    for varn in slcvarns:
    2792327932        ovar = onc.variables[varn]
    2792427933        vu = ovar.units
    2792527934        dimnv = list(ovar.dimensions)
    27926         dv = ovar[:]
    27927 
    27928         print 'varn:', varn, ' dims:', dimnv
     27935
     27936        # Removing undesired dimensions from slicing variable
     27937        if sliceremovedim is not None:
     27938            print infmsg
     27939            print '  ' + fname + ": removing dimension '", sliceremovedim,           \
     27940              "' from slice ..."
     27941            dv, rmdims, rmshape = ovar_reducedims(ovar, sliceremovedim)
     27942        else:
     27943            dv = ovar[:]
     27944            rmdims = dimnv
     27945            rmshape = list(ovar.shape)
    2792927946
    2793027947        dimbnds = []
    27931         for dn in dimnv:
     27948        for dn in rmdims:
    2793227949            if slicebndsdim.has_key(dn): dimbnds.append(dn)
    2793327950
     
    2795327970                ovarbnds = onc.variables[slicebndsdim[dn]]
    2795427971
    27955                 # Removing undesired dimensions from slicing variable
     27972                # Removing undesired dimensions from bounds slicing variable
    2795627973                if sliceremovedim is not None:
    2795727974                    varv, rmdims, rmshape = ovar_reducedims(ovarbnds, sliceremovedim)
     
    2796227979
    2796327980                dimvbnds[dn] = varv
    27964                 dimvdnds[dn] = rmdims
    27965                 dimvsnds[dn] = rmshape
    27966 
    27967             if gen.searchInlist(slcvarns, dn) and not vardimbndslice.has_key(dn):
     27981                dimdbnds[dn] = rmdims
     27982                dimsbnds[dn] = rmshape
     27983
     27984            dn = '_'.join(slicebndsdim)
     27985            if not gen.searchInlist(slcvarns, dn) and not                            \
     27986              gen.searchInlist(newslcvarns, dn) and not vardimbndslice.has_key(dn):
    2796827987                if len(dv.shape) == 1:
    2796927988                    print infmsg
     
    2801228031                    dxget = dd
    2801328032                    dyget = 1
     28033                    dvref = 4
     28034                    dvget = 4
     28035
     28036                    # Values for file
     28037                    dref = [dn]
     28038                    sref = [dxref]
     28039                    dget = [dn]
     28040                    sget = [dxget]
    2801428041       
    2801528042                elif len(dv.shape) == 2:
    28016                     xdim = rmdims[1]
    28017                     ydim = rmdims[0]
    28018                     getdims = dimvsnds[xdim]
     28043                    print "  2D slicing  bounded variable: '" + varn + "': ", dv.shape
     28044                    xdim = rmdims[2]
     28045                    ydim = rmdims[1]
     28046                    getdims = dimdbnds[xdim]
     28047
    2801928048                    # ref values
    28020                     if slicesinf.has_key(getdims[1]):
    28021                         varslcv = slicesinf[getdims[1]]
     28049                    if slicesinf.has_key(dimvars[getdims[2]]):
     28050                        varslcv = slicesinf[dimvars[getdims[2]]]
    2802228051                        dxref = varslcv[0]
    28023                         reflon1D = varslcv[4]
     28052                        reflon1D = varslcv[3]
     28053                        refblon1D = varslcv[4]
    2802428054                    else:
    2802528055                        print infmsg
    2802628056                        print '  ' + fname + ": 2D slicing varibale '" + varn +      \
    28027                           "' with x-dimension '" + getdims[1] + "' without related "+\
    28028                           " slicing-variable !!"
    28029                         quit(-1)
    28030                     if slicesinf.has_key(getdims[0]):
    28031                         varslcv = slicesinf[getdims[0]]
     28057                          "' with x-dimension '" +dimvars[getdims[2]]+ "' without "+ \
     28058                          "related slicing-variable !!"
     28059                        oxvar = onc.variables[dimvars[getdims[2]]]
     28060
     28061                        # Removing undesired dimensions from bounds slicing variable
     28062                        if sliceremovedim is not None:
     28063                            xvar, rmd, rms = ovar_reducedims(oxvar, sliceremovedim)
     28064                        else:
     28065                            xvar = oxvar[:]
     28066                            rmd = oxvar.dimensions
     28067                            rms = list(oxvar.shape)
     28068
     28069                        xn = np.min(xvar)
     28070                        xx = np.max(xvar)
     28071                        dxref = 1
     28072                        reflon1D = xvar
     28073                        refblon1D = np.array([xn, xx])
     28074                        print '    using variable extremes instead: ',reflon1D
     28075
     28076                    if slicesinf.has_key(dimvars[getdims[1]]):
     28077                        varslcv = slicesinf[dimvars[getdims[1]]]
    2803228078                        dyref = varslcv[0]
    28033                         reflat1D = varslcv[4]
     28079                        reflat1D = varslcv[3]
     28080                        refblat1D = varslcv[4]
    2803428081                    else:
    2803528082                        print infmsg
    2803628083                        print '  ' + fname + ": 2D slicing varibale '" + varn +      \
    28037                           "' with y-dimension '" + getdims[0] + "' without related "+\
    28038                           " slicing-variable !!"
    28039                         quit(-1)
     28084                          "' with y-dimension '" +dimvars[getdims[1]]+ "' without " +\
     28085                          "related slicing-variable !!"
     28086                        oyvar = onc.variables[dimvars[getdims[1]]]
     28087
     28088                        # Removing undesired dimensions from bounds slicing variable
     28089                        if sliceremovedim is not None:
     28090                            yvar, rmd, rms = ovar_reducedims(oyvar, sliceremovedim)
     28091                        else:
     28092                            yvar = oyvar[:]
     28093                            rmd = oyvar.dimensions
     28094                            rms = list(oxvar.shape)
     28095
     28096                        yn = np.min(yvar)
     28097                        yx = np.max(yvar)
     28098                        dyref = 1
     28099                        reflat1D = yvar
     28100                        refblat1D = np.array([yn, yx])
     28101                        print '    using variable extremes instead: ',reflat1D
    2804028102                    # Slicing following boundaries, dimensions are 1D thus expand to
    2804128103                    #    2D filling as NW, NE, SE, SW
     
    2804328105                    reflon = np.zeros((dyref,dxref), dtype=np.float)
    2804428106                    reflat = np.zeros((dyref,dxref), dtype=np.float)
    28045                     xslice2D = np.zeros((4,dyref,dxref), dtype=np.float)
    28046                     yslice2D = np.zeros((4,dyref,dxref), dtype=np.float)
     28107                    dvref = 4
     28108                    xslice2D = np.zeros((dvref,dyref,dxref), dtype=np.float)
     28109                    yslice2D = np.zeros((dvref,dyref,dxref), dtype=np.float)
    2804728110                    for j in range(dyref):
    2804828111                        for i in range(dxref):
    28049                             reflon[j,i] = slcvalsc
    28050                             reflat[j,i] = slcvalsc
    28051                             xslice2D[0,j,i] = reflon1D[i,0]
    28052                             xslice2D[1,j,i] = reflon1D[i,1]
    28053                             xslice2D[2,j,i] = reflon1D[i,1]
    28054                             xslice2D[3,j,i] = reflon1D[i,0]
    28055                             yslice2D[0,j,i] = reflat1D[j,1]
    28056                             yslice2D[1,j,i] = reflat1D[j,1]
    28057                             yslice2D[2,j,i] = reflat1D[j,0]
    28058                             yslice2D[3,j,i] = reflat1D[j,0]
     28112                            reflon[j,i] = reflon1D[i]
     28113                            reflat[j,i] = reflat1D[j]
     28114                            xslice2D[0,j,i] = refblon1D[i,0]
     28115                            xslice2D[1,j,i] = refblon1D[i,1]
     28116                            xslice2D[2,j,i] = refblon1D[i,1]
     28117                            xslice2D[3,j,i] = refblon1D[i,0]
     28118                            yslice2D[0,j,i] = refblat1D[j,1]
     28119                            yslice2D[1,j,i] = refblat1D[j,1]
     28120                            yslice2D[2,j,i] = refblat1D[j,0]
     28121                            yslice2D[3,j,i] = refblat1D[j,0]
    2805928122
    2806028123                    # get values
    28061                     if dimvars.has_key(getdims[1]): getlon = dimvars[getdims[1]]
     28124                    if dimvars.has_key(getdims[2]):
     28125                        ogetlon = onc.variables[dimvars[getdims[2]]]
     28126                        # Removing undesired dimensions from bounds slicing variable
     28127                        if sliceremovedim is not None:
     28128                            getlon, rmd, rms = ovar_reducedims(ogetlon, sliceremovedim)
     28129                        else:
     28130                            getlon = ogetlon[:]
     28131                            rmd = ogetlon.dimensions
     28132                            rms = list(ogetlon.shape)
    2806228133                    else:
    2806328134                        print infmsg
    28064                         print '  ' + fname + ": 2D slicing varibale '" + varn +      \
    28065                           "' with x-dimension '" + getdims[1] + "' without related "+\
     28135                        print '  ' + fname + ": 2D bounded varibale '" + varn +      \
     28136                          "' with x-dimension '" + getdims[2] + "' without related "+\
    2806628137                          " dimension-variable !!"
    2806728138                        quit(-1)
    28068                     if dimvars.has_key(getdims[0]): getlat = dimvars[getdims[0]]
     28139                    if dimvars.has_key(getdims[1]):
     28140                        ogetlat = onc.variables[dimvars[getdims[1]]]
     28141                        # Removing undesired dimensions from bounds slicing variable
     28142                        if sliceremovedim is not None:
     28143                            getlat, rmd, rms = ovar_reducedims(ogetlat, sliceremovedim)
     28144                        else:
     28145                            getlat = ogetlat[:]
     28146                            rmd = ogetlat.dimensions
     28147                            rms = list(ogetlat.shape)
    2806928148                    else:
    2807028149                        print infmsg
    28071                         print '  ' + fname + ": 2D slicing varibale '" + varn +      \
    28072                           "' with y-dimension '" + getdims[0] + "' without related "+\
     28150                        print '  ' + fname + ": 2D bounded varibale '" + varn +      \
     28151                          "' with y-dimension '" + getdims[1] + "' without related "+\
    2807328152                          " dimension-variable !!"
    2807428153                        quit(-1)
    2807528154
    28076                     getshape = dimvsnds[xdim]
    28077                     dxget = getshape[1]
    28078                     dyget = getshape[0]
     28155                    getshape = dimsbnds[xdim]
     28156                    dxget = getshape[2]
     28157                    dyget = getshape[1]
     28158                    dvget = getshape[0]
    2807928159                    xdimvarbnds2D = dimvbnds[xdim]
    2808028160                    ydimvarbnds2D = dimvbnds[ydim]
    2808128161
    28082                     reflon = np.zeros((1,Nslices), dtype=np.float)
    28083                     reflon[0,:] = slcvalsc
    28084                     reflat = np.zeros((1,Nslices), dtype=np.float)
    28085                     xslice2D = np.zeros((4,1,Nslices), dtype=np.float)
    28086                     xslice2D[0,0,:] = slcvals[:,1]
    28087                     xslice2D[1,0,:] = slcvals[:,1]
    28088                     xslice2D[2,0,:] = slcvals[:,0]
    28089                     xslice2D[3,0,:] = slcvals[:,0]
    28090                     yslice2D = np.zeros((4,1,Nslices), dtype=np.float)
    28091                     yslice2D[0,0,:] = -1.
    28092                     yslice2D[1,0,:] = 1.
    28093                     yslice2D[2,0,:] = 1.
    28094                     yslice2D[3,0,:] = -1.
    28095    
    28096                     dd = len(onc.dimensions[dn])
    28097                     getlon = np.zeros((1,dd), dtype=np.float)
    28098                     getlon[0,:] = dv
    28099                     getlat = np.zeros((1,dd), dtype=np.float)
    28100                     xdimvarbnds2D = np.zeros((4,1,dd), dtype=np.float)
    28101                     xdimvarbnds2D[0,0,:] = ovarbnds[:,1]
    28102                     xdimvarbnds2D[1,0,:] = ovarbnds[:,1]
    28103                     xdimvarbnds2D[2,0,:] = ovarbnds[:,0]
    28104                     xdimvarbnds2D[3,0,:] = ovarbnds[:,0]
    28105                     ydimvarbnds2D = np.zeros((4,1,dd), dtype=np.float)
    28106                     ydimvarbnds2D[0,0,:] = -1.
    28107                     ydimvarbnds2D[1,0,:] = 1.
    28108                     ydimvarbnds2D[2,0,:] = 1.
    28109                     ydimvarbnds2D[3,0,:] = -1.
    28110 
    28111                     dxref = Nslices
    28112                     dyref = 1
    28113                     dxget = dd
    28114                     dyget = 1
    28115 
    28116                     dimvar2D.append(dn)
    28117                     continue
     28162                    # Values for file
     28163                    dref = [dimvars[getdims[1]], dimvars[getdims[2]]]
     28164                    sref = [dyref, dxref]
     28165                    dget = [getdims[1], getdims[2]]
     28166                    sget = [dyget, dxget]
     28167
    2811828168                # Issue with WRF's XLONG(time, sout_north, west_east) ....
    2811928169                else:
     
    2813828188                  xcbvals=getlont, ycbvals=getlatt, xbbvals=getvarxbndst,            \
    2813928189                  ybbvals=getvarybndst, strict=False, dxa=dxref, dya=dyref,          \
    28140                   navertexmax=4, dxb=dxget, dyb=dyget, dxyb=dxget*dyget,             \
    28141                   nbvertexmax=4)
     28190                  navertexmax=dvref, dxb=dxget, dyb=dyget, dxyb=dxget*dyget,         \
     28191                  nbvertexmax=dvget)
    2814228192
    2814328193                Ngridsin = Ngridsint.transpose()
     
    2814728197                Ngridsinmax = np.max(Ngridsin)
    2814828198        else:
     28199            # Here is only done by 1D variables !!!
    2814928200            print infmsg
    2815028201            print '  ' + fname + ": slicing variable '" + dn + "' without bounds !!"
     
    2816728218            for islc in range(Nslices):
    2816828219                unmasked = slcvar[islc,]
    28169                 unma = np.where(unmasked, 0., 1.)
     28220                unma = np.where(unmasked, 0., 1)
    2817028221                unmat = unma.transpose()
    2817128222                if (len(unma.shape) == 1):
    28172                   indices = gen.multi_index_mat(unmat,1.)
     28223                  indices = gen.multi_index_mat(unmat,1)
    2817328224                  Nt = len(indices)
    2817428225                elif (len(unma.shape) == 2):
    2817528226                    drng = unma.shape[0]*unma.shape[1]
    28176                     Nt,indices=fsci.module_scientific.multi_index_mat2drk(d12=drng,  \
    28177                       mat=unmat, value=1., d1=unma.shape[1], d2=unma.shape[0])
     28227                    Nt,indices=fsci.module_scientific.multi_index_mat2di(d12=drng,   \
     28228                      mat=unmat, value=1, d1=unma.shape[1], d2=unma.shape[0])
    2817828229                elif (len(unma.shape) == 3):
    2817928230                    drng = unma.shape[0]*unma.shape[1]*unma.shape[2]
    28180                     Nt,indices=fsci.module_scientific.multi_index_mat3drk(d123=drng, \
    28181                       mat=unmat, value=1., d1=unma.shape[2], d2=unma.shape[1],       \
     28231                    Nt,indices=fsci.module_scientific.multi_index_mat3di(d123=drng, \
     28232                      mat=unmat, value=1, d1=unma.shape[2], d2=unma.shape[1],        \
    2818228233                      d3=unma.shape[0])
    2818328234                elif (len(unma.shape) == 4):
    2818428235                    drng = unma.shape[0]*unma.shape[1]*unma.shape[2]*unma.shape[3]
    28185                     Nt,indices=fsci.module_scientific.multi_index_mat4drk(d1234=drng,\
    28186                       mat=unmat, value=1., d1=unma.shape[3], d2=unma.shape[2],       \
     28236                    Nt,indices=fsci.module_scientific.multi_index_mat4di(d1234=drng, \
     28237                      mat=unmat, value=1, d1=unma.shape[3], d2=unma.shape[2],        \
    2818728238                      d3=unma.shape[1], d4=unma.shape[0])
    2818828239                else:
    2818928240                  rS = str(len(unma.shape))
    2819028241                  print errormsg
    28191                   print '  ' + fname + ": 'multi_index_mat" + rS + "drk' not ready !!"
     28242                  print '  ' + fname + ": 'multi_index_mat" + rS + "di' not ready !!"
    2819228243                  quit(-1)
    2819328244
     
    2819928250
    2820028251        # Let's avoid memory issues...
     28252        newslcvarns.append(dn)
    2820128253        lvalues = [Ngridsin, gridsin, percens]
    2820228254        vardimbndslice[dn] = lvalues
    28203 
    28204         # Writting it to the file variables space-weight
    28205         if not gen.searchInlist(onewnc.dimensions, dn+'slice'):
    28206             newdim = onewnc.createDimension(dn+'slice',Nslices)
    28207             newdim = onewnc.createDimension(dn+'bnds',4)
    28208             newdim = onewnc.createDimension(dn+'gridin',Ngridsinmax)
    28209         if not gen.searchInlist(onewnc.dimensions, 'coord'):
    28210             newdim = onewnc.createDimension('coord',2)
    28211 
    28212         newvar = onewnc.createVariable(dn+'Ngrid','i',(dn+'slice'))
    28213 
    28214         newvar[:] = Ngridsin[:]
    28215         basicvardef(newvar, dn+'Ngrid', "number of grids cells from " +     \
    28216           ".get. laying within .ref.", '-')
    28217         newvar.setncattr('coordinates',dn)
    28218 
    28219         innewvar = onewnc.createVariable(dn+'gridin', 'i', ('coord',         \
    28220           dn+'gridin',dn+'slice'))
    28221         basicvardef(innewvar, dn+'gridin', "coordinates of the grids " +     \
    28222           "cells from .get. laying within .ref.",'-')
    28223         innewvar.setncattr('coordinates',dn+'slice')
     28255        if not onewnc.variables.has_key(dn+'gridin'):
     28256
     28257            # Writting it to the file variables space-weight
     28258            Srgrid = []
     28259            Scgrid = []
     28260            Sigrid = ['coord', dn+'gridin']
     28261            Spgrid = [dn+'gridin']
     28262            iid = 0
     28263            for dnn in dref:
     28264                if not gen.searchInlist(onewnc.dimensions, 'slice_' + dnn):
     28265                   newdim = onewnc.createDimension('slice_' + dnn,sref[iid])
     28266
     28267                if not gen.searchInlist(onewnc.dimensions, dnn+'bnds'):
     28268                   newdim = onewnc.createDimension(dnn+'bnds',4)
     28269                Srgrid.append('slice_' + dnn)
     28270                Scgrid.append('slice_' + dnn)
     28271                Sigrid.append('slice_' + dnn)
     28272                Spgrid.append('slice_' + dnn)
     28273                iid = iid + 1
     28274            if not gen.searchInlist(onewnc.dimensions, dn+'gridn'):
     28275                newdim = onewnc.createDimension(dn+'gridin',Ngridsinmax)
     28276            if not gen.searchInlist(onewnc.dimensions, 'coord'):
     28277                newdim = onewnc.createDimension('coord',2)
     28278
     28279            newvar = onewnc.createVariable(dn+'Ngrid','i', tuple(Srgrid))
     28280            newvar[:] = Ngridsin[:]
     28281            basicvardef(newvar, dn+'Ngrid', "number of grids cells from " +          \
     28282              ".get. laying within .ref.", '-')
     28283            newvar.setncattr('coordinates',' '.join(Scgrid[::-1]))
     28284   
     28285            innewvar = onewnc.createVariable(dn+'gridin', 'i', tuple(Sigrid))
     28286            basicvardef(innewvar, dn+'gridin', "coordinates of the grids " +         \
     28287              "cells from .get. laying within .ref.",'-')
     28288            innewvar.setncattr('coordinates',' '.join(Scgrid[::-1]))
    2822428289       
    28225         pnewvar = onewnc.createVariable(dn+'gridpercen','f',(dn+'gridin',    \
    28226           dn+'slice'))
    28227         basicvardef(pnewvar ,dn+'gridpercen', "percentages of the " +        \
    28228          "grids cells from .get. laying within .ref.", '1')
    28229         pnewvar.setncattr('coordinates',dn)
    28230         for j in range(1):
    28231            for i in range(Nslices):
    28232                 innewvar[:,0:Ngridsin[j,i],i] = gridsin[:,0:Ngridsin[j,i],j,i]
    28233                 pnewvar[0:Ngridsin[j,i],i]= percens[0:Ngridsin[j,i],j,i]
    28234         onewnc.sync()
    28235 
    28236 #    # Slicing 2D dimension-variables
    28237 #    if len(dimvar2D) != 0:
    28238 #        ovar = onc.variables[varn]
    28239 #        vu = ovar.units
    28240 #        dimnv = list(ovar.dimensions)
    28241 
    28242 #        varbndns = []
    28243 #        dimvals = {}
    28244 #        dimslcs = {}
    28245 #        for dn in dimnv:
    28246 #            # Looking for boundaries
    28247 #            varbnds = []
    28248 #            dn = varn
    28249 #            vdarattrs = ovar.ncattrs()
    28250 #            dv = ovar[:]
    28251 
    28252 #            if gen.searchInlist(vdarattrs,'bounds'):
    28253 #                boundsv = ovar.getncattr('bounds')
    28254 #                print '    ' + infmsg
    28255 #                print '    ' +fname+ ": slicing variable '" +dn+ "' with bounds !!"
    28256 #                print '      bounds found:', boundsv
    28257 #                print '      getting them to retrieve the slices'
    28258 #                bndvarns = boundsv.replace(' ','').split(',')
    28259 
    28260 #                for vn in bndvarns:
    28261 #                    if not gen.searchInlist(varbnds, vn): varbnds.append(vn)
    28262                
    28263 #        # Slicing following boundaries
    28264 #        if gen.searchInlist(slcvarns, dn) and not vardimbndslice.has_key(dn):
    28265 #            print infmsg
    28266 #            print '    ' + fname + ": slicing dimension '" + dn + "' ... "
    28267 #            varslcv = slicesinf[dn]
    28268 #            Nslices = varslcv[0]
    28269 #            ovardims = varslcv[1]
    28270 #            slcvar = varslcv[2]
    28271 #            slcvalsc = varslcv[3]
    28272 #            slcvals = varslcv[4]
    28273 #            dimslcs[dn] = slcvals       
    28274 
    28275 #         if len(varbndns) != 0:
    28276 #             for boundsv in varbnds:
    28277 #                ovarbnds = onc.variables[boundsv]
    28278 #                varbnds = ovarbnds[:]
    28279 #                dimvals[
    28280 
    28281 
     28290            pnewvar = onewnc.createVariable(dn+'gridpercen','f',tuple(Spgrid))
     28291            basicvardef(pnewvar ,dn+'gridpercen', "percentages of the " +            \
     28292             "grids cells from .get. laying within .ref.", '1')
     28293            pnewvar.setncattr('coordinates',' '.join(Scgrid[::-1]))
     28294
     28295            if len(dv.shape) == 1:
     28296                for j in range(1):
     28297                   for i in range(Nslices):
     28298                        innewvar[:,0:Ngridsin[j,i],i] =                              \
     28299                          gridsin[:,0:Ngridsin[j,i],j,i]
     28300                        pnewvar[0:Ngridsin[j,i],i]= percens[0:Ngridsin[j,i],j,i]
     28301            elif len(dv.shape) == 2:
     28302                for j in range(dyref):
     28303                   for i in range(dxref):
     28304                        innewvar[:,0:Ngridsin[j,i],j,i] =                            \
     28305                          gridsin[:,0:Ngridsin[j,i],j,i]
     28306                        pnewvar[0:Ngridsin[j,i],j,i]= percens[0:Ngridsin[j,i],j,i]
     28307   
     28308            onewnc.sync()
     28309
     28310    slcvarns = slcvarns + newslcvarns
    2828228311
    2828328312    for varn in varns:
     
    2858428613    return
    2858528614
    28586 #values='lon,286.,323.6,4.;lat,-63.,19.,4.;orog,250.,7000.,500.@time|time:lon|lon:lat|lat@time'
     28615#values='lon,286.,323.6,4.;lat,-63.,19.,4.;orog,500.,7000.,500.@time|time:lon|lon:lat|lat@time'
    2858728616#compute_slices_stats_areaweighted(values, '/media/lluis/ExtDiskC_ext3/DATA/estudios/Andes/DATA/concatenated/historical/tasmin/tasmin_Amon_ACCESS1-0_historical_r1i1p1_185001-200512_Andes_19600101000000-19900101000000.nc', 'tasmin')
    28588 values='XLONG,-74.,-36.4,4.;XLAT,-63.,19.,4.;HGT,250.,7000.,500.@Time|WRFtime:' +    \
    28589   'west_east|XLONG:south_north|XLAT@Time@south_north|lat_bnds,west_east|lon_bnds@Time'
    28590 compute_slices_stats_areaweighted(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2')
     28617#values='XLONG,-74.,-36.4,4.;XLAT,-63.,19.,4.;HGT,500.,7000.,500.@Time|WRFtime:' +    \
     28618#  'west_east|XLONG:south_north|XLAT@Time@south_north|lat_bnds,west_east|lon_bnds@Time'
     28619#compute_slices_stats_areaweighted(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2')
    2859128620
    2859228621#quit()
Note: See TracChangeset for help on using the changeset viewer.