예제 #1
0
def getPDFfromSetup(pdfoption,lonlatPframe,xMeshP,yMeshP):
    
    row,col = np.shape(xMeshP)
    if pdfoption.lower()=='kde' or pdfoption.lower()=='kernel':
        ZZpdfPframe = SK.serialK(int(nSamples),lonlatPframe,row,col,xMeshP,yMeshP,.0,0)
    elif pdfoption=='normal' or pdfoption=='gaussian' or pdfoption=='gauss':
        nSamples,dims = np.shape(lonlatPframe)
        if dims!=2:
            print 'Error in lonlatPframe, dimensions are not correct'
            print 'Check inputs to getPDFfromSetup in casualtyEstimate.py'
            exit() 
        mean,covar = meancov.meancovmatrix(lonlatPframe,nSamples)
        ZZpdfPframe = meancov.normalbivariate(mean,covar,xMeshP,yMeshP,col,row) #fortran version    
    return ZZpdfPframe
예제 #2
0
def getPDFfromSetup(pdfoption, lonlatPframe, xMeshP, yMeshP):

    row, col = np.shape(xMeshP)
    if pdfoption.lower() == 'kde' or pdfoption.lower() == 'kernel':
        ZZpdfPframe = SK.serialK(int(nSamples), lonlatPframe, row, col, xMeshP,
                                 yMeshP, .0, 0)
    elif pdfoption == 'normal' or pdfoption == 'gaussian' or pdfoption == 'gauss':
        nSamples, dims = np.shape(lonlatPframe)
        if dims != 2:
            print 'Error in lonlatPframe, dimensions are not correct'
            print 'Check inputs to getPDFfromSetup in casualtyEstimate.py'
            exit()
        mean, covar = meancov.meancovmatrix(lonlatPframe, nSamples)
        ZZpdfPframe = meancov.normalbivariate(mean, covar, xMeshP, yMeshP, col,
                                              row)  #fortran version
    return ZZpdfPframe
예제 #3
0
def getPDFfromSetup(nSamples,pdfoption,lonlatPframe,lonOrMesh,latOrMesh,U,xMeshP,yMeshP):

    row,col = np.shape(xMeshP)
    #print xMeshP
    if pdfoption.lower()=='kde' or pdfoption.lower()=='kernel':
        
        
        ZZpdfPframe = SK.serialK(int(nSamples),lonlatPframe,row,col,xMeshP,yMeshP,.0,0)
    
    elif pdfoption=='normal' or pdfoption=='gaussian' or pdfoption=='gauss':
        ZZpdfPframe = meancov.normalbivariate(mean,covar,xMeshP,yMeshP,col,row) #fortran version    
    #ZZpdf on P frame
    


    #xlen,ylen = np.shape(xMeshP)
    return (xMeshP,yMeshP,ZZpdfPframe,lonOrMesh,latOrMesh)
