示例#1
0
def reflective_boundary():
    from scipy.interpolate import NearestNDInterpolator as npi

    fn_hFacC = pth_data_in + 'hFacC.data'
    try:
        hfac = np.fromfile(fn_hFacC, '>f4')
    except:
        sys.exit(' ^o^ ' * 20 +
                 '\n%s does not exist, please double check.\n' % fn_hFacC +
                 ' ^p^ ' * 20)

    hfac = np.reshape(hfac, [nz, ny, nx])

    y = np.arange(ny)
    x = np.arange(-10, nx + 10)
    xx, yy = np.meshgrid(x, y)
    xs = xx.flatten()
    ys = yy.flatten()

    newx = np.zeros((nz, ny, nx + 20))
    newy = np.zeros((nz, ny, nx + 20))

    for k in np.arange(nz):
        print "calculating reflective boundary condition for model level", k
        hfc = hfac[k, ...]
        hf = np.c_[hfc[:, -10:], hfc, hfc[:, :10]]
        ip = (hf.flatten() > 0)
        try:
            px = npi((xs[ip], ys[ip]), xs[ip])
            py = npi((xs[ip], ys[ip]), ys[ip])
            newx[k, ...] = (px((xx, yy)).reshape(ny, -1))  #[:,1:-1]
            newy[k, ...] = (py((xx, yy)).reshape(ny, -1))  #[:,1:-1]
            del hfc, hf, ip, py, px
        except:
            print 'something went wrong..'
    newx[..., 8:-8].astype('>f4').tofile(pth_data_out + '/reflect_x.bin')
    newy[..., 8:-8].astype('>f4').tofile(pth_data_out + '/reflect_y.bin')
    print "+" * 40
    print "  Saved files reflect_x.bin reflect_y.bin to %s " % pth_data_out
    print "+" * 40

    return
示例#2
0
def reflective_boundary():
    from scipy.interpolate import NearestNDInterpolator as npi 
    
    nz,ny,nx=42,320,2160 #the model grid size
    
    
    fn_hFacC=pth_data_in+'hFacC.data'
    try:
        hfac=np.fromfile(fn_hFacC,'>f4').reshape(nz,ny,nx)
    except:
        sys.exit(' ^o^ '*20+'\n%s does not exist, please double check.\n'%fn_hFacC+
                 ' ^p^ '*20)
            
    
    
    y=np.arange(ny)
    x=np.arange(-10,nx+10)
    xx,yy=np.meshgrid(x,y)
    xs=xx.flatten()
    ys=yy.flatten()
    
    newx=np.zeros((nz,ny,nx+20))
    newy=np.zeros((nz,ny,nx+20))
    
    for k in np.arange(nz):
        print "calculating reflective boundary condition for model level",k
        hfc=hfac[k,...]
        hf=np.c_[hfc[:,-10:],hfc,hfc[:,:10]]
        ip=(hf.flatten()>0)
        px = npi((xs[ip],ys[ip]),xs[ip])
        py = npi((xs[ip],ys[ip]),ys[ip])
        newx[k,...]=(px((xx,yy)).reshape(ny,-1))#[:,1:-1]
        newy[k,...]=(py((xx,yy)).reshape(ny,-1))#[:,1:-1]
        del hfc, hf, ip, py, px
    
    newx[...,8:-8].astype('>f4').tofile(pth_data_out+'/reflect_x.bin')
    newy[...,8:-8].astype('>f4').tofile(pth_data_out+'/reflect_y.bin')
    print "+"*40
    print "  Saved files reflect_x.bin reflect_y.bin to %s "%pth_data_out
    print "+"*40
    
    return
x=arange(-10,2160+10)
xx,yy=meshgrid(x,y)
xs=xx.flatten()
ys=yy.flatten()

nz,ny,nx=hfac.shape
newx=zeros((nz,ny,nx+20))
newy=zeros((nz,ny,nx+20))


for k in arange(nz):
    print k
    hfc=hfac[k,...]
    hf=c_[hfc[:,-10:],hfc,hfc[:,:10]]
    ip=(hf.flatten()>0)
    px = npi((xs[ip],ys[ip]),xs[ip])
    py = npi((xs[ip],ys[ip]),ys[ip])
    newx[k,...]=(px((xx,yy)).reshape(320,-1)-xx)#[:,1:-1]
    newy[k,...]=(py((xx,yy)).reshape(320,-1)-yy)#[:,1:-1]
    del hfc, hf, ip, py, px

newx[...,8:-8].astype('>f4').tofile('reflect_x.bin')
newy[...,8:-8].astype('>f4').tofile('reflect_y.bin')

popy.io.saveh5('reflect_dy.h5','d',newy)
popy.io.saveh5('reflect_dx.h5','d',newx)
#i0,i1,j0,j1=0,200,116,320
#pcolor(hf[j0:j1,i0:i1])

#for i in range(i0,i1):
#    for j in range(j0,j1):
示例#4
0
y = arange(320)
x = arange(-10, 2160 + 10)
xx, yy = meshgrid(x, y)
xs = xx.flatten()
ys = yy.flatten()

nz, ny, nx = hfac.shape
newx = zeros((nz, ny, nx + 20))
newy = zeros((nz, ny, nx + 20))

for k in arange(nz):
    print k
    hfc = hfac[k, ...]
    hf = c_[hfc[:, -10:], hfc, hfc[:, :10]]
    ip = (hf.flatten() > 0)
    px = npi((xs[ip], ys[ip]), xs[ip])
    py = npi((xs[ip], ys[ip]), ys[ip])
    newx[k, ...] = (px((xx, yy)).reshape(320, -1) - xx)  #[:,1:-1]
    newy[k, ...] = (py((xx, yy)).reshape(320, -1) - yy)  #[:,1:-1]
    del hfc, hf, ip, py, px

newx[..., 8:-8].astype('>f4').tofile('reflect_x.bin')
newy[..., 8:-8].astype('>f4').tofile('reflect_y.bin')

popy.io.saveh5('reflect_dy.h5', 'd', newy)
popy.io.saveh5('reflect_dx.h5', 'd', newx)
#i0,i1,j0,j1=0,200,116,320
#pcolor(hf[j0:j1,i0:i1])

#for i in range(i0,i1):
#    for j in range(j0,j1):