Beispiel #1
0
def getCorrelation2InRotatedFrame(beta,vals):
    # lon0, lat0 : main vehicle lat and lon used as initial conditions for debris propagation
    # beta : main vehicle heading angle (counterclockwise starting East) [deg]
    
    lonlat = vals[0]
    nSamples = vals[1]
    lon0 = vals[2]
    lat0 = vals[3]
    R1 = Rotz(lon0*np.pi/180.) # generating rotation matrices
    R2 = Roty(-lat0*np.pi/180.)
    R3 = Rotx(beta*np.pi/180.)
    
    Uint = np.dot(R2,R1)
    U  = np.dot(R3,Uint)
    UT = U.T
    xyz,x,y,z = getxyz(lonlat)
    pqr = np.dot(U,xyz) # rotating point to new frame...(P frame)
    p = pqr[0,:] 
    q = pqr[1,:]
    r = pqr[2,:]
    lonlatPframe = getlonlat(p,q,r)
    lonlatPframe = lonlatChecks.fixlon4pdf(lonlatPframe,nSamples)
    mean,covar = meancov.meancovmatrix(lonlatPframe,nSamples)
    #D,Ulocal = np.linalg.eig(covar)
    #lonlatAframe = np.dot(lonlatPframe,Ulocal) 
    #lonlatAframe = lonlatChecks.fixlon4pdf(lonlatAframe,nSamples)
    
    #mean,covar = meancov.meancovmatrix(lonlatAframe,nSamples)
    sigma1 = (covar[0,0])**.5
    sigma2 = (covar[1,1])**.5
    correlation = covar[0,1]/(sigma1*sigma2)
    #print sigma1,sigma2,correlation

    return abs(correlation)*sigma2 # objective function for optimization part (minimizing rho) 
def originalFrame2Pframe(lonlat, U):

    xyz, x, y, z = getxyz(lonlat)

    pqr = np.dot(U, xyz)  # rotating point to new frame...(P frame)
    p = pqr[0, :]
    q = pqr[1, :]
    r = pqr[2, :]
    lonlatPframe = getlonlat(p, q, r)

    lonlatPframe = lonlatChecks.fixlon4pdf(
        lonlatPframe,
        len(x))  # P frame should be technically in the principal axis

    return lonlatPframe
Beispiel #3
0
# driver for lonlatChecks
import lonlatChecks
import numpy as np

nsamples = 100
lon = np.linspace(-10, 220, nsamples)
lat = np.linspace(33, 70, nsamples)

lonlat = np.zeros((nsamples, 2))

lonlat[:, 0] = lon
lonlat[:, 1] = lat

print lonlat

lonlat2 = lonlatChecks.boundlon(lonlat, nsamples)

lonlat3 = lonlatChecks.fixlon4pdf(lonlat2, nsamples)

print lonlat - lonlat3
Beispiel #4
0
def getPDF4KLDiv(lonlat, nSamples, pdfoption, lonMesh, latMesh, R1, R2, R3,
                 xlen, ylen):
    # lon0, lat0 : main vehicle lat and lon used as initial conditions for debris propagation
    # beta : main vehicle heading angle (counterclockwise starting East) [deg]
    # this routine should only be used for KL Divergence check.
    # SIMPLE MODIFICATION FROM pdfCoordTrans.py

    xyz, x, y, z = pdf.getxyz(lonlat)

    Uint = np.dot(R2, R1)
    U = np.dot(R3, Uint)
    #U = Uint
    UT = U.T
    pqr = np.dot(U, xyz)  # rotating point to new frame...(P frame)

    p = pqr[0, :]
    q = pqr[1, :]
    r = pqr[2, :]
    lonlatPframe = pdf.getlonlat(p, q, r)
    lonlatPframe = lonlatChecks.fixlon4pdf(lonlatPframe, nSamples)
    '''
    mean,covar = meancov.meancovmatrix(lonlatPframe,nSamples)
    #print 'Mean in P frame =',mean
    D,Ulocal = np.linalg.eig(covar)
    
    
    
    lonlatAframe = np.dot(lonlatPframe,Ulocal) 
    #lonlatAframe = lonlatChecks.fixlon4pdf(lonlatAframe,nSamples)
    
    mean,covar = meancov.meancovmatrix(lonlatAframe,nSamples)
  
    
    
    if pdfoption=='KDE':
        ZZpdf = meancov.kde(lonlatAframe,XX,YY,[nSamples, xlen,ylen])
    elif pdfoption=='normal':
        ZZpdf = meancov.normalbivariate(mean,covar,XX,YY,xlen,ylen) #fortran version
    '''

    lonVec = np.reshape(lonMesh, np.size(lonMesh))
    latVec = np.reshape(latMesh, np.size(latMesh))
    lonlatVec = np.zeros((len(lonVec), 2))
    lonlatVec[:, 0] = lonVec
    lonlatVec[:, 1] = latVec
    lonlatVecP = pdf.originalFrame2Pframe(lonlatVec, U)
    ylen, xlen = np.shape(lonMesh)
    lonMeshP = np.reshape(lonlatVecP[:, 0], [ylen, xlen])
    latMeshP = np.reshape(lonlatVecP[:, 1], [ylen, xlen])

    pqrVec, pVec, qVec, rVec = pdf.getxyz(
        lonlatVecP)  # mesh locations in P frame

    if pdfoption == 'KDE':
        ZZpdf = meancov.kde(lonlatPframe, lonMeshP, latMeshP,
                            [nSamples, xlen, ylen])
    elif pdfoption == 'normal' or pdfoption == 'gaussian' or pdfoption == 'gauss':
        mean, covar = meancov.meancovmatrix(lonlatPframe, nSamples)
        ZZpdf = meancov.normalbivariate(mean, covar, lonMeshP, latMeshP, xlen,
                                        ylen)  #fortran version

    pdfN = pdf.transformPDF(U, pqrVec, np.pi / 180 * lonlatVec[:, 0],
                            np.pi / 180 * lonlatVec[:, 1],
                            np.reshape(ZZpdf, xlen * ylen))

    ZZpdfN = np.reshape(pdfN, [ylen, xlen])

    return (ZZpdfN)