Esempio n. 1
0
def plotcoast(axin,**kwargs):
    """
    Plots the coastline on an ax.

    :Parameters:
        axin - a plt axes to plot on.
    :Optional:
        filename - which coastline file to use. Use nc coastline format from xscan. (default mid_nwatl6b.nc)
        color - the color on the coastline (default black).
        lw - the width of the coastline's lines (default 1).
        ls - the style of the coastline's lines (default 1).
        fill - True/False to fill in the coastline (default False)
        fcolor - the color used to fill the coastline (default 0.75, dark gray)
        ticksout - Face the axis ticksout  (R style - default False) 
    """ 

   
    color='k'
    lw=1
    ls='solid'
    filename='mid_nwatl6b.nc'
    fcolor='0.75'
    fill=False

    if kwargs is not None:
        for key, value in kwargs.iteritems():            
            if (key=='color'):
                color=value
            if (key=='lw'):
                lw=value
            if (key=='ls'):
                ls=value    
            if (key=='filename'):
                filename=value   
            if (key=='fill'):
                fill=value 
            if (key=='fcolor'):
                fcolor=value

    sl=dt.loadnc("",singlename='data/shorelines/'+filename)

    idx=np.where(sl['count']!=0)[0]
    sl['count']=sl['count'][idx]
    sl['start']=sl['start'][idx]

    tmparray=[list(zip(sl['lon'][sl['start'][i]:(sl['start'][i]+sl['count'][i])],sl['lat'][sl['start'][i]:(sl['start'][i]+sl['count'][i])])) for i in range(0,len(sl['start']))]

    if fill==True:
        coastseg=PC(tmparray,facecolor = fcolor,edgecolor=color,linewidths=lw)
    else:
        coastseg=LC(tmparray,linewidths = lw,linestyles=ls,color=color)



    

    axin.add_collection(coastseg)
Esempio n. 2
0
def checkrestart():
    import glob
    filenames=glob.glob('*restart*')
    filenames.sort()
    for filename in filenames:
        print(filename)
        data=dt.loadnc('',filename)
        print(data['zeta'][:,1000].max())
    print(data['Time'])
    print('='*30)
Esempio n. 3
0
def checkrestart():
    import glob
    filenames = glob.glob('*restart*')
    filenames.sort()
    for filename in filenames:
        print(filename)
        data = dt.loadnc('', filename)
        print(data['zeta'][:, 1000].max())
    print(data['Time'])
    print('=' * 30)
Esempio n. 4
0
import matplotlib.pyplot as plt
import os
np.set_printoptions(precision=8, suppress=True)

name = 'kitimat3_128'
grid = 'kitimat3'
dim = '2d'

directory = '/home/moflaher/Desktop/workspace_python/figures/timeseries/curl/' + grid + '_' + name + '_' + dim + '/'
if not os.path.exists(directory):
    os.makedirs(directory)

if 1 == 1:

    fileDir = '/media/moflaher/My Book/kitimat3_timetests/kitimat3_128_0/output/'
    data = dt.loadnc(fileDir, None, '2D')
    data = dt.ncdatasort(data)

    #region, passage, passageP = regions('kitimat3') # nargout=3
    #nidx, uvidx = get_indexs(nodell, uvnodell, region, trinodes) # nargout=2

if 1 == 1:
    a, b = data['ua'].shape  # nargout=2
    curl = np.zeros((b, a))
    z_vec = np.zeros((1, a)).T
    ua_in = np.hstack([data['ua'], z_vec]).T
    va_in = np.hstack([data['va'], z_vec]).T
    for i in np.arange(0, len(data['uvnodell'])):
        e1 = data['nbe'][i, 0]
        e2 = data['nbe'][i, 1]
        e3 = data['nbe'][i, 2]
Esempio n. 5
0
import os
np.set_printoptions(precision=8,suppress=True)


name = 'kitimat3_128'
grid = 'kitimat3'
dim = '2d'

directory='/home/moflaher/Desktop/workspace_python/figures/timeseries/curl/' + grid + '_' + name + '_' + dim + '/'
if not os.path.exists(directory):
    os.makedirs(directory)

if 1 == 1:

    fileDir='/media/moflaher/My Book/kitimat3_timetests/kitimat3_128_0/output/'
    data = dt.loadnc(fileDir,None,'2D')
    data = dt.ncdatasort(data)
   


    #region, passage, passageP = regions('kitimat3') # nargout=3
    #nidx, uvidx = get_indexs(nodell, uvnodell, region, trinodes) # nargout=2



if 1 == 1:
    a, b = data['ua'].shape # nargout=2
    curl = np.zeros((b, a))
    z_vec = np.zeros((1,a)).T
    ua_in = np.hstack([data['ua'],z_vec]).T
    va_in = np.hstack([data['va'],z_vec]).T
