Skip to content

Commit f783f61

Browse files
committed
fix tests and add test case for case at pole
1 parent 60cf6d6 commit f783f61

File tree

4 files changed

+65
-43
lines changed

4 files changed

+65
-43
lines changed

test/test_arcs.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import uxarray as ux
1111

1212
from uxarray.grid.coordinates import _lonlat_rad_to_xyz
13-
from uxarray.grid.arcs import point_within_gca, _point_within_gca_cartesian
13+
from uxarray.grid.arcs import point_within_gca
1414

1515
try:
1616
import constants
@@ -31,29 +31,29 @@ class TestIntersectionPoint(TestCase):
3131
def test_pt_within_gcr(self):
3232
# The GCR that's eexactly 180 degrees will have Value Error raised
3333

34-
gcr_180degree_cart = [
34+
gcr_180degree_cart = np.asarray([
3535
_lonlat_rad_to_xyz(0.0, np.pi / 2.0),
3636
_lonlat_rad_to_xyz(0.0, -np.pi / 2.0)
37-
]
37+
])
38+
pt_same_lon_in = np.asarray(_lonlat_rad_to_xyz(0.0, 0.0))
3839

39-
pt_same_lon_in = _lonlat_rad_to_xyz(0.0, 0.0)
4040
with self.assertRaises(ValueError):
41-
_point_within_gca_cartesian(pt_same_lon_in, gcr_180degree_cart)
42-
41+
point_within_gca(pt_same_lon_in, gcr_180degree_cart[0],gcr_180degree_cart[1] )
42+
#
4343
# Test when the point and the GCA all have the same longitude
44-
gcr_same_lon_cart = [
44+
gcr_same_lon_cart = np.asarray([
4545
_lonlat_rad_to_xyz(0.0, 1.5),
4646
_lonlat_rad_to_xyz(0.0, -1.5)
47-
]
48-
pt_same_lon_in = _lonlat_rad_to_xyz(0.0, 0.0)
49-
self.assertTrue(_point_within_gca_cartesian(pt_same_lon_in, gcr_same_lon_cart))
47+
])
48+
pt_same_lon_in = np.asarray(_lonlat_rad_to_xyz(0.0, 0.0))
49+
self.assertTrue(point_within_gca(pt_same_lon_in, gcr_same_lon_cart[0], gcr_same_lon_cart[1]))
5050

51-
pt_same_lon_out = _lonlat_rad_to_xyz(0.0, 1.5000001)
52-
res = _point_within_gca_cartesian(pt_same_lon_out, gcr_same_lon_cart)
51+
pt_same_lon_out = np.asarray(_lonlat_rad_to_xyz(0.0, 1.5000001))
52+
res = point_within_gca(pt_same_lon_out, gcr_same_lon_cart[0], gcr_same_lon_cart[1])
5353
self.assertFalse(res)
5454

55-
pt_same_lon_out_2 = _lonlat_rad_to_xyz(0.1, 1.0)
56-
res = _point_within_gca_cartesian(pt_same_lon_out_2, gcr_same_lon_cart)
55+
pt_same_lon_out_2 = np.asarray(_lonlat_rad_to_xyz(0.1, 1.0))
56+
res = point_within_gca(pt_same_lon_out_2, gcr_same_lon_cart[0], gcr_same_lon_cart[1])
5757
self.assertFalse(res)
5858

5959
def test_pt_within_gcr_antimeridian(self):
@@ -64,13 +64,13 @@ def test_pt_within_gcr_antimeridian(self):
6464
pt_cart = np.array(
6565
[0.9438777657502077, 0.1193199333436068, 0.922714737029319])
6666
self.assertTrue(
67-
_point_within_gca_cartesian(pt_cart, gcr_cart))
67+
point_within_gca(pt_cart, gcr_cart[0], gcr_cart[1]))
6868

6969
gcr_cart_flip = np.array([[0.617, 0.672, 0.410], [0.351, -0.724,
7070
0.593]])
7171
# If we flip the gcr in the undirected mode, it should still work
7272
self.assertTrue(
73-
_point_within_gca_cartesian(pt_cart, gcr_cart_flip))
73+
point_within_gca(pt_cart, gcr_cart_flip[0], gcr_cart_flip[1]))
7474

7575
# 2nd anti-meridian case
7676
# GCR vertex0 in radian : [4.104711496596806, 0.5352983676533828],
@@ -81,7 +81,7 @@ def test_pt_within_gcr_antimeridian(self):
8181
pt_cart_within = np.array(
8282
[0.6136726305712109, 0.28442243941920053, -0.365605190899831])
8383
self.assertFalse(
84-
_point_within_gca_cartesian(pt_cart_within, gcr_cart_1))
84+
point_within_gca(pt_cart_within, gcr_cart_1[0], gcr_cart_1[1]))
8585

8686

8787

@@ -93,5 +93,4 @@ def test_pt_within_gcr_cross_pole(self):
9393
# Normalize the point abd the GCA
9494
pt_cart = pt_cart / np.linalg.norm(pt_cart)
9595
gcr_cart = np.array([x / np.linalg.norm(x) for x in gcr_cart])
96-
self.assertTrue(_point_within_gca_cartesian(pt_cart, gcr_cart))
97-
96+
self.assertTrue(point_within_gca(pt_cart, gcr_cart[0], gcr_cart[1]))

test/test_intersections.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ def test_get_GCA_GCA_intersections_perpendicular(self):
9292
self.assertTrue(len(res_cart) == 0)
9393

9494