예제 #4
0
def calculatePDF(refLonLat, xMesh, yMesh, pdfoption):
    '''
    plt.figure()
    plt.plot(refLonLat[:,0],refLonLat[:,1],'x')
    plt.show()
    exit()
    '''
    xyz, x, y, z = pdf.getxyz(refLonLat)
    xmean = np.mean(x)
    ymean = np.mean(y)
    zmean = np.mean(z)
    mag = (xmean**2 + ymean**2 + zmean**2)  #**.5
    lonlat0 = pdf.getlonlat(xmean / mag, ymean / mag, zmean / mag)
    lon0 = lonlat0[0, 0]
    lat0 = lonlat0[0, 1]
    beta = 0  # initial guess
    nSamples, colvals = np.shape(refLonLat)
    row, col = np.shape(xMesh)
    beta = pdf.optimizeHeadingAngle(refLonLat, nSamples, lon0, lat0, beta)
    R1 = pdf.Rotz(lon0 * np.pi / 180.)  # generating rotation matrices
    R2 = pdf.Roty(-lat0 * np.pi / 180.)
    R3 = pdf.Rotx(beta * np.pi / 180.)
    transformDetails = [R1, R2, R3, lon0, lat0, beta]

    Uint = np.dot(R2, R1)
    U = np.dot(R3, Uint)
    lonlatPframe = pdf.originalFrame2Pframe(refLonLat, U)

    lonlatMesh = np.zeros((np.size(xMesh), 2))
    lonlatMesh[:, 0] = np.reshape(xMesh, np.size(xMesh))
    lonlatMesh[:, 1] = np.reshape(yMesh, np.size(yMesh))

    lonlatPMesh = pdf.originalFrame2Pframe(lonlatMesh, U)

    ylen, xlen = np.shape(xMesh)
    lonMeshP = np.reshape(lonlatPMesh[:, 0], [ylen, xlen])
    latMeshP = np.reshape(lonlatPMesh[:, 1], [ylen, xlen])

    if pdfoption.lower() == 'kde' or pdfoption.lower() == 'kernel':
        ZZpdfPframe = SK.serialK(int(nSamples), lonlatPframe, row, col,
                                 lonMeshP, latMeshP, .0, 0)
    elif pdfoption == 'normal' or pdfoption == 'gaussian' or pdfoption == 'gauss':
        ZZpdfPframe = meancov.normalbivariate(mean, covar, lonMeshP, latMeshP,
                                              col, row)  #fortran version
    '''
    plt.figure()
    plt.contour(lonMeshP,latMeshP,ZZpdfPframe,30)
    plt.plot(lonlatPframe[:,0],lonlatPframe[:,1],'x')
    
    plt.figure()
    plt.plot(lonlatPMesh[:,0],lonlatPMesh[:,1],'x')
    exit()
    '''

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

    pdfN = pdf.transformPDF(U, pqrVec, np.pi / 180 * lonlatMesh[:, 0],
                            np.pi / 180 * lonlatMesh[:, 1],
                            np.reshape(ZZpdfPframe, xlen * ylen))
    ZZpdfN = np.reshape(pdfN, [ylen, xlen])
    lonMesh = np.reshape(lonlatMesh[:, 0], [ylen, xlen])
    latMesh = np.reshape(lonlatMesh[:, 1], [ylen, xlen])
    '''
    plt.figure()
    plt.contour(lonMeshP,latMeshP,ZZpdfPframe,30)
    plt.plot(refLonLat[:,0],refLonLat[:,1],'x')
    plt.show()
    
    plt.figure()
    plt.contour(lonMesh,latMesh,ZZpdfN,30)
    plt.plot(refLonLat[:,0],refLonLat[:,1],'x')
    plt.show()
    '''
    return (lonMesh, latMesh, ZZpdfN)
