Changeset 2308 in lmdz_wrf for trunk


Ignore:
Timestamp:
Jan 31, 2019, 3:38:37 PM (6 years ago)
Author:
lfita
Message:

Working!!
Adding:

  • `compute_slices_stats_areaweighted': Function to compute stats of variables of a file splitting variables by slices along sets of ranges for a series of variables weighting by the area covered by each grid (defined as polygon) within the slice
Location:
trunk/tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/module_scientific.f90

    r2304 r2308  
    57195719          END DO
    57205720
    5721           IF (s1 == ss1 .AND. s2 == ss2 .AND. s3 == ss3) THEN
    5722             PRINT *, ' Lluis FOR Nin:', Nin
    5723             PRINT *, ' Lluis FOR values:', vin(:,ii3)
    5724             DO iv=1, Nin
    5725               PRINT *,' c:', iv, ':', gin(iv,:), ' p:', pin(iv)
    5726             END DO
    5727           END IF
    5728 
    57295721          ! Computing along d3
    57305722          DO i3=1, di3
  • trunk/tools/nc_var.py

    r2287 r2308  
    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
     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@west_east|lon_bnds,south_north|lat_bnds@XLONG|lat_bnds;lon_bnds,XLAT|lat_bnds;lon_bnds@Time' -f /home/lluis/estudios/Andes/space_weighted/wrfout_bnds.nc -v T2,U10,V10,Q2
    7272
    7373from optparse import OptionParser
  • trunk/tools/nc_var_tools.py

    r2305 r2308  
    2647626476    for islc in range(Nslices1):
    2647726477        vvslc = slcvar1[islc,]
    26478         slcv[islc,] = np.where(vvslc, 1, 0)
    26479     newvar = onewnc.createVariable(varn1+'sliced', 'i', tuple(slcdims))
     26478        slcv[islc,] = np.where(vvslc, 1, gen.fillValueI)
     26479    newvar = onewnc.createVariable(varn1+'sliced', 'i', tuple(slcdims),              \
     26480      fill_value=gen.fillValueI)
    2648026481    newvar[:] = slcv[:]
    2648126482    basicvardef(newvar, varn1+'sliced', 'sliced variable ' + varn1, v1u)
     
    2649926500    for islc in range(Nslices2):
    2650026501        vvslc = slcvar2[islc,]
    26501         slcv[islc,] = np.where(vvslc, 1, 0)
    26502     newvar = onewnc.createVariable(varn2+'sliced', 'i', tuple(slcdims))
     26502        slcv[islc,] = np.where(vvslc, 1, gen.fillValueI)
     26503    newvar = onewnc.createVariable(varn2+'sliced', 'i', tuple(slcdims),              \
     26504      fill_value=gen.fillValueI)
    2650326505    newvar[:] = slcv[:]
    2650426506    basicvardef(newvar, varn2+'sliced', 'sliced variable ' + varn2, v2u)
     
    2776927771    if values == 'h':
    2777027772        print fname + '_____________________________________________________________'
    27771         print compute_slices_stats.__doc__
     27773        print compute_slices_stats_areaweighted.__doc__
    2777227774        quit()
    2777327775
     
    2795327955        for islc in range(Nslices):
    2795427956            vvslc =~slcvar[islc,]
    27955             slcv[islc,] = np.where(vvslc, 1, 0)
    27956         newvar = onewnc.createVariable(varn+'sliced', 'i', tuple(slcdims))
     27957            slcv[islc,] = np.where(vvslc, 1, gen.fillValueI)
     27958        newvar = onewnc.createVariable(varn+'sliced', 'i', tuple(slcdims),           \
     27959          fill_value=gen.fillValueI)
    2795727960        newvar[:] = slcv[:]
    2795827961        basicvardef(newvar, varn+'sliced', 'sliced variable ' + varn, vu)
     
    2822828231                  nbvertexmax=dvget)
    2822928232
     28233                # Comming from Fortran (dx, dy) !!!
    2823028234                Ngridsin = Ngridsint.transpose()
    28231                 gridsin = gridsint.transpose()
     28235                gridsin0 = gridsint.transpose()
     28236                gridsin = np.zeros(gridsin0.shape, dtype=int)
     28237                gridsin[0,...] = gridsin0[1,...]
     28238                gridsin[1,...] = gridsin0[0,...]
     28239                gridsin = gridsin - 1
     28240
    2823228241                areas = areast.transpose()
    2823328242                percens = percenst.transpose()
    2823428243
    2823528244                # Remember we are in C-like!
    28236                 gridsin = gridsin - 1
    2823728245
    2823828246                Ngridsinmax = np.max(Ngridsin)
     
    2833528343
    2833628344                if Nt > 0:
     28345                    # Results come from Fortran... (dx, dy)
    2833728346                    gridsin[1,0:Nt,0,islc] = ainds[0:Nt,0]
    2833828347                    gridsin[0,0:Nt,0,islc] = ainds[0:Nt,1]
     
    2848628495
    2848728496    onewnc.sync()
     28497
    2848828498    # Getting full slice
    2848928499    # NOTE: for simplicity let's assume that there is only one slice with bounds !!
     
    2858728597    pnewvar.setncattr('coordinates',' '.join(Spgrid[::-1]))
    2858828598
     28599    jjA = 10
     28600    iiA = 2
     28601    jjB = 0
     28602    iiB = 4
    2858928603    for jA in range(dyA):
    2859028604        for iA in range(dxA):
     
    2861228626
    2861328627    onewnc.sync()
     28628    #onewnc.close()
     28629    #quit()
    2861428630
    2861528631    for islc in range(2,Nnewslcs):
     
    2875828774                        # Let's check
    2875928775                        psum = np.sum(sgpa[0:Nin,jA,iA,jB,iB])
    28760                         if psum != 1.:
    28761                             print warnmsg
    28762                             print '    ' + fname + 'at slide:', jA,iA,jB,iB,         \
    28763                               'percentages do NOT add one !!'
    28764                             print '    Ngrids:', Nin, 'slice area:',                 \
    28765                               aanewvar[jA,iA,jB,iB], 'total sum:', psum
    28766                             #for iv in range(Nin):
    28767                             #    print iv, sgpa[iv,jA,iA,jB,iB]
     28776                        if not np.isnan(psum):
     28777                            if not gen.almost_zero(psum, 1., 4):
     28778                                print warnmsg
     28779                                print '    ' + fname + 'at slide:', jA,iA,jB,iB,     \
     28780                                  'percentages do NOT add one down to 0.0001 !!'
     28781                                print '    Ngrids:', Nin, 'slice area:',             \
     28782                                  aanewvar[jA,iA,jB,iB], 'total sum:', psum
     28783                        else:
     28784                            print errormsg
     28785                            print '  ' + fname + ': grid Nan slice area for final '+ \
     28786                              ' slice:', jA, iA, jB, iB, 'N grids:', Nin,' !!'
     28787                            print '     slice total area:', aanewvar[jA,iA,jB,iB]
     28788                            print '     #grid grid_area grid_percen _______'
     28789                            for iv in range(Nin):
     28790                                print iv, anewvar[iv,jA,iA,jB,iB], sgpa[iv,jA,iA,jB,iB]
     28791                            quit(-1)
    2876828792    onewnc.sync()
    2876928793                     
     
    2878528809    #sint = sin.transpose()
    2878628810    sint0 = sin.transpose()
    28787     ## We are in Fortran thus (dx,dy) and 1st:1 !!!!
     28811    ## We are going to use them in Fortran thus (dx,dy) and 1st:1 !!!!
    2878828812    sint = np.ones((sint0.shape), dtype=np.float)*gen.fillValueF
    2878928813    sint[...,0] = sint0[...,1]
    2879028814    sint[...,1] = sint0[...,0]
     28815    sint = sint + 1
    2879128816    spt = sgpa.transpose()
    2879228817
     
    2879828823    it = 1
    2879928824    slicesvals = []
    28800     print 'Lluis Ndims:', Ndims
    2880128825    idd = 0
    2880228826    for dnn in Ndims:
    2880328827        scvv = slicesinf[dnn.split('_')[1]]
    2880428828        sccvvv = scvv[3]
    28805         print 'sccvvv:', sccvvv
    28806         print 'Lluis dnn:', dnn, sccvvv[chijk[idd]]
    2880728829        slicesvals.append(sccvvv[chijk[idd]])
    2880828830        idd = idd + 1
     
    2885628878        newvardims = vardims + dimsslice
    2885728879        newvarshape = varshape + shapeslice
    28858         print 'Lluis newvardims:', newvardims, 'newvarshape:', newvarshape, 'varv:', varv.shape
    28859         print 'Lluis shapes sint:', sint.shape
    2886028880
    2886128881#        newvarslice = []
     
    2888428904        varvt = None
    2888528905        varvt = varv.transpose()
    28886         print 'vs:', varvt[7, 69, :]
    2888728906        if len(vshape) == 3 and len(sN.shape) == 4:
    2888828907            voutt = fsci.module_scientific.multi_spaceweightstats_in3drk3_slc3v4(    \
     
    2890628925            quit(-1)
    2890728926
    28908         print "Lluis Let's check !!", vout.shape
    28909         print 'i j k it:', i, j, k ,it, 'N:', sN[i,j,k], '<>', slicesvals
    28910         for iv in range(sN[i,j,k]):
    28911             print iv, 'c:', sin[:,iv,i,j,k], 'p:', sgpa[iv,i,j,k], 'v:',             \
    28912               varv[it,sin[0,iv,i,j,k],sin[1,iv,i,j,k]]
    28913         print 'min max mean mean2 std median count _______'
    28914         print vout[:,it,i,j,k]
     28927        #print "Lluis Let's check !!", vout.shape
     28928        #print 'i j k it:', i, j, k ,it, 'N:', sN[i,j,k], '<>', slicesvals
     28929        #for iv in range(sN[i,j,k]):
     28930        #    print iv, 'c:', sin[:,iv,i,j,k], 'p:', sgpa[iv,i,j,k], 'v:',             \
     28931        #      varv[it,sin[0,iv,i,j,k],sin[1,iv,i,j,k]]
     28932        #print 'min max mean mean2 std median count _______'
     28933        #print vout[:,it,i,j,k]
    2891528934
    2891628935        ist = 0
    2891728936        for statn in statns:
    2891828937            newvar = onewvars[statn]
    28919             print 'Lluis stn:', statn, 'shape:', newvar.shape
    2892028938            rightvals = np.where(vout[6] == 0, gen.fillValueF, vout[ist])
    2892128939            newvar[:] = rightvals
Note: See TracChangeset for help on using the changeset viewer.