Changeset 2271 in lmdz_wrf for trunk


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
Location:
trunk/tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/module_scientific.f90

    r2270 r2271  
    50255025    INTEGER                                              :: ix, iy, iu, minvalv
    50265026    LOGICAL                                              :: single
     5027    REAL(r_k), ALLOCATABLE, DIMENSION(:)                 :: uniques
     5028
    50275029
    50285030!!!!!!! Variables
     
    50545056      END DO
    50555057    END DO
    5056 
    5057     CALL sortR_K(unique, Nunique)
     5058    IF (ALLOCATED(uniques)) DEALLOCATE(uniques)
     5059    ALLOCATE(uniques(Nunique))
     5060    uniques(1:Nunique) = unique(1:Nunique)
     5061   
     5062    CALL sortR_K(uniques(1:Nunique), Nunique)
     5063    unique(1:Nunique) = uniques(1:Nunique)
    50585064
    50595065  END SUBROUTINE unique_matrixRK2D
     
    51655171        END DO
    51665172      CASE('count')
    5167         CALL unique_matrixRK2D(dxA, dyA, dxA*dyA, varin, Ncounts, icounts)
     5173        CALL unique_matrixRK2D(dxB, dyB, dxB*dyB, varin, Ncounts, icounts)
    51685174        IF (Lstats /= Ncounts) THEN
     5175          PRINT *,'  ' // TRIM(fname) // 'provided:', Lstats
     5176          PRINT *,'  ' // TRIM(fname) // 'found:', Ncounts, ' :', icounts
    51695177          WRITE(val1S,'(I3)')Lstats
    51705178          WRITE(val2S,'(I3)')Ncounts
  • trunk/tools/nc_var.py

    r2247 r2271  
    6767## e.g. # nc_var.py -o compute_slices_stats -S 'XLONG,-74.,-36.,4.;XLAT,-62.,18.,2.;HGT,500.,7000.,500.@Time|Times:west_east|XLONG:south_north|XLAT@Time' -f wrfout_d01_1995-01-01_00:00:00 -v T2,Q2
    6868## e.g. # nc_var.py -o dimrename -f /media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out_irene/simcdx_vars_cape_120lev_cdxwrf2.nc -S Time -v time0
     69## 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
    6970
    7071from optparse import OptionParser
     
    8081# addVar: Operation to add a new variable in a file using exisintg dimensions
    8182# addvals: Function to add values to a given variable at a given dimension
     83# area_weighted: Function to provide an area weighted statistics within two different values
     84#   of matrices assuming regular lon/lat projections without taking into account Earth's curvature
    8285# CDO_toCF: Function to pass a CDO output file to CF-conventions
    8386# CFmorzization: Function to provide a CF-compilation version of a variable within a file
     
    209212# WRF_to_newCF: Function to pass a WRF original file to new CF-conventions file
    210213
    211 operations=['addDim', 'addVar', 'addvals', 'CDO_toCF', 'CFmorzization',              \
    212   'chdimname', 'changevartype',                                                      \
     214operations=['addDim', 'addVar', 'addvals', 'area_weighted', 'CDO_toCF',              \
     215  'CFmorzization', 'chdimname', 'changevartype',                                     \
    213216  'checkallvars', 'checkAllValues', 'checkNaNs',                                     \
    214217  'chgtimestep', 'chvarname', 'cleaning_varsfile', 'compute_deaccum',                \
     
    291294
    292295# Operations which file name is not a real file
    293 NotCheckingFile = ['DatesFiles', 'compute_opersvarsfiles', 'file_creation',          \
     296NotCheckingFile = ['area_weighted', 'DatesFiles', 'compute_opersvarsfiles',          \
     297  'file_creation',                                                                   \
    294298  'join_singlestation_obsfiles', 'join_sounding_obsfiles', 'list_operations',        \
    295299  'merge_files',                                                                     \
     
    327331elif oper == 'addvals':
    328332    ncvar.addvals(opts.values, opts.ncfile, opts.varname)
     333elif oper == 'area_weighted':
     334    ncvar.area_weighted(opts.values, opts.ncfile, opts.varname)
    329335elif oper == 'CDO_toCF':
    330336    ncvar.CDO_toCF(opts.ncfile)
  • 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.