Esempio n. 6
0
def cross_shore_transect_2d(grid, name, region, vec, npt):
    data = dt.loadnc('runs/' + grid + '/' + name + '/output/',
                     singlename=grid + '_0001.nc')
    print('done load')
    data = dt.ncdatasort(data, trifinder=True)
    print('done sort')

    cages = gt.loadcage('runs/' + grid + '/' + name + '/input/' + grid +
                        '_cage.dat')
    if np.shape(cages) != ():
        tmparray = [
            list(
                zip(data['nodell'][data['nv'][i, [0, 1, 2, 0]], 0],
                    data['nodell'][data['nv'][i, [0, 1, 2, 0]], 1]))
            for i in cages
        ]
        color = 'g'
        lw = .2
        ls = 'solid'

    vectorstart = np.array(vec[0])
    vectorend = np.array(vec[1])
    vectorx = np.array([vectorstart[0], vectorend[0]])
    vectory = np.array([vectorstart[1], vectorend[1]])
    snv = (vectorend - vectorstart) / np.linalg.norm(vectorend - vectorstart)

    xi = np.linspace(vectorstart[0], vectorend[0], npt)
    yi = np.linspace(vectorstart[1], vectorend[1], npt)
    us = data['ua'].shape

    savepath = 'data/cross_shore_transect/'
    if not os.path.exists(savepath): os.makedirs(savepath)

    plotpath = 'figures/png/' + grid + '_2d/cross_shore_transect/'
    if not os.path.exists(plotpath): os.makedirs(plotpath)

    nidx = dt.get_nodes(data, region)
    f = plt.figure()
    ax = f.add_axes([.125, .1, .775, .8])
    triax = ax.tripcolor(data['trigrid'],
                         data['h'],
                         vmin=data['h'][nidx].min(),
                         vmax=data['h'][nidx].max())
    ax.plot(xi, yi, 'k', lw=3)
    if np.shape(cages) != ():
        lseg_t = LC(tmparray, linewidths=lw, linestyles=ls, color=color)
        coast = ax.add_collection(lseg_t)
        coast.set_zorder(30)
    pt.prettyplot_ll(ax, setregion=region, cb=triax, cblabel=r'Depth (m)')
    f.savefig(plotpath + name + '_' + ('%f' % vectorx[0]) + '_' +
              ('%f' % vectorx[1]) + '_' + ('%f' % vectory[0]) + '_' +
              ('%f' % vectory[1]) + '_' + ('%d' % len(xi)) +
              '_line_location.png',
              dpi=600)
    plt.close(f)

    fillarray_u = np.empty((us[0], npt))
    fillarray_v = np.empty((us[0], npt))
    fillalong = np.empty((us[0], npt))
    fillcross = np.empty((us[0], npt))
    dist = np.empty((npt, ))
    h = np.empty((npt, ))

    print('interp uvw on path')
    for i in range(0, len(xi)):
        print(i)
        fillarray_u[:, i] = interpE_at_loc(data, 'ua', [xi[i], yi[i]])
        fillarray_v[:, i] = interpE_at_loc(data, 'va', [xi[i], yi[i]])
        h[i] = interpN_at_loc(data, 'h', [xi[i], yi[i]])

    print('Calc along path current')
    for i in range(0, len(xi)):
        print(i)
        inner = np.inner(
            np.vstack([fillarray_u[:, i], fillarray_v[:, i]]).T, snv)
        along = np.vstack([inner * snv[0], inner * snv[1]]).T
        tmpa = np.multiply(np.sign(np.arctan2(along[:, 1], along[:, 0])),
                           np.linalg.norm(along, axis=1))
        fillalong[:, i] = tmpa
        cross = np.vstack([fillarray_u[:, i], fillarray_v[:, i]]).T - along
        tmpc = np.multiply(np.sign(np.arctan2(cross[:, 1], cross[:, 0])),
                           np.linalg.norm(cross, axis=1))
        fillcross[:, i] = tmpc

        dist[i] = (sw.dist([vectorstart[1], yi[i]], [vectorstart[0], xi[i]],
                           'km'))[0] * 1000

    if np.shape(cages) != ():
        incage = np.zeros((len(xi), ))
        host = data['trigrid'].get_trifinder().__call__(xi, yi)
        incage[np.in1d(host, cages)] = 1

    savedic = {}

    savedic['u'] = fillarray_u
    savedic['v'] = fillarray_v
    savedic['along'] = fillalong
    savedic['cross'] = fillcross
    savedic['distance'] = dist
    savedic['h'] = h
    savedic['lon'] = xi
    savedic['lat'] = yi
    if np.shape(cages) != ():
        savedic['incage'] = incage

    np.save(
        savepath + grid + '_' + name + '_' + ('%f' % vectorx[0]) + '_' +
        ('%f' % vectorx[1]) + '_' + ('%f' % vectory[0]) + '_' +
        ('%f' % vectory[1]) + '_' + ('%d' % len(xi)) + '_2d.npy', savedic)
    sio.savemat(savepath + 'matfiles/' + grid + '_' + name + '_' +
                ('%f' % vectorx[0]) + '_' + ('%f' % vectorx[1]) + '_' +
                ('%f' % vectory[0]) + '_' + ('%f' % vectory[1]) + '_' +
                ('%d' % len(xi)) + '_2d.mat',
                mdict=savedic)
