diff --git a/knoten/utils.py b/knoten/utils.py index 77da0bf7c9847b144e3a02fac66149388a62e9ab..2527bd2f82f007546ac6dd95303e42fcf32c72bb 100644 --- a/knoten/utils.py +++ b/knoten/utils.py @@ -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 diff --git a/tests/test_utils.py b/tests/test_utils.py index d68ab1882a116d4a875ee83c889d6d5d1d9e995b..46345f4aa5148037d9e30d4da70126bf95205bba 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -91,14 +91,4 @@ def test_scale_vector(): vec = utils.Point(1.0, 2.0, -3.0) scalar = 3.0 result = utils.Point(3.0, 6.0, -9.0) - np.testing.assert_array_equal(utils.scale_vector(vec, scalar), result) - -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 + np.testing.assert_array_equal(utils.scale_vector(vec, scalar), result) \ No newline at end of file