2323atol_dist = 1e-6 # 1 micrometer
2424
2525
26+ @pytest .mark .parametrize ('lla' ,
27+ [(42 , - 82 , 200 ),
28+ ([42 ], [- 82 ], [200 ]),
29+ (np .array (42 ), np .array (- 82 ), np .array (200 )),
30+ (np .array ([42 ]), np .array ([- 82 ]), np .array ([200 ])),
31+ (np .atleast_3d (42 ), np .atleast_3d (- 82 ), np .atleast_3d (200 ))],
32+ ids = ('scalar' , 'list' , '0d' , '1d' , '3d' ))
33+ def test_scalar_geodetic2ecef (lla ):
34+ """
35+ verify we can handle the wide variety of input data type users might use
36+ """
37+ x0 , y0 , z0 = pm .geodetic2ecef (* lla )
38+
39+ assert (x0 , y0 , z0 ) == approx (xyz0 )
40+
41+
42+ @pytest .mark .parametrize ('xyz' ,
43+ [(xyz0 [0 ], xyz0 [1 ], xyz0 [2 ]),
44+ ([xyz0 [0 ]], [xyz0 [1 ]], [xyz0 [2 ]]),
45+ (np .array (xyz0 [0 ]), np .array (xyz0 [1 ]), np .array (xyz0 [2 ])),
46+ (np .array ([xyz0 [0 ]]), np .array ([xyz0 [1 ]]), np .array ([xyz0 [2 ]])),
47+ (np .atleast_3d (xyz0 [0 ]), np .atleast_3d (xyz0 [1 ]), np .atleast_3d (xyz0 [2 ]))],
48+ ids = ('scalar' , 'list' , '0d' , '1d' , '3d' ))
49+ def test_scalar_ecef2geodetic (xyz ):
50+ """
51+ verify we can handle the wide variety of input data type users might use
52+ """
53+ lat , lon , alt = pm .ecef2geodetic (* xyz )
54+
55+ assert [lat , lon , alt ] == approx (lla0 , rel = 1e-4 )
56+
57+
58+ @pytest .mark .parametrize ('xyz' ,
59+ [(0 , E .a , 50 ),
60+ ([0 ], [E .a ], [50 ]),
61+ (np .array (0 ), np .array (E .a ), np .array (50 )),
62+ (np .array ([0 ]), np .array ([E .a ]), np .array ([50 ])),
63+ (np .atleast_3d (0 ), np .atleast_3d (E .a ), np .atleast_3d (50 ))],
64+ ids = ('scalar' , 'list' , '0d' , '1d' , '3d' ))
65+ def test_scalar_aer_enu (xyz ):
66+ """
67+ verify we can handle the wide variety of input data type users might use
68+ """
69+ enu = pm .ecef2enu (* xyz , 0 , 90 , - 100 )
70+
71+ assert pm .enu2ecef (* enu , 0 , 90 , - 100 ) == approx ([0 , E .a , 50 ])
72+
73+
74+ def test_xarray ():
75+ xarray = pytest .importorskip ('xarray' )
76+ xr_lla = xarray .DataArray (list (lla0 ))
77+
78+ xyz = pm .geodetic2ecef (* xr_lla )
79+
80+ assert xyz == approx (xyz0 )
81+ assert isinstance (xyz [0 ], xarray .DataArray )
82+ # %%
83+ xr_xyz = xarray .DataArray (list (xyz0 ))
84+
85+ lla = pm .ecef2geodetic (* xr_xyz )
86+
87+ assert lla == approx (lla0 )
88+ assert isinstance (lla [0 ], float ) # xarrayness is lost, possibly expensive to keep due to isinstance()
89+
90+
91+ def test_pandas ():
92+ pandas = pytest .importorskip ('pandas' )
93+ pd_lla = pandas .Series (lla0 )
94+
95+ xyz = pm .geodetic2ecef (* pd_lla )
96+
97+ assert xyz == approx (xyz0 )
98+ assert isinstance (xyz [0 ], float ) # series degenerates to scalars by pandas itself
99+ # %% dataframe degenerates to series
100+ pd_lla = pandas .DataFrame ([[* lla0 ], [* lla0 ]], columns = ['lat' , 'lon' , 'alt_m' ])
101+ xyz = pm .geodetic2ecef (pd_lla ['lat' ], pd_lla ['lon' ], pd_lla ['alt_m' ])
102+
103+ assert xyz [0 ].values == approx (xyz0 [0 ])
104+ assert xyz [1 ].values == approx (xyz0 [1 ])
105+ assert xyz [2 ].values == approx (xyz0 [2 ])
106+ assert isinstance (xyz [0 ], pandas .Series )
107+
108+
26109def test_ecef ():
27110 xyz = pm .geodetic2ecef (* lla0 )
28111
@@ -32,9 +115,6 @@ def test_ecef():
32115 with pytest .raises (ValueError ):
33116 pm .geodetic2ecef (- 100 , lla0 [1 ], lla0 [2 ])
34117
35- with pytest .raises (ValueError ):
36- pm .geodetic2ecef (lla0 [0 ], - 200 , lla0 [2 ])
37-
38118 assert pm .ecef2geodetic (* xyz ) == approx (lla0 )
39119 assert pm .ecef2geodetic (* xyz , deg = False ) == approx (rlla0 )
40120
@@ -93,4 +173,4 @@ def test_somenan():
93173
94174
95175if __name__ == '__main__' :
96- pytest .main ([__file__ ])
176+ pytest .main (['-x' , __file__ ])
0 commit comments