Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Knoten
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aflab
astrogeology
Knoten
Commits
4f8c09b4
Commit
4f8c09b4
authored
1 year ago
by
Amy Stamile
Browse files
Options
Downloads
Patches
Plain Diff
switch to np.narray types
parent
9eccae5d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
knoten/utils.py
+14
-37
14 additions, 37 deletions
knoten/utils.py
tests/test_utils.py
+1
-11
1 addition, 11 deletions
tests/test_utils.py
with
15 additions
and
48 deletions
knoten/utils.py
+
14
−
37
View file @
4f8c09b4
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
tests/test_utils.py
+
1
−
11
View file @
4f8c09b4
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment