Beispiel #1
0
def proj_xyz(n,file_cov,output_file,option_cov=None):
	''' Program that outputs x,y,z,teta,semi-major,semi-minor from a x,y,z,cxx,cyy,czz,cxy,cxz,cyz
	file (generally given by a nor2cov process). option_cov specifies if COV is given in the non-direct basis Oxyz but z downward.
	n is the viewpoint in the Oxyz direct basis (z upward). You don't care if z is negative in the 3rd column as it only copies this column'''

	#file_cov='test.xyz'
	#output_file='proj_ellipse.xyz'
	f1=open(file_cov,'r')
	f2=open(output_file,'w')
	#n=[0,0,-1]

	lines=f1.readlines()

	for line in lines:
		A=line.split()
		if len(A)!=9:
			f2.write('-999\n')
			continue
		# Assigne COV matrix
		COV=np.zeros((3,3))
		COV[0,0]=A[3]
		COV[1,1]=A[4]
		COV[2,2]=A[5]
		COV[0,1]=A[6]
		COV[0,2]=A[7]
		COV[1,2]=A[8]
		COV=COV+np.transpose(np.triu(COV,1))
		
		#### If Z is positive down then multiply by special matrix
		
		if option_cov != None:
			M=np.array([[1,1,-1],[1,1,-1],[-1,-1,1]])

			COV=COV*M
		
		teta,semi_major,semi_minor=proj_cov(n,COV)
		#print teta
		f2.write('%9s %9s %7s %6.1f %7.2f %7.2f\n' %(A[0],A[1],A[2],teta,semi_major,semi_minor))
		

	f1.close()
	f2.close()
Beispiel #2
0
def proj_xyz(n, file_cov, output_file, option_cov=None):
    ''' Program that outputs x,y,z,teta,semi-major,semi-minor from a x,y,z,cxx,cyy,czz,cxy,cxz,cyz
	file (generally given by a nor2cov process). option_cov specifies if COV is given in the non-direct basis Oxyz but z downward.
	n is the viewpoint in the Oxyz direct basis (z upward). You don't care if z is negative in the 3rd column as it only copies this column'''

    #file_cov='test.xyz'
    #output_file='proj_ellipse.xyz'
    f1 = open(file_cov, 'r')
    f2 = open(output_file, 'w')
    #n=[0,0,-1]

    lines = f1.readlines()

    for line in lines:
        A = line.split()
        if len(A) != 9:
            f2.write('-999\n')
            continue
        # Assigne COV matrix
        COV = np.zeros((3, 3))
        COV[0, 0] = A[3]
        COV[1, 1] = A[4]
        COV[2, 2] = A[5]
        COV[0, 1] = A[6]
        COV[0, 2] = A[7]
        COV[1, 2] = A[8]
        COV = COV + np.transpose(np.triu(COV, 1))

        #### If Z is positive down then multiply by special matrix

        if option_cov != None:
            M = np.array([[1, 1, -1], [1, 1, -1], [-1, -1, 1]])

            COV = COV * M

        teta, semi_major, semi_minor = proj_cov(n, COV)
        #print teta
        f2.write('%9s %9s %7s %6.1f %7.2f %7.2f\n' %
                 (A[0], A[1], A[2], teta, semi_major, semi_minor))

    f1.close()
    f2.close()
Beispiel #3
0
def ang2ell(az,phi,proj):
	## AZ is the azimuth CW from north, PH is the angle of the norm CW from Z upward
	## proj is the normal to projection define in the ENZ base for ex [0,0,1]

	az=az*np.pi/180
	phi=phi*np.pi/180

	####### Get n 

	nz=np.cos(phi)
	nx=np.sin(phi)*np.sin(az)
	ny=np.sin(phi)*np.cos(az)

	n=np.array([nx,ny,nz])

	####### Get perpendicular vectors to n

	z=np.array([0,0,1])
	u1=np.cross(n,z)
	u1=u1/np.linalg.norm(u1)
	u2=np.cross(n,u1)
	u2=u2/np.linalg.norm(u2)

	####### Reconstruct covariance

	lambda_mat=np.eye(3)
	lambda_mat[2,2]=0
	U=np.zeros(shape=(3,3))
	U[0][:]=u1
	U[1][:]=u2
	U[2][:]=n

	U=U.transpose()

	COV=np.dot(np.dot(U,lambda_mat),np.linalg.inv(U))
	
	### Get angles and major axes
	teta,major,minor=proj_cov(proj,COV)

	return teta,major,minor
Beispiel #4
0
def ang2ell(az, phi, proj):
    ## AZ is the azimuth CW from north, PH is the angle of the norm CW from Z upward
    ## proj is the normal to projection define in the ENZ base for ex [0,0,1]

    az = az * np.pi / 180
    phi = phi * np.pi / 180

    ####### Get n

    nz = np.cos(phi)
    nx = np.sin(phi) * np.sin(az)
    ny = np.sin(phi) * np.cos(az)

    n = np.array([nx, ny, nz])

    ####### Get perpendicular vectors to n

    z = np.array([0, 0, 1])
    u1 = np.cross(n, z)
    u1 = u1 / np.linalg.norm(u1)
    u2 = np.cross(n, u1)
    u2 = u2 / np.linalg.norm(u2)

    ####### Reconstruct covariance

    lambda_mat = np.eye(3)
    lambda_mat[2, 2] = 0
    U = np.zeros(shape=(3, 3))
    U[0][:] = u1
    U[1][:] = u2
    U[2][:] = n

    U = U.transpose()

    COV = np.dot(np.dot(U, lambda_mat), np.linalg.inv(U))

    ### Get angles and major axes
    teta, major, minor = proj_cov(proj, COV)

    return teta, major, minor