예제 #5
0
def getPDF(lonlat,nSamples,delta,nsigma,pdfoption):
    # lon0, lat0 : main vehicle lat and lon used as initial conditions for debris propagation
    # beta : main vehicle heading angle (counterclockwise starting East) [deg]
    
    
    xyz,x,y,z = getxyz(lonlat)
    xmean = np.mean(x)
    ymean = np.mean(y)
    zmean = np.mean(z)
    mag = (xmean**2+ymean**2+zmean**2)**.5
    lonlat0 = getlonlat(xmean/mag,ymean/mag,zmean/mag)
    lon0 = lonlat0[0,0]
    lat0 = lonlat0[0,1]
    beta = 0 # initial guess
    beta = optimizeHeadingAngle(lonlat,nSamples,lon0,lat0,beta)

    R1 = Rotz(lon0*np.pi/180.) # generating rotation matrices
    R2 = Roty(-lat0*np.pi/180.)
    R3 = Rotx(beta*np.pi/180.)
    transformDetails = [R1,R2,R3,lon0,lat0,beta]
    
    Uint = np.dot(R2,R1)
    U  = np.dot(R3,Uint)
    lonlatPframe = originalFrame2Pframe(lonlat,U)
    # error check for this case not yet implemented
    
    #mean,covar = meancov.meancovmatrix(lonlatPframe,nSamples)
    #D,Ulocal = np.linalg.eig(covar)

    #lonlatAframe = np.dot(lonlatPframe,Ulocal) 
    
    
    
    #    ZZ = meancov.normalbivariate(mean,covar,XX,YY,xlen,ylen) #fortran version
    if pdfoption.lower()=='kde' or pdfoption.lower()=='kernel':
        xMeshP,yMeshP,xlen,ylen,areaInt = statsPython.areaOfInterestKDE(lonlatPframe,delta) # A frame could also be used
    elif pdfoption=='normal' or pdfoption=='gaussian' or pdfoption=='gauss':
        mean,covar = meancov.meancovmatrix(lonlatPframe,nSamples)
        xMeshP,yMeshP,xlen,ylen = statsPython.areaOfInterest(mean,covar,delta,nsigma)
   
        
    lonlatPframeMesh = np.zeros((np.size(xMeshP),2))
    lonlatPframeMesh[:,0] = np.reshape(xMeshP,np.size(xMeshP))
    lonlatPframeMesh[:,1] = np.reshape(yMeshP,np.size(yMeshP))
    lonlatOrFrameMesh = Pframe2originalFrame(lonlatPframeMesh,U)
    lonMesh,latMesh = getLonLatMesh(lonlatOrFrameMesh[:,0],lonlatOrFrameMesh[:,1],delta)

    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 = 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= getxyz(lonlatVecP) # mesh locations in P frame

          
    if pdfoption.lower()=='kde' or pdfoption.lower()=='kernel':
        #ZZpdf = meancov.kde(lonlatPframe,lonMeshP,latMeshP,[nSamples, xlen,ylen])
        print 'Starting quad KDE'
        ZZpdf = SK.serialK(nSamples,lonlatPframe,ylen,xlen,lonMeshP,latMeshP,.1,1)
        print 'Done with quad KDE'
    elif pdfoption=='normal' or pdfoption=='gaussian' or pdfoption=='gauss':
        ZZpdf = meancov.normalbivariate(mean,covar,lonMeshP,latMeshP,xlen,ylen) #fortran version

 
    pdfN = transformPDF(U,pqrVec,np.pi/180*lonlatVec[:,0],np.pi/180*lonlatVec[:,1],np.reshape(ZZpdf,xlen*ylen))
    ZZpdfN = np.reshape(pdfN,[ylen,xlen])
    #plt.figure()
    #plt.contourf(lonMesh,latMesh,np.reshape(pdfN,[ylen,xlen]))
    #plt.show()
    return (lonMesh,latMesh,ZZpdfN,lonMeshP,latMeshP,xlen,ylen,transformDetails,areaInt) #
