Package ivs :: Package coordinates :: Module vectors
[hide private]
[frames] | no frames]

Module vectors

source code

Vector and coordinate identities and transformations

General conventions:

Transform cartesian coordinates to spherical coordinates and back

>>> x,y,z = np.random.uniform(low=-1,high=1,size=(3,10))
>>> r,phi,theta = cart2spher_coord(x,y,z)
>>> x_,y_,z_ = spher2cart_coord(r,phi,theta)
>>> np.allclose(x,x_),np.allclose(y,y_),np.allclose(z,z_)
(True, True, True)

Transform cartesian vectors to spherical vectors and back

>>> x0,y0,z0 = np.random.uniform(low=-1,high=1,size=(3,10))
>>> x1,y1,z1 = np.random.uniform(low=-1,high=1,size=(3,10))
>>> r0,phi0,theta0 = cart2spher_coord(x0,y0,z0)
>>> r1,phi1,theta1 = cart2spher((x0,y0,z0),(x1,y1,z1))
>>> x1_,y1_,z1_ = spher2cart((r0,phi0,theta0),(r1,phi1,theta1))
>>> np.allclose(x1,x1_),np.allclose(y1,y1_),np.allclose(z1,z1_)
(True, True, True)
Functions [hide private]
    Coordinate transformations
 
spher2cart_coord(r, phi, theta)
Spherical to Cartesian coordinates
source code
 
cart2spher_coord(x, y, z)
theta colatitude phi longitude
source code
 
rotate(x, y, theta, x0=0., y0=0.)
Rotate counter clockwise.
source code
    Coordinate vector transformations
 
spher2cart((r, phi, theta), (a_r, a_phi, a_theta))
theta is angle from z-axis (colatitude) phi is longitude
source code
 
cart2spher((x0, y0, z0), (x1, y1, z1))
theta is angle from z-axis (colatitude) phi is longitude
source code
    Vector identities
 
norm(vec)
Euclidic norm of a vector (or of a grid of vectors)
source code
 
angle(vec1, vec2)
Compute angle between two vectors (or between two grids of vectors).
source code
 
cos_angle(vec1, vec2)
Compute cosine of angle between two vectors (or between two grids of vectors).
source code
Function Details [hide private]

spher2cart((r, phi, theta), (a_r, a_phi, a_theta))

source code 

theta is angle from z-axis (colatitude) phi is longitude

E.g. http://www.engin.brown.edu/courses/en3/Notes/Vector_Web2/Vectors6a/Vectors6a.htm

>>> np.random.seed(111)
>>> r,phi,theta = np.random.uniform(low=-1,high=1,size=(3,2))
>>> a_r,a_phi,a_theta = np.random.uniform(low=-1,high=1,size=(3,2))
>>> a_x,a_y,a_z = spher2cart((r,phi,theta),(a_r,a_phi,a_theta))

cart2spher((x0, y0, z0), (x1, y1, z1))

source code 

theta is angle from z-axis (colatitude) phi is longitude

return r,phi,theta

norm(vec)

source code 

Euclidic norm of a vector (or of a grid of vectors)

Input vectors should be numpy arrays.

angle(vec1, vec2)

source code 

Compute angle between two vectors (or between two grids of vectors).

Input vectors should be numpy arrays.

cos_angle(vec1, vec2)

source code 

Compute cosine of angle between two vectors (or between two grids of vectors).

Input vectors should be numpy arrays.