Changeset 2271 in lmdz_wrf for trunk/tools/nc_var_tools.py


Ignore:
Timestamp:
Dec 27, 2018, 8:46:52 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `area_weighted': Function to provide an area weighted statistics within two different values of matrices assuming regular lon/lat projections without taking into account Earth's curvature
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r2270 r2271  
    2828# addVar: Operation to add a new variable in a file using exisintg dimensions
    2929# addvals: Function to add values to a given variable at a given dimension
     30# area_weighted: Function to provide an area weighted statistics within two different values
     31#   of matrices assuming regular lon/lat projections without taking into account Earth's curvature
    3032# attrinvar: Check existence of an attribute in a netCDF variable object
    3133# basicvardef: Function to give the basic attributes to a variable (std_name, long_name, units)
     
    2722227224        quit()
    2722327225
    27224     statsavail = ['mean', 'min', 'max', 'mean2', 'stddev']
     27226    statsavail = ['mean', 'min', 'max', 'mean2', 'stddev', 'count']
    2722527227    # Characteristics of the statistics
    2722627228    statnschars = {'mean': ['spcmean', 'spatial mean', 1],                           \
     
    2723827240
    2723927241    for stn in statns:
    27240         if not gen.searchInlist(statsavail, stn):
     27242        if not gen.searchInlist(statnschars.keys(), stn):
    2724127243            print errormsg
    2724227244            print '  ' + fname + ": statistics '" + stn + "' not ready !!"
    27243             print '    available ones:', statnschar.keys()
     27245            print '    available ones:', statsavail
    2724427246            quit(-1)
    2724527247
     
    2757427576            varns.append(vn)
    2757527577
     27578    varrm = [refvarxn, refvaryn, refvarxbndsn, refvarybndsn, getvarxn, getvaryn,     \
     27579      getvarxbndsn, getvarybndsn]
     27580    for vn in varrm:
     27581        if gen.searchInlist(varns, vn): varns.remove(vn)
     27582
    2757627583    for vn in varns:
    2757727584        print '  ' + fname + ": using '" + vn + "' ..."
     
    2758727594
    2758827595            if stn == 'count':
    27589                 svals = np.unique(varin)
     27596                svals = np.unique(varvals)
    2759027597                statchar[2] = len(svals)
    2759127598
    27592             varout = fsci.module_scientific.spaceweightstats(varin=varvalst,         \
     27599            varoutt = fsci.module_scientific.spaceweightstats(varin=varvalst,        \
    2759327600              ngridsin=Ngridsint, gridsin=gridsint, percentages=percenst,            \
    2759427601              stats=stn, dxa=refdx, dya=refdy, dxb=getdx, dyb=getdy,                 \
    2759527602              maxngridsin=Ngridsinmax, lstats=statchar[2])
    2759627603
    27597             varout = varout.transpose()
     27604            varout = varoutt.transpose()
    2759827605            if statchar[2] == 1:
    2759927606                newvar = onewnc.createVariable(vn + statchar[0], 'f', ('lat','lon'))
     
    2760127608            else:
    2760227609                if stn == 'count':
    27603                     if not gen.searchInlist(onewnc.dimensions, 'count'):
    27604                         newdim = onewnc.createDimension('count', statchar[2])
    27605                         newvar = onewnc.createVariable(vn + 'count', 'f', ('count'))
     27610                    if not gen.searchInlist(onewnc.dimensions, vn+'count'):
     27611                        newdim = onewnc.createDimension(vn+'count', statchar[2])
     27612                        newvar = onewnc.createVariable(vn+'count', 'f', (vn+'count'))
    2760627613                        newvar[:] = svals
    2760727614                        basicvardef(newvar, vn+'count', 'unique .get. values of ' +  \
    2760827615                          vn, ovar.units)
    2760927616
    27610                     newvar = onewnc.createVariable(vn + statchar[0], 'f', ('count', \
     27617                    newvar = onewnc.createVariable(vn+statchar[0], 'f', (vn+'count', \
    2761127618                      'lat','lon'))
    2761227619                    newvar[:] = varout[:]
     
    2762727634    return
    2762827635
    27629 fvals= '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'
    27630 area_weighted('yes:min,max,mean,stddev',fvals,'ct_values')
     27636#fvals= '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'
     27637#area_weighted('yes:min,max,mean,stddev',fvals,'ct_values')
    2763127638
    2763227639
Note: See TracChangeset for help on using the changeset viewer.