1
1
from collections .abc import Sequence
2
+ from typing import Tuple , Union
2
3
3
4
import numpy as np
4
5
5
6
from ...gridding .Q_blocks import QPoint_3D
6
7
7
8
8
9
class lonlat_cartesian_3D_transformer :
10
+ """Transformer between longitude,latitude and 3d dimension (x,y,z)."""
11
+
9
12
def __init__ (self ) -> None :
10
13
pass
11
14
12
- def transform (lng , lat , radius = 6371 ):
15
+ def transform (lng : np .ndarray , lat : np .ndarray , radius : float = 6371.0 ) -> Tuple [np .ndarray , np .ndarray ]:
16
+ """Transform lng, lat to x,y,z
17
+
18
+ Args:
19
+ lng (np.ndarray): lng
20
+ lat (np.ndarray): lat
21
+ radius (float, optional): radius of earth in km. Defaults to 6371.
22
+
23
+ Returns:
24
+ Tuple[np.ndarray, np.ndarray]: x,y,z
25
+ """
26
+
13
27
# Convert latitude and longitude from degrees to radians
14
28
lat_rad = np .radians (lat )
15
29
lng_rad = np .radians (lng )
@@ -21,15 +35,38 @@ def transform(lng, lat, radius=6371):
21
35
22
36
return x , y , z
23
37
24
- def inverse_transform (x , y , z , r = None ):
38
+ def inverse_transform (
39
+ x : np .ndarray , y : np .ndarray , z : np .ndarray , r : float = None
40
+ ) -> Tuple [np .ndarray , np .ndarray ]:
41
+ """transform x,y,z to lon, lat
42
+
43
+ Args:
44
+ x (np.ndarray): x
45
+ y (np.ndarray): y
46
+ z (np.ndarray): z
47
+ r (float, optional): Radius of your spherical coordinate. If not given, calculate from x,y,z. Defaults to None.
48
+
49
+ Returns:
50
+ Tuple[np.ndarray, np.ndarray]: longitude, latitude
51
+ """
25
52
if r is None :
26
53
r = np .sqrt (x ** 2 + y ** 2 + z ** 2 )
27
54
latitude = np .degrees (np .arcsin (z / r ))
28
55
longitude = np .degrees (np .arctan2 (y , x ))
29
56
return longitude , latitude
30
57
31
58
32
- def get_midpoint_3D (p1 , p2 , radius = 6371 ):
59
+ def get_midpoint_3D (p1 : QPoint_3D , p2 : QPoint_3D , radius : float = 6371.0 ) -> QPoint_3D :
60
+ """Get the mid-point of three QPoint_3D objet (vector)
61
+
62
+ Args:
63
+ p1 (QPoint_3D): p1
64
+ p2 (QPoint_3D): p2
65
+ radius (float, optional): radius of earth in km. Defaults to 6371.0.
66
+
67
+ Returns:
68
+ QPoint_3D: mid-point.
69
+ """
33
70
v1 = np .array ([p1 .x , p1 .y , p1 .z ])
34
71
v2 = np .array ([p2 .x , p2 .y , p2 .z ])
35
72
@@ -41,7 +78,19 @@ def get_midpoint_3D(p1, p2, radius=6371):
41
78
return p3
42
79
43
80
44
- def continuous_interpolation_3D_plotting (p1 , p2 , radius = 6371 ):
81
+ def continuous_interpolation_3D_plotting (
82
+ p1 : np .ndarray , p2 : np .ndarray , radius : float = 6371.0
83
+ ) -> Tuple [np .ndarray , np .ndarray , np .ndarray ]:
84
+ """interpolate 10 points on earth surface between the given two points. For plotting.
85
+
86
+ Args:
87
+ p1 (np.ndarray): p1
88
+ p2 (np.ndarray): p2
89
+ radius (float, optional): radius of earth in km. Defaults to 6371.0.
90
+
91
+ Returns:
92
+ Tuple[np.ndarray, np.ndarray, np.ndarray]: 10 x, 10 y, 10 z
93
+ """
45
94
v1 = np .array ([p1 [0 ], p1 [1 ], p1 [2 ]])
46
95
v2 = np .array ([p2 [0 ], p2 [1 ], p2 [2 ]])
47
96
0 commit comments