Ejemplo n.º 1
0
def plotgrid_ll(data,size,ll,nore):
    if nore=='n':
        num=dt.closest_node(data,ll)
        region={}
        region['region']=[data['nodexy'][num,0]-size,data['nodexy'][num,0]+size,data['nodexy'][num,1]-size,data['nodexy'][num,1]+size]
        idx=dt.get_nodes_xy(data,region)
        plt.triplot(data['trigridxy'],lw=.5)
        for i in idx:
            plt.text(data['nodexy'][i,0],data['nodexy'][i,1],("%d"%i),fontsize=10,bbox={'facecolor':'white', 'alpha':.7, 'pad':3})
        region2={}
        region2['region']=[data['nodexy'][num,0]-(size*2),data['nodexy'][num,0]+(size*2),data['nodexy'][num,1]-(size*2),data['nodexy'][num,1]+(size*2)]
        plt.axis(region2['region'])
        plt.show()
    if nore=='e':
        num=dt.closest_element(data,ll)
        region={}
        region['region']=[data['uvnode'][num,0]-size,data['uvnode'][num,0]+size,data['uvnode'][num,1]-size,data['uvnode'][num,1]+size]
        idx=dt.get_elements_xy(data,region)
        plt.triplot(data['trigridxy'],lw=.5)
        for i in idx:
            plt.text(data['uvnode'][i,0],data['uvnode'][i,1],("%d"%i),fontsize=10,bbox={'facecolor':'white', 'alpha':.7, 'pad':3})
        region2={}
        region2['region']=[data['uvnode'][num,0]-(size*2),data['uvnode'][num,0]+(size*2),data['uvnode'][num,1]-(size*2),data['uvnode'][num,1]+(size*2)]
        plt.axis(region2['region'])
        plt.show()
Ejemplo n.º 2
0
def regionll2xy(data, region):
    """
    Take an FVCOM data dictionary, a region dictionary and return a region dictionary with regionxy added which best approximates the ll region in xy.
 
    """
    try:
        np.shape(region['center'])
    except KeyError:
        region['center'] = [(region['region'][0] + region['region'][1]) / 2,
                            (region['region'][2] + region['region'][3]) / 2]

    ehost = dt.closest_element(data, region['center'])
    nhost = dt.closest_node(data, region['center'])

    edist = ll2m(data['uvnodell'][ehost, :], region['center'])
    ndist = ll2m(data['nodell'][nhost, :], region['center'])

    if (np.linalg.norm(edist) > np.linalg.norm(ndist)):
        region['centerxy'] = data['nodexy'][nhost, :]
        xp, yp = ll2m(data['nodell'][nhost, :], region['region'][[1, 3]])
        xn, yn = ll2m(data['nodell'][nhost, :], region['region'][[0, 2]])
    else:
        region['centerxy'] = data['uvnode'][ehost, :]
        xp, yp = ll2m(data['uvnodell'][ehost, :], region['region'][[1, 3]])
        xn, yn = ll2m(data['uvnodell'][ehost, :], region['region'][[0, 2]])

    region['regionxy'] = [
        region['centerxy'][0] + xn, region['centerxy'][0] + xp,
        region['centerxy'][1] + yn, region['centerxy'][1] + yp
    ]

    #old code leave this in till the new code above is tested
    #    left=np.argmin(np.sqrt((data['uvnodell'][:,0]-region['region'][0])**2+(data['uvnodell'][:,1]-(region['region'][2]+region['region'][3])*.5)**2))
    #    right=np.argmin(np.sqrt((data['uvnodell'][:,0]-region['region'][1])**2+(data['uvnodell'][:,1]-(region['region'][2]+region['region'][3])*.5)**2))
    #
    #    top=np.argmin(np.sqrt((data['uvnodell'][:,1]-region['region'][3])**2+(data['uvnodell'][:,0]-(region['region'][0]+region['region'][1])*.5)**2))
    #    bottom=np.argmin(np.sqrt((data['uvnodell'][:,1]-region['region'][2])**2+(data['uvnodell'][:,0]-(region['region'][0]+region['region'][1])*.5)**2))

    #    region['regionxy']=[data['uvnode'][left,0],data['uvnode'][right,0],data['uvnode'][bottom,1],data['uvnode'][top,1]]

    return region
Ejemplo n.º 3
0
def regionll2xy(data,region):
    """
    Take an FVCOM data dictionary, a region dictionary and return a region dictionary with regionxy added which best approximates the ll region in xy.
 
    """
    try:
        np.shape(region['center'])
    except KeyError:
        region['center']=[(region['region'][0]+region['region'][1])/2,(region['region'][2]+region['region'][3])/2]

    ehost=dt.closest_element(data,region['center'])
    nhost=dt.closest_node(data,region['center'])

    edist=ll2m(data['uvnodell'][ehost,:],region['center'])
    ndist=ll2m(data['nodell'][nhost,:],region['center'])

    if ( np.linalg.norm(edist)>np.linalg.norm(ndist) ):
        region['centerxy']=data['nodexy'][nhost,:]
        xp,yp=ll2m(data['nodell'][nhost,:],region['region'][[1,3]])
        xn,yn=ll2m(data['nodell'][nhost,:],region['region'][[0,2]])
    else:
        region['centerxy']=data['uvnode'][ehost,:]
        xp,yp=ll2m(data['uvnodell'][ehost,:],region['region'][[1,3]])
        xn,yn=ll2m(data['uvnodell'][ehost,:],region['region'][[0,2]])

    region['regionxy']=[region['centerxy'][0]+xn,region['centerxy'][0]+xp,region['centerxy'][1]+yn,region['centerxy'][1]+yp]      

    #old code leave this in till the new code above is tested
    #    left=np.argmin(np.sqrt((data['uvnodell'][:,0]-region['region'][0])**2+(data['uvnodell'][:,1]-(region['region'][2]+region['region'][3])*.5)**2))
    #    right=np.argmin(np.sqrt((data['uvnodell'][:,0]-region['region'][1])**2+(data['uvnodell'][:,1]-(region['region'][2]+region['region'][3])*.5)**2))
    #    
    #    top=np.argmin(np.sqrt((data['uvnodell'][:,1]-region['region'][3])**2+(data['uvnodell'][:,0]-(region['region'][0]+region['region'][1])*.5)**2))
    #    bottom=np.argmin(np.sqrt((data['uvnodell'][:,1]-region['region'][2])**2+(data['uvnodell'][:,0]-(region['region'][0]+region['region'][1])*.5)**2))

    #    region['regionxy']=[data['uvnode'][left,0],data['uvnode'][right,0],data['uvnode'][bottom,1],data['uvnode'][top,1]]

    return region