In [1]:
import pyart
import numpy as np
import numpy.ma as ma
import glob

In [2]:
# dowPath = '/Users/danstechman/GoogleDrive/PECAN-Data/samurai/20150706/S3P6_D7D8_fsdabr/runDir/dow7/'
# dowPath = '/Users/danstechman/GoogleDrive/PECAN-Data/samurai/20150706/S3P6_D7D8_fsdabr/runDir/dow8/'
dowPath = '/data/pecan/a/stechma2/pecan/radar-data/20150706/DOW7_high/sweeps_/'

files = glob.glob(dowPath + '*.nc')

In [3]:
i = 1
for file in files:

    print('Working on file {} of {}...'.format(i,len(files)))
    radar = pyart.io.read(file)
    
    DBZqc = radar.fields['DBZqc']['data']
    VGqc = radar.fields['VGqc']['data']
    WIDTH = radar.fields['WIDTH']['data']
    
    dbzMod = ma.copy(DBZqc)
    vgMod = ma.copy(VGqc)
    widthMod = ma.copy(WIDTH)
    
    dbzMod[::2,:] = ma.masked
    vgMod[::2,:] = ma.masked
    widthMod[::2,:] = ma.masked

    gateAvg = 3
    midGate = int(gateAvg/2)
    for ray in range(1,dbzMod.shape[0],2):
        for gate in range(0,dbzMod.shape[1],gateAvg):
            if gate+gateAvg > dbzMod.shape[1]:
                gateAvg = dbzMod.shape[1] - gate
                midGate = int(gateAvg/2)
#                 print('gateAvg = {}\nmidGate = {}'.format(gateAvg,midGate))
            
            dbzMod[ray,gate+midGate] = ma.average(dbzMod[ray,gate:gate+gateAvg])
            vgMod[ray,gate+midGate] = ma.average(vgMod[ray,gate:gate+gateAvg])
            widthMod[ray,gate+midGate] = ma.average(widthMod[ray,gate:gate+gateAvg])

            crntSlice = np.arange(gate,gate+gateAvg)
            excld = [n for n in crntSlice if n != gate+midGate]
            dbzMod[ray,excld] = ma.masked
            vgMod[ray,excld] = ma.masked
            widthMod[ray,excld] = ma.masked
    
    radar.add_field_like('DBZqc','DBZqc',dbzMod,replace_existing=True)
    radar.add_field_like('VGqc','VGqc',vgMod,replace_existing=True)
    radar.add_field_like('WIDTH','WIDTH',widthMod,replace_existing=True)
    
    newFN = file[:-3] + '_mod.nc'
    pyart.io.write_cfradial(newFN,radar)
    
    i += 1


Working on file 1 of 28...
gateAvg = 2
midGate = 1
Working on file 2 of 28...
gateAvg = 2
midGate = 1
Working on file 3 of 28...
gateAvg = 2
midGate = 1
Working on file 4 of 28...
gateAvg = 2
midGate = 1
Working on file 5 of 28...
gateAvg = 2
midGate = 1
Working on file 6 of 28...
gateAvg = 2
midGate = 1
Working on file 7 of 28...
gateAvg = 2
midGate = 1
Working on file 8 of 28...
gateAvg = 2
midGate = 1
Working on file 9 of 28...
gateAvg = 2
midGate = 1
Working on file 10 of 28...
gateAvg = 2
midGate = 1
Working on file 11 of 28...
gateAvg = 2
midGate = 1
Working on file 12 of 28...
gateAvg = 2
midGate = 1
Working on file 13 of 28...
gateAvg = 2
midGate = 1
Working on file 14 of 28...
gateAvg = 2
midGate = 1
Working on file 15 of 28...
gateAvg = 2
midGate = 1
Working on file 16 of 28...
gateAvg = 2
midGate = 1
Working on file 17 of 28...
gateAvg = 2
midGate = 1
Working on file 18 of 28...
gateAvg = 2
midGate = 1
Working on file 19 of 28...
gateAvg = 2
midGate = 1
Working on file 20 of 28...
gateAvg = 2
midGate = 1
Working on file 21 of 28...
gateAvg = 2
midGate = 1
Working on file 22 of 28...
gateAvg = 2
midGate = 1
Working on file 23 of 28...
gateAvg = 2
midGate = 1
Working on file 24 of 28...
gateAvg = 2
midGate = 1
Working on file 25 of 28...
gateAvg = 2
midGate = 1
Working on file 26 of 28...
gateAvg = 2
midGate = 1
Working on file 27 of 28...
gateAvg = 2
midGate = 1
Working on file 28 of 28...
gateAvg = 2
midGate = 1