예제 #6
0
def getPDF2(lonlat,nSamples,delta,nsigma,pdfoption):
    # lon0, lat0 : main vehicle lat and lon used as initial conditions for debris propagation
    # beta : main vehicle heading angle (counterclockwise starting East) [deg]
    #import time
    
    xyz,x,y,z = getxyz(lonlat)
    xmean = np.mean(x)
    ymean = np.mean(y)
    zmean = np.mean(z)
    mag = (xmean**2+ymean**2+zmean**2)
    lonlat0 = getlonlat(xmean/mag,ymean/mag,zmean/mag)
    lon0 = lonlat0[0,0]
    lat0 = lonlat0[0,1]
    beta = 0 # initial guess
    beta = optimizeHeadingAngle(lonlat,nSamples,lon0,lat0,beta)
    
    R1 = Rotz(lon0*np.pi/180.) # generating rotation matrices
    R2 = Roty(-lat0*np.pi/180.)
    R3 = Rotx(beta*np.pi/180.)
    transformDetails = [R1,R2,R3,lon0,lat0,beta]
    
    Uint = np.dot(R2,R1)
    U  = np.dot(R3,Uint)
    lonlatPframe = originalFrame2Pframe(lonlat,U)

    # error check for this case not yet implemented
    
    #mean,covar = meancov.meancovmatrix(lonlatPframe,nSamples)
    #D,Ulocal = np.linalg.eig(covar)
    
    #lonlatAframe = np.dot(lonlatPframe,Ulocal) 
    
    
    #    ZZ = meancov.normalbivariate(mean,covar,XX,YY,xlen,ylen) #fortran version
    if pdfoption.lower()=='kde' or pdfoption.lower()=='kernel':
        xMeshP,yMeshP,xlen,ylen= statsPython.areaOfInterestKDE(lonlatPframe,delta) # A frame could also be used
    
    elif pdfoption=='normal' or pdfoption=='gaussian' or pdfoption=='gauss':
        mean,covar = meancov.meancovmatrix(lonlatPframe,nSamples)
        xMeshP,yMeshP,xlen,ylen = statsPython.areaOfInterest(mean,covar,delta,nsigma)
    
    lonlatPframeMesh = np.zeros((np.size(xMeshP),2))
    lonlatPframeMesh[:,0] = np.reshape(xMeshP,np.size(xMeshP))
    lonlatPframeMesh[:,1] = np.reshape(yMeshP,np.size(yMeshP))
    row,col = np.shape(xMeshP)
    #print xMeshP
    if pdfoption.lower()=='kde' or pdfoption.lower()=='kernel':
        
  
        ZZpdfPframe = SK.serialK(int(nSamples),lonlatPframe,row,col,xMeshP,yMeshP,.0,0)
 
    elif pdfoption=='normal' or pdfoption=='gaussian' or pdfoption=='gauss':
        ZZpdfPframe = meancov.normalbivariate(mean,covar,xMeshP,yMeshP,col,row) #fortran version    
    #ZZpdf on P frame

    
    lonlatOrFrameMesh = Pframe2originalFrame(lonlatPframeMesh,U)
    lonOrMesh = np.reshape(lonlatOrFrameMesh[:,0],[ylen,xlen])
    latOrMesh = np.reshape(lonlatOrFrameMesh[:,1],[ylen,xlen])

    '''
    print 'maxABS',np.max(np.abs(ZZpdfPframe-ZZpdfPframe0))
    plt.figure()
    plt.contourf(xMeshP,yMeshP,ZZpdfPframe)
    plt.figure()
    plt.contourf(xMeshP,yMeshP,ZZpdfPframe0)
    plt.figure()
    plt.contourf(xMeshP,yMeshP,ZZpdfPframe0-ZZpdfPframe)


    plt.figure()
    plt.plot(lonlatPframe[:,0],lonlatPframe[:,1],'x')
    plt.figure()
    plt.contourf(lonOrMesh,latOrMesh,ZZpdfPframe)
    plt.plot(lonlat[:,0],lonlat[:,1],'x')
    plt.show()
    '''
    return (xMeshP,yMeshP,ZZpdfPframe,lonOrMesh,latOrMesh,xlen,ylen,transformDetails) #
