Utilities

Core Utils

geoana.utils.mkvc(x, numDims=1)[source]

Creates a vector with the number of dimension specified

e.g.:

a = np.array([1, 2, 3])

mkvc(a, 1).shape
    > (3, )

mkvc(a, 2).shape
    > (3, 1)

mkvc(a, 3).shape
    > (3, 1, 1)
geoana.utils.ndgrid(*args, **kwargs)[source]

Form tensorial grid for 1, 2, or 3 dimensions.

Returns as column vectors by default.

To return as matrix input:

ndgrid(…, vector=False)

The inputs can be a list or separate arguments.

e.g.:

a = np.array([1, 2, 3])
b = np.array([1, 2])

XY = ndgrid(a, b)
    > [[1 1]
       [2 1]
       [3 1]
       [1 2]
       [2 2]
       [3 2]]

X, Y = ndgrid(a, b, vector=False)
    > X = [[1 1]
           [2 2]
           [3 3]]
    > Y = [[1 2]
           [1 2]
           [1 2]]

Spatial

geoana.spatial.cartesian_2_cylindrical(grid, vec=None)[source]

Takes a grid or vector (if provided) defined in cartesian coordinates \((x, y, z)\) and transform it to cylindrical coordinates, \((r, \theta, z)\).

Required

Parameters:grid (numpy.ndarray) – grid in cartesian coordinates \((x, y, z)\)

Optional

Parameters:vec (numpy.ndarray) – (optional) vector defined in cartesian coordinates

Returns

Returns:grid or vector (if provided) in cylindrical coordinates \((r, \theta, z)\)
Return type:numpy.ndarray
geoana.spatial.cartesian_2_spherical(grid, vec=None)[source]

Takes a grid or vector (if provided) defined in cartesian coordinates \((x, y, z)\) and transform it to spherical coordinates, \((r, \theta, \phi)\).

Required

Parameters:grid (numpy.ndarray) – grid in cartesian coordinates \((x, y, z)\)

Optional

Parameters:vec (numpy.ndarray) – (optional) vector defined in cartesian coordinates

Returns

Returns:grid or vector (if provided) in spherical coordinates \((r, \theta, \phi)\)
Return type:numpy.ndarray
geoana.spatial.cylindrical_2_cartesian(grid, vec=None)[source]

Take a grid or vector (if provided) defined in cylindrical coordinates \((r, \theta, z)\) and transform it to cartesian coordinates, \((x, y, z)\).

Required

Parameters:grid (numpy.ndarray) – grid in cylindrical coordinates \((r, \theta, z)\)

Optional

Parameters:vec (numpy.ndarray) – (optional) vector defined in cylindrical coordinates

Returns

Returns:grid or vector (if provided) in cartesian coordinates \((x, y, z)\)
Return type:numpy.ndarray
geoana.spatial.distance(xyz, origin=array([ 0., 0., 0.]))[source]

Radial distance from an grid of points to the origin

Required

Parameters:xyz (numpy.ndarray) – grid (npoints x 3)

Optional

Parameters:origin (numpy.ndarray) – origin (default: [0., 0., 0.])

Returns

Returns:distance between each point and the origin (npoints x 1)
Return type:numpy.ndarray
geoana.spatial.repeat_scalar(scalar, dim=3)[source]

Repeat a spatially distributed scalar value dim times to simplify multiplication with a vector.

Required

Parameters:scalar (numpy.ndarray) – (n x 1) array of scalars

Optional

Parameters:dim (int) – dimension of the second axis for the output (default = 3)

Returns

Returns:(n x dim) array of the repeated vector
Return type:numpy.ndarray
geoana.spatial.rotate_points_from_normals(xyz, n0, n1, x0=array([ 0., 0., 0.]))[source]

rotates a grid so that the vector n0 is aligned with the vector n1

Required

Parameters:

Optional

Parameters:x0 (numpy.ndarray) – vector of length 3, point about which we perform the rotation

Returns

Return type:numpy.ndarray
Returns:(3x3) rotation matrix which rotates the frame so that n0 is aligned with n1
geoana.spatial.rotation_matrix_from_normals(v0, v1, tol=1e-20)[source]

Performs the minimum number of rotations to define a rotation from the direction indicated by the vector n0 to the direction indicated by n1. The axis of rotation is n0 x n1 https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula

Parameters:
  • v0 (numpy.ndarray) – vector of length 3
  • v1 (numpy.ndarray) – vector of length 3
  • tol (float) – tolerance. If the norm of the cross product between the two vectors is below this, no rotation is performed default = 1e-20
Return type:

numpy.ndarray

Returns:

3 x 3 rotation matrix which rotates the frame so that n0 is aligned with n1

geoana.spatial.spherical_2_cartesian(grid, vec=None)[source]

Take a grid or vector (if provided) defined in spherical coordinates \((r, \theta, \phi)\) and transform it to cartesian coordinates, \((x, y, z)\).

Required

Parameters:grid (numpy.ndarray) – grid in spherical coordinates \((r, \theta, \phi)\)

Optional

Parameters:vec (numpy.ndarray) – (optional) vector defined in spherical coordinates

Returns

Returns:grid or vector (if provided) in cartesian coordinates \((x, y, z)\)
Return type:numpy.ndarray
geoana.spatial.vector_distance(xyz, origin=array([ 0., 0., 0.]))[source]

Vector distance of a grid, xyz from an origin origin.

Required

Parameters:xyz (numpy.ndarray) – grid (npoints x 3)

Optional

Parameters:origin (numpy.ndarray) – origin (default: [0., 0., 0.])

Returns

Returns:vector distance from a grid of points from the origin (npoints x 3)
Return type:numpy.ndarray
geoana.spatial.vector_dot(xyz, vector)[source]

Take a dot product between an array of vectors, xyz and a vector [x, y, z]

Required

Parameters:

Returns

Returns:dot product between the grid and the (1 x 3) vector, returns an (npoints x 1) array
Return type:numpy.ndarray
geoana.spatial.vector_magnitude(v)[source]

Amplitude of a vector, v.

Required

Parameters:v (numpy.ndarray) – vector array

Returns

Returns:magnitude of a vector (n, 1)
Return type:numpy.ndarray