95+
def test_GCA_GCA_pole(self):
96+
face_lonlat = np.deg2rad(np.array([-175, 26.5]))
97+
98+
# this fails when the pole is set to exactly -90.0
99+
ref_point_lonlat = np.deg2rad(np.array([0.0, -89.9]))
100+
face_xyz = np.array(_lonlat_rad_to_xyz(*face_lonlat))
101+
ref_point_xyz = np.array(_lonlat_rad_to_xyz(*ref_point_lonlat))
102+
103+
edge_a_lonlat = np.deg2rad(np.array((-175, -24.5)))
104+
edge_b_lonlat = np.deg2rad(np.array((-173, 25.7)))
105+
106+
edge_a_xyz = np.array(_lonlat_rad_to_xyz(*edge_a_lonlat))
107+
edge_b_xyz = np.array(_lonlat_rad_to_xyz(*edge_b_lonlat))
108+
109+
gca_a_xyz = np.array([face_xyz, ref_point_xyz])
110+
111+
gca_b_xyz = np.array([edge_a_xyz, edge_b_xyz])
112+
113+
# The edge should intersect
114+
self.assertTrue(len(gca_gca_intersection(gca_a_xyz, gca_b_xyz)))
115+
116+
117+
118+
95119
class TestGCAconstLatIntersection(TestCase):
96120

97121
def test_GCA_constLat_intersections_antimeridian(self):

uxarray/grid/arcs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def _to_list(obj):
2828
return obj
2929

3030

31-
def _point_within_gca_cartesian(pt_xyz, gca_xyz):
32-
pt_xyz = np.asarray(pt_xyz)
33-
gca_xyz = np.asarray(gca_xyz)
34-
35-
gca_a_xyz = gca_xyz[0]
36-
37-
gca_b_xyz = gca_xyz[1]
38-
39-
return point_within_gca(pt_xyz, gca_a_xyz, gca_b_xyz)
31+
# def _point_within_gca_cartesian(pt_xyz, gca_xyz):
32+
# pt_xyz = np.asarray(pt_xyz)
33+
# gca_xyz = np.asarray(gca_xyz)
34+
#
35+
# gca_a_xyz = gca_xyz[0]
36+
#
37+
# gca_b_xyz = gca_xyz[1]
38+
#
39+
# return point_within_gca(pt_xyz, gca_a_xyz, gca_b_xyz)
4040

4141

4242
@njit(cache=True)

uxarray/grid/intersections.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import numpy as np
22
from uxarray.constants import MACHINE_EPSILON, ERROR_TOLERANCE, INT_DTYPE
3-
from uxarray.grid.utils import _newton_raphson_solver_for_gca_constLat, _angle_of_2_vectors
3+
from uxarray.grid.utils import (
4+
_newton_raphson_solver_for_gca_constLat,
5+
_angle_of_2_vectors,
6+
)
47
from uxarray.grid.arcs import (
5-
point_within_gca,
68
in_between,
79
_extreme_gca_latitude_cartesian,
8-
_point_within_gca_cartesian,
10+
point_within_gca,
911
)
10-
from uxarray.grid.coordinates import _xyz_to_lonlat_rad_scalar
1112
import platform
1213
import warnings
1314
from uxarray.utils.computing import cross_fma, allclose, cross, norm
@@ -252,24 +253,22 @@ def gca_gca_intersection(gca_a_xyz, gca_b_xyz):
252253
x1_xyz = cross_norms
253254
x2_xyz = -x1_xyz
254255
# Check intersection points
255-
if point_within_gca(
256-
x1_xyz, w0_xyz, w1_xyz
257-
) and point_within_gca(x1_xyz, v0_xyz, v1_xyz):
256+
if point_within_gca(x1_xyz, w0_xyz, w1_xyz) and point_within_gca(
257+
x1_xyz, v0_xyz, v1_xyz
258+
):
258259
res[count, :] = x1_xyz
259260
count += 1
260261

261-
if point_within_gca(
262-
x2_xyz, w0_xyz, w1_xyz
263-
) and point_within_gca(x2_xyz, v0_xyz, v1_xyz):
262+
if point_within_gca(x2_xyz, w0_xyz, w1_xyz) and point_within_gca(
263+
x2_xyz, v0_xyz, v1_xyz
264+
):
264265
res[count, :] = x2_xyz
265266
count += 1
266267

267268
return res[:count, :]
268269

269270

270-
def gca_const_lat_intersection(
271-
gca_cart, constZ, fma_disabled=True, verbose=False
272-
):
271+
def gca_const_lat_intersection(gca_cart, constZ, fma_disabled=True, verbose=False):
273272
"""Calculate the intersection point(s) of a Great Circle Arc (GCA) and a
274273
constant latitude line in a Cartesian coordinate system.
275274
@@ -360,7 +359,7 @@ def gca_const_lat_intersection(
360359
res = None
361360

362361
# Now test which intersection point is within the GCA range
363-
if _point_within_gca_cartesian(p1, gca_cart):
362+
if point_within_gca(p1, gca_cart[0], gca_cart[1]):
364363
try:
365364
converged_pt = _newton_raphson_solver_for_gca_constLat(
366365
p1, gca_cart, verbose=verbose
@@ -382,7 +381,7 @@ def gca_const_lat_intersection(
382381
except RuntimeError:
383382
raise RuntimeError(f"Error encountered with initial guess: {p1}")
384383

385-
if _point_within_gca_cartesian(p2, gca_cart):
384+
if point_within_gca(p2, gca_cart[0], gca_cart[1]):
386385
try:
387386
converged_pt = _newton_raphson_solver_for_gca_constLat(
388387
p2, gca_cart, verbose=verbose

0 commit comments

Comments
 (0)