예제 #7
0
def getPDF(lonlat,pdfoption='kde',delta=None,nMesh=50):
    #lonlat is a nx2 matrix with lon lat locations
    # nsigma is only used for getting PDF area when using normal distribution
    # pdf option 'kde' or 'normal' dist 
    # delta is spacing used for mesh in PDF
    # if delta not specified,then it will use nMesh which is the number of points used in one dim...total mesh will be nMesh x nMesh
    
    #this routine rotates the SPHERICAL planet to get a better 'flat planet' approximation by using local lat and lons and then applies the KDE or normal PDF routines
    
    xyz,x,y,z = getxyz(lonlat)
    xmean = np.mean(x)
    ymean = np.mean(y)
    zmean = np.mean(z)
    mag = (xmean**2+ymean**2+zmean**2)**.5
    lonlat0 = getlonlat(xmean/mag,ymean/mag,zmean/mag)
    lon0 = lonlat0[0,0]
    lat0 = lonlat0[0,1]
    beta = 0 # initial guess
    nSamples,dims = np.shape(lonlat)
    if dims!=2:
        print 'Error in lonlat, dimensions are not correct'
        print 'Check inputs to getPDF in casualtyEstimate.py'
        exit()
    
    beta = optimizeHeadingAngle(lonlat,nSamples,lon0,lat0,beta)
    
    R1 = Rotz(lon0*np.pi/180.) # generating rotation matrices
    R2 = Roty(-lat0*np.pi/180.)
    R3 = Rotx(beta*np.pi/180.)
    transformDetails = [R1,R2,R3,lon0,lat0,beta]
    
    Uint = np.dot(R2,R1)
    U  = np.dot(R3,Uint)
    lonlatPframe = originalFrame2Pframe(lonlat,U)

    if pdfoption.lower()=='kde' or pdfoption.lower()=='kernel':
        xMeshP,yMeshP,xlen,ylen,areaInt = statsPython.areaOfInterestKDE(lonlatPframe,delta=delta,nMesh=nMesh) # A frame could also be used
    elif pdfoption=='normal' or pdfoption=='gaussian' or pdfoption=='gauss':
        #mean,covar = meancov.meancovmatrix(lonlatPframe,nSamples)
        #xMeshP,yMeshP,xlen,ylen = statsPython.areaOfInterest(mean,covar,delta,nsigma)
        xMeshP,yMeshP,xlen,ylen,areaInt = statsPython.areaOfInterestKDE(lonlatPframe,delta=delta,nMesh=nMesh) # A frame could also be used

    
    
    lonlatPframeMesh = np.zeros((np.size(xMeshP),2))
    lonlatPframeMesh[:,0] = np.reshape(xMeshP,np.size(xMeshP))
    lonlatPframeMesh[:,1] = np.reshape(yMeshP,np.size(yMeshP))
    lonlatOrFrameMesh = Pframe2originalFrame(lonlatPframeMesh,U)
    lonMesh,latMesh = getLonLatMesh(lonlatOrFrameMesh[:,0],lonlatOrFrameMesh[:,1],delta)
    
    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 = 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= getxyz(lonlatVecP) # mesh locations in P frame
    
    
    if pdfoption.lower()=='kde' or pdfoption.lower()=='kernel':
        #ZZpdf = meancov.kde(lonlatPframe,lonMeshP,latMeshP,[nSamples, xlen,ylen])
        print 'Starting quad KDE'
        ZZpdf = SK.serialK(nSamples,lonlatPframe,ylen,xlen,lonMeshP,latMeshP,.1,1)
        print 'Done with quad KDE'
    elif pdfoption=='normal' or pdfoption=='gaussian' or pdfoption=='gauss':
        ZZpdf = meancov.normalbivariate(mean,covar,lonMeshP,latMeshP,xlen,ylen) #fortran version
    
    
    pdfN = transformPDF(U,pqrVec,np.pi/180*lonlatVec[:,0],np.pi/180*lonlatVec[:,1],np.reshape(ZZpdf,xlen*ylen))
    ZZpdfN = np.reshape(pdfN,[ylen,xlen])

    PframeVals = [lonPMesh,latPMesh,ZZpdf]
    OrFrameVals = [lonMesh,latMesh,ZZpdfN]
    return (PframeVals,OrFrameVals,transformDetails,areaInt)
예제 #8
0
mean = [10, -5]

cov = [[1, -.6], [-.6, 1]]

x, y = np.random.multivariate_normal(mean, cov, 5000).T
xnew = np.array(np.matrix(x).T)
ynew = np.array(np.matrix(y).T)

xvec = np.linspace(0, 20, 600)
yvec = np.linspace(-15, 5, 600)
dx = xvec[2] - xvec[1]
dy = yvec[2] - yvec[1]

xy = np.concatenate((xnew, ynew), 1)
#print xy
#print np.std(ynew)
X, Y = np.meshgrid(xvec, yvec)

fhatFAST = SK.serialK(5000, xy, 600, 600, X, Y, 2, 1)
print fhatFAST

print np.sum(fhatFAST * dx * dy)

plt.figure(1)
plt.plot(x, y, 'x')
plt.axis('equal')

