Commit 4f8c09b4 authored by Amy Stamile's avatar Amy Stamile
Browse files

switch to np.narray types

parent 9eccae5d
Loading
Loading
Loading
Loading
+14 −37
Original line number Diff line number Diff line
@@ -3,23 +3,18 @@ import numpy as np
from typing import NamedTuple

class Point(NamedTuple):
    x: np.double
    y: np.double
    z: np.double
    x: np.ndarray
    y: np.ndarray
    z: np.ndarray

class LatLon(NamedTuple):
    lat: np.double
    lon: np.double

    lat: np.ndarray
    lon: np.ndarray
# np.narray
class Sphere(NamedTuple):
    lat: np.double
    lon: np.double
    radius: np.double

class Matrix(NamedTuple):
    vec_a: Point
    vec_b: Point
    vec_c: Point
    lat: np.ndarray
    lon: np.ndarray
    radius: np.ndarray

def sep_angle(a_vec, b_vec):
    """
@@ -31,7 +26,7 @@ def sep_angle(a_vec, b_vec):

    Returns
    -------
    : float
    : np.ndarray
    """
    dot_prod = a_vec.x * b_vec.x + a_vec.y * b_vec.y + a_vec.z * b_vec.z
    dot_prod /= magnitude(a_vec) * magnitude(b_vec)
@@ -49,7 +44,7 @@ def magnitude(vec):

    Returns
    -------
    : float
    : np.ndarray
    """
    return np.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z)

@@ -63,7 +58,7 @@ def distance(start, stop):

    Returns
    -------
    : float
    : np.ndarray
    """
    diff = Point(stop.x - start.x, stop.y - start.y, stop.z - start.z)

@@ -133,7 +128,7 @@ def ground_azimuth(ground_pt, sub_pt):

    Returns
    -------
    : float
    : np.ndarray
    """
    if (ground_pt.lat >= 0.0):
      a = (90.0 - sub_pt.lat) * np.pi / 180.0
@@ -266,7 +261,7 @@ def scale_vector(vec, scalar):
    ----------
    vec : Point object (x, y, z)

    scalar : float
    scalar : np.ndarray

    Returns
    -------
@@ -274,24 +269,6 @@ def scale_vector(vec, scalar):
    """
    return Point(vec.x * scalar, vec.y * scalar, vec.z * scalar)

def matrix_vec_product(mat, vec):
    """
    Parameters
    ----------
    mat : Matrix object (vec_a, vec_b, vec_c)

    vec : Point object (x, y, z)

    Returns
    -------
    : Point object (x, y, z)
    """
    x = mat.vec_a.x * vec.x + mat.vec_a.y * vec.y + mat.vec_a.z * vec.z
    y = mat.vec_b.x * vec.x + mat.vec_b.y * vec.y + mat.vec_b.z * vec.z
    z = mat.vec_c.x * vec.x + mat.vec_c.y * vec.y + mat.vec_c.z * vec.z

    return Point(x, y, z)

def reproject(record, semi_major, semi_minor, source_proj, dest_proj, **kwargs):
    """
    Thin wrapper around PyProj's Transform() function to transform 1 or more three-dimensional
+1 −11
Original line number Diff line number Diff line
@@ -92,13 +92,3 @@ def test_scale_vector():
  scalar = 3.0
  result = utils.Point(3.0, 6.0, -9.0)
  np.testing.assert_array_equal(utils.scale_vector(vec, scalar), result)
 No newline at end of file

def test_matrix_vec_product():
  vec_a = utils.Point(0.0,  1.0,  0.0)
  vec_b = utils.Point(-1.0,  0.0,  0.0)
  vec_c = utils.Point(0.0,  0.0,  1.0)
  mat = utils.Matrix(vec_a, vec_b, vec_c)
  vec = utils.Point(1.0,  2.0,  3.0)

  result = utils.Point(2.0, -1.0, 3.0)
  np.testing.assert_array_equal(result, utils.matrix_vec_product(mat, vec))
 No newline at end of file