Esempio n. 7
0
def cross_shore_transect_2d(grid,name,region,vec,npt):
    data = dt.loadnc('runs/'+grid+'/'+name+'/output/',singlename=grid + '_0001.nc')
    print('done load')
    data = dt.ncdatasort(data,trifinder=True)
    print('done sort')

    cages=gt.loadcage('runs/'+grid+'/' +name+ '/input/' +grid+ '_cage.dat')
    if np.shape(cages)!=():
        tmparray=[list(zip(data['nodell'][data['nv'][i,[0,1,2,0]],0],data['nodell'][data['nv'][i,[0,1,2,0]],1])) for i in cages ]
        color='g'
        lw=.2
        ls='solid'
   
    vectorstart=np.array(vec[0])
    vectorend=np.array(vec[1])
    vectorx=np.array([vectorstart[0],vectorend[0]])
    vectory=np.array([vectorstart[1],vectorend[1]])
    snv=(vectorend-vectorstart)/np.linalg.norm(vectorend-vectorstart)

    xi=np.linspace(vectorstart[0],vectorend[0],npt)
    yi=np.linspace(vectorstart[1],vectorend[1],npt)
    us=data['ua'].shape

    savepath='data/cross_shore_transect/'
    if not os.path.exists(savepath): os.makedirs(savepath)

    plotpath='figures/png/'+grid+'_2d/cross_shore_transect/'
    if not os.path.exists(plotpath): os.makedirs(plotpath)



    nidx=dt.get_nodes(data,region)
    f=plt.figure()
    ax=f.add_axes([.125,.1,.775,.8])
    triax=ax.tripcolor(data['trigrid'],data['h'],vmin=data['h'][nidx].min(),vmax=data['h'][nidx].max())
    ax.plot(xi,yi,'k',lw=3)  
    if np.shape(cages)!=():   
        lseg_t=LC(tmparray,linewidths = lw,linestyles=ls,color=color)
        coast=ax.add_collection(lseg_t)
        coast.set_zorder(30)
    pt.prettyplot_ll(ax,setregion=region,cb=triax,cblabel=r'Depth (m)') 
    f.savefig(plotpath + name+'_'+('%f'%vectorx[0])+'_'+('%f'%vectorx[1])+'_'+('%f'%vectory[0])+'_'+('%f'%vectory[1])+'_'+('%d'%len(xi))+'_line_location.png',dpi=600)
    plt.close(f)

    fillarray_u=np.empty((us[0],npt))
    fillarray_v=np.empty((us[0],npt))
    fillalong=np.empty((us[0],npt))
    fillcross=np.empty((us[0],npt))
    dist=np.empty((npt,))
    h=np.empty((npt,))

    print('interp uvw on path')
    for i in range(0,len(xi)):
        print(i)
        fillarray_u[:,i]=interpE_at_loc(data,'ua',[xi[i],yi[i]])
        fillarray_v[:,i]=interpE_at_loc(data,'va',[xi[i],yi[i]])
        h[i]=interpN_at_loc(data,'h',[xi[i],yi[i]])

    print('Calc along path current')
    for i in range(0,len(xi)):
        print(i)
        inner=np.inner(np.vstack([fillarray_u[:,i],fillarray_v[:,i]]).T,snv)
        along=np.vstack([inner*snv[0],inner*snv[1]]).T
        tmpa=np.multiply(np.sign(np.arctan2(along[:,1],along[:,0])),np.linalg.norm(along,axis=1))
        fillalong[:,i]=tmpa
        cross=np.vstack([fillarray_u[:,i],fillarray_v[:,i]]).T-along
        tmpc=np.multiply(np.sign(np.arctan2(cross[:,1],cross[:,0])),np.linalg.norm(cross,axis=1))
        fillcross[:,i]=tmpc

        dist[i]=(sw.dist([vectorstart[1], yi[i]],[vectorstart[0], xi[i]],'km'))[0]*1000;
        
    if np.shape(cages)!=():
        incage=np.zeros((len(xi),))
        host=data['trigrid'].get_trifinder().__call__(xi,yi)
        incage[np.in1d(host,cages)]=1


    savedic={}

    savedic['u']=fillarray_u
    savedic['v']=fillarray_v
    savedic['along']=fillalong
    savedic['cross']=fillcross
    savedic['distance']=dist
    savedic['h']=h
    savedic['lon']=xi
    savedic['lat']=yi
    if np.shape(cages)!=():
        savedic['incage']=incage

    np.save(savepath+grid+'_'+name+'_'+('%f'%vectorx[0])+'_'+('%f'%vectorx[1])+'_'+('%f'%vectory[0])+'_'+('%f'%vectory[1])+'_'+('%d'%len(xi))+'_2d.npy',savedic)
    sio.savemat(savepath+'matfiles/'+grid+'_'+name+'_'+('%f'%vectorx[0])+'_'+('%f'%vectorx[1])+'_'+('%f'%vectory[0])+'_'+('%f'%vectory[1])+'_'+('%d'%len(xi))+'_2d.mat',mdict=savedic)