plt.figure(2)
plt.contour(X, Y, fhatFAST, 50)
plt.show()
예제 #9
0
def calculatePDF(refLonLat,xMesh,yMesh,pdfoption):
    
    '''
    plt.figure()
    plt.plot(refLonLat[:,0],refLonLat[:,1],'x')
    plt.show()
    exit()
    '''
    xyz,x,y,z = pdf.getxyz(refLonLat)
    xmean = np.mean(x)
    ymean = np.mean(y)
    zmean = np.mean(z)
    mag = (xmean**2+ymean**2+zmean**2)#**.5
    lonlat0 = pdf.getlonlat(xmean/mag,ymean/mag,zmean/mag)
    lon0 = lonlat0[0,0]
    lat0 = lonlat0[0,1]
    beta = 0 # initial guess
    nSamples,colvals = np.shape(refLonLat)
    row,col = np.shape(xMesh)
    beta = pdf.optimizeHeadingAngle(refLonLat,nSamples,lon0,lat0,beta)
    R1 = pdf.Rotz(lon0*np.pi/180.) # generating rotation matrices
    R2 = pdf.Roty(-lat0*np.pi/180.)
    R3 = pdf.Rotx(beta*np.pi/180.)
    transformDetails = [R1,R2,R3,lon0,lat0,beta]
    
    Uint = np.dot(R2,R1)
    U  = np.dot(R3,Uint)
    lonlatPframe = pdf.originalFrame2Pframe(refLonLat,U)
    
    lonlatMesh = np.zeros((np.size(xMesh),2))
    lonlatMesh[:,0] = np.reshape(xMesh,np.size(xMesh))
    lonlatMesh[:,1] = np.reshape(yMesh,np.size(yMesh))

    lonlatPMesh = pdf.originalFrame2Pframe(lonlatMesh,U)
 
    ylen,xlen = np.shape(xMesh)
    lonMeshP = np.reshape(lonlatPMesh[:,0],[ylen,xlen])
    latMeshP = np.reshape(lonlatPMesh[:,1],[ylen,xlen])

    if pdfoption.lower()=='kde' or pdfoption.lower()=='kernel':        
        ZZpdfPframe = SK.serialK(int(nSamples),lonlatPframe,row,col,lonMeshP,latMeshP,.0,0)
    elif pdfoption=='normal' or pdfoption=='gaussian' or pdfoption=='gauss':
        ZZpdfPframe = meancov.normalbivariate(mean,covar,lonMeshP,latMeshP,col,row) #fortran version    
    '''
    plt.figure()
    plt.contour(lonMeshP,latMeshP,ZZpdfPframe,30)
    plt.plot(lonlatPframe[:,0],lonlatPframe[:,1],'x')
    
    plt.figure()
    plt.plot(lonlatPMesh[:,0],lonlatPMesh[:,1],'x')
    exit()
    '''
    
    
    pqrVec ,pVec,qVec,rVec= pdf.getxyz(lonlatPMesh) # mesh locations in P frame
    
    pdfN = pdf.transformPDF(U,pqrVec,np.pi/180*lonlatMesh[:,0],np.pi/180*lonlatMesh[:,1],np.reshape(ZZpdfPframe,xlen*ylen))
    ZZpdfN = np.reshape(pdfN,[ylen,xlen])
    lonMesh = np.reshape(lonlatMesh[:,0],[ylen,xlen])
    latMesh = np.reshape(lonlatMesh[:,1],[ylen,xlen])
    
    '''
    plt.figure()
    plt.contour(lonMeshP,latMeshP,ZZpdfPframe,30)
    plt.plot(refLonLat[:,0],refLonLat[:,1],'x')
    plt.show()
    
    plt.figure()
    plt.contour(lonMesh,latMesh,ZZpdfN,30)
    plt.plot(refLonLat[:,0],refLonLat[:,1],'x')
    plt.show()
    '''
    return (lonMesh,latMesh,ZZpdfN)
예제 #10
0
def getPDF(lonlat, pdfoption='kde', delta=None, nMesh=50):
    #lonlat is a nx2 matrix with lon lat locations
    # nsigma is only used for getting PDF area when using normal distribution
    # pdf option 'kde' or 'normal' dist
    # delta is spacing used for mesh in PDF
    # if delta not specified,then it will use nMesh which is the number of points used in one dim...total mesh will be nMesh x nMesh

    #this routine rotates the SPHERICAL planet to get a better 'flat planet' approximation by using local lat and lons and then applies the KDE or normal PDF routines

    xyz, x, y, z = getxyz(lonlat)
    xmean = np.mean(x)
    ymean = np.mean(y)
    zmean = np.mean(z)
    mag = (xmean**2 + ymean**2 + zmean**2)**.5
    lonlat0 = getlonlat(xmean / mag, ymean / mag, zmean / mag)
    lon0 = lonlat0[0, 0]
    lat0 = lonlat0[0, 1]
    beta = 0  # initial guess
    nSamples, dims = np.shape(lonlat)
    if dims != 2:
        print 'Error in lonlat, dimensions are not correct'
        print 'Check inputs to getPDF in casualtyEstimate.py'
        exit()

    beta = optimizeHeadingAngle(lonlat, nSamples, lon0, lat0, beta)

    R1 = Rotz(lon0 * np.pi / 180.)  # generating rotation matrices
    R2 = Roty(-lat0 * np.pi / 180.)
    R3 = Rotx(beta * np.pi / 180.)
    transformDetails = [R1, R2, R3, lon0, lat0, beta]

    Uint = np.dot(R2, R1)
    U = np.dot(R3, Uint)
    lonlatPframe = originalFrame2Pframe(lonlat, U)

    if pdfoption.lower() == 'kde' or pdfoption.lower() == 'kernel':
        xMeshP, yMeshP, xlen, ylen, areaInt = statsPython.areaOfInterestKDE(
            lonlatPframe, delta=delta,
            nMesh=nMesh)  # A frame could also be used
    elif pdfoption == 'normal' or pdfoption == 'gaussian' or pdfoption == 'gauss':
        #mean,covar = meancov.meancovmatrix(lonlatPframe,nSamples)
        #xMeshP,yMeshP,xlen,ylen = statsPython.areaOfInterest(mean,covar,delta,nsigma)
        xMeshP, yMeshP, xlen, ylen, areaInt = statsPython.areaOfInterestKDE(
            lonlatPframe, delta=delta,
            nMesh=nMesh)  # A frame could also be used

    lonlatPframeMesh = np.zeros((np.size(xMeshP), 2))
    lonlatPframeMesh[:, 0] = np.reshape(xMeshP, np.size(xMeshP))
    lonlatPframeMesh[:, 1] = np.reshape(yMeshP, np.size(yMeshP))
    lonlatOrFrameMesh = Pframe2originalFrame(lonlatPframeMesh, U)
    lonMesh, latMesh = getLonLatMesh(lonlatOrFrameMesh[:, 0],
                                     lonlatOrFrameMesh[:, 1], delta)

    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 = 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 = getxyz(lonlatVecP)  # mesh locations in P frame

    if pdfoption.lower() == 'kde' or pdfoption.lower() == 'kernel':
        #ZZpdf = meancov.kde(lonlatPframe,lonMeshP,latMeshP,[nSamples, xlen,ylen])
        print 'Starting quad KDE'
        ZZpdf = SK.serialK(nSamples, lonlatPframe, ylen, xlen, lonMeshP,
                           latMeshP, .1, 1)
        print 'Done with quad KDE'
    elif pdfoption == 'normal' or pdfoption == 'gaussian' or pdfoption == 'gauss':
        ZZpdf = meancov.normalbivariate(mean, covar, lonMeshP, latMeshP, xlen,
                                        ylen)  #fortran version

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

    PframeVals = [lonPMesh, latPMesh, ZZpdf]
    OrFrameVals = [lonMesh, latMesh, ZZpdfN]
    return (PframeVals, OrFrameVals, transformDetails, areaInt)