Skip to content

Commit 7b9422b

Browse files
committed
changed format to pass tox checks
1 parent 9f1a660 commit 7b9422b

File tree

1 file changed

+92
-67
lines changed

1 file changed

+92
-67
lines changed

src/skaero/geometry/coordinates.py

+92-67
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def lla2ecef(lat, lng, h):
2929
ECEF coordinates in meters
3030
"""
3131
if abs(lat) > 90:
32-
raise ValueError('latitude should be -90º <= latitude <= 90º')
32+
raise ValueError("latitude should be -90º <= latitude <= 90º")
3333

3434
if abs(lng) > 180:
35-
raise ValueError('longitude should be -180º <= longitude <= 180º')
35+
raise ValueError("longitude should be -180º <= longitude <= 180º")
3636

3737
if not (0 <= h <= 84852.05):
38-
msg = 'pressure model is only valid if 0 <= h <= 84852.05'
38+
msg = "pressure model is only valid if 0 <= h <= 84852.05"
3939
raise ValueError(msg)
4040

4141
a = 6378137 # [m] Earth equatorial axis
@@ -45,11 +45,11 @@ def lla2ecef(lat, lng, h):
4545
lat = deg2rad(lat) # degrees to radians
4646
lng = deg2rad(lng) # degrees to radians
4747

48-
N = a / (1 - (e * sin(lat))**2)**(.5)
48+
N = a / (1 - (e * sin(lat)) ** 2) ** (0.5)
4949

5050
x = (N + h) * cos(lat) * cos(lng)
5151
y = (N + h) * cos(lat) * sin(lng)
52-
z = (((b/a)**2) * N + h) * sin(lat)
52+
z = (((b / a) ** 2) * N + h) * sin(lat)
5353

5454
return array([x, y, z])
5555

@@ -75,17 +75,21 @@ def ned2ecef(v_ned, lat, lng):
7575
vector expressed in ECEF coordinates
7676
"""
7777
if abs(lat) > 90:
78-
raise ValueError('latitude should be -90º <= latitude <= 90º')
78+
raise ValueError("latitude should be -90º <= latitude <= 90º")
7979

8080
if abs(lng) > 180:
81-
raise ValueError('longitude should be -180º <= longitude <= 180º')
81+
raise ValueError("longitude should be -180º <= longitude <= 180º")
8282

8383
lat = deg2rad(lat)
8484
lng = deg2rad(lng)
8585

86-
Lne = array([[-sin(lat) * cos(lng), -sin(lat) * sin(lng), cos(lat)],
87-
[-sin(lng), cos(lng), 0],
88-
[-cos(lat) * cos(lng), -cos(lat) * sin(lng), -sin(lat)]])
86+
Lne = array(
87+
[
88+
[-sin(lat) * cos(lng), -sin(lat) * sin(lng), cos(lat)],
89+
[-sin(lng), cos(lng), 0],
90+
[-cos(lat) * cos(lng), -cos(lat) * sin(lng), -sin(lat)],
91+
]
92+
)
8993

9094
Len = Lne.transpose()
9195
v_ecef = Len.dot(v_ned)
@@ -114,17 +118,21 @@ def ecef2ned(v_ecef, lat, lng):
114118
vector expressed in NED coordinates
115119
"""
116120
if abs(lat) > 90:
117-
raise ValueError('latitude should be -90º <= latitude <= 90º')
121+
raise ValueError("latitude should be -90º <= latitude <= 90º")
118122

119123
if abs(lng) > 180:
120-
raise ValueError('longitude should be -180º <= longitude <= 180º')
124+
raise ValueError("longitude should be -180º <= longitude <= 180º")
121125

122126
lat = deg2rad(lat)
123127
lng = deg2rad(lng)
124128

125-
Lne = array([[-sin(lat) * cos(lng), -sin(lat) * sin(lng), cos(lat)],
126-
[-sin(lng), cos(lng), 0],
127-
[-cos(lat) * cos(lng), -cos(lat) * sin(lng), -sin(lat)]])
129+
Lne = array(
130+
[
131+
[-sin(lat) * cos(lng), -sin(lat) * sin(lng), cos(lat)],
132+
[-sin(lng), cos(lng), 0],
133+
[-cos(lat) * cos(lng), -cos(lat) * sin(lng), -sin(lat)],
134+
]
135+
)
128136

129137
v_ned = Lne.dot(v_ecef)
130138

@@ -152,24 +160,30 @@ def body2ned(v_body, theta, phi, psi):
152160
v_ned : array_like
153161
vector expressed in local horizon (NED) coordinates
154162
"""
155-
if abs(theta) > np.pi/2:
156-
raise ValueError('theta should be -pi/2 <= theta <= pi/2')
163+
if abs(theta) > np.pi / 2:
164+
raise ValueError("theta should be -pi/2 <= theta <= pi/2")
157165

158166
if abs(phi) > np.pi:
159-
raise ValueError('phi should be -pi <= phi <= pi')
160-
161-
if not 0 <= psi <= 2*np.pi:
162-
raise ValueError('psi should be 0 <= psi <= 2*pi')
163-
164-
Lnb = array([[cos(theta) * cos(psi),
165-
sin(phi) * sin(theta) * cos(psi) - cos(phi) * sin(psi),
166-
cos(phi) * sin(theta) * cos(psi) + sin(phi) * sin(psi)],
167-
[cos(theta) * sin(psi),
168-
sin(phi) * sin(theta) * sin(psi) + cos(phi) * cos(psi),
169-
cos(phi) * sin(theta) * sin(psi) - sin(phi) * cos(psi)],
170-
[-sin(theta),
171-
sin(phi) * cos(theta),
172-
cos(phi) * cos(theta)]])
167+
raise ValueError("phi should be -pi <= phi <= pi")
168+
169+
if not 0 <= psi <= 2 * np.pi:
170+
raise ValueError("psi should be 0 <= psi <= 2*pi")
171+
172+
Lnb = array(
173+
[
174+
[
175+
cos(theta) * cos(psi),
176+
sin(phi) * sin(theta) * cos(psi) - cos(phi) * sin(psi),
177+
cos(phi) * sin(theta) * cos(psi) + sin(phi) * sin(psi),
178+
],
179+
[
180+
cos(theta) * sin(psi),
181+
sin(phi) * sin(theta) * sin(psi) + cos(phi) * cos(psi),
182+
cos(phi) * sin(theta) * sin(psi) - sin(phi) * cos(psi),
183+
],
184+
[-sin(theta), sin(phi) * cos(theta), cos(phi) * cos(theta)],
185+
]
186+
)
173187

174188
v_ned = Lnb.dot(v_body)
175189

@@ -197,24 +211,30 @@ def ned2body(v_ned, theta, phi, psi):
197211
v_body: array-like
198212
vector expressed in body coordinates
199213
"""
200-
if abs(theta) > np.pi/2:
201-
raise ValueError('theta should be -pi/2 <= theta <= pi/2')
214+
if abs(theta) > np.pi / 2:
215+
raise ValueError("theta should be -pi/2 <= theta <= pi/2")
202216

203217
if abs(phi) > np.pi:
204-
raise ValueError('phi should be -pi <= phi <= pi')
205-
206-
if not 0 <= psi <= 2*np.pi:
207-
raise ValueError('psi should be 0 <= psi <= 2*pi')
208-
209-
Lbn = array([[cos(theta) * cos(psi),
210-
cos(theta) * sin(psi),
211-
-sin(theta)],
212-
[sin(phi) * sin(theta) * cos(psi) - cos(phi) * sin(psi),
213-
sin(phi) * sin(theta) * sin(psi) + cos(phi) * cos(psi),
214-
sin(phi) * cos(theta)],
215-
[cos(phi) * sin(theta) * cos(psi) + sin(phi) * sin(psi),
216-
cos(phi) * sin(theta) * sin(psi) - sin(phi) * cos(psi),
217-
cos(phi) * cos(theta)]])
218+
raise ValueError("phi should be -pi <= phi <= pi")
219+
220+
if not 0 <= psi <= 2 * np.pi:
221+
raise ValueError("psi should be 0 <= psi <= 2*pi")
222+
223+
Lbn = array(
224+
[
225+
[cos(theta) * cos(psi), cos(theta) * sin(psi), -sin(theta)],
226+
[
227+
sin(phi) * sin(theta) * cos(psi) - cos(phi) * sin(psi),
228+
sin(phi) * sin(theta) * sin(psi) + cos(phi) * cos(psi),
229+
sin(phi) * cos(theta),
230+
],
231+
[
232+
cos(phi) * sin(theta) * cos(psi) + sin(phi) * sin(psi),
233+
cos(phi) * sin(theta) * sin(psi) - sin(phi) * cos(psi),
234+
cos(phi) * cos(theta),
235+
],
236+
]
237+
)
218238

219239
v_body = Lbn.dot(v_ned)
220240

@@ -239,15 +259,19 @@ def body2wind(v_body, alpha, beta):
239259
v_wind : array_like
240260
vector expressed in wind coordinates
241261
"""
242-
if abs(alpha) > np.pi/2:
243-
raise ValueError('alpha should be -pi/2 <= alpha <= pi/2')
262+
if abs(alpha) > np.pi / 2:
263+
raise ValueError("alpha should be -pi/2 <= alpha <= pi/2")
244264

245265
if abs(beta) > np.pi:
246-
raise ValueError('beta should be -pi <= beta <= pi')
266+
raise ValueError("beta should be -pi <= beta <= pi")
247267

248-
Lwb = array([[cos(alpha) * cos(beta), sin(beta), sin(alpha) * cos(beta)],
249-
[-cos(alpha) * sin(beta), cos(beta), -sin(alpha) * sin(beta)],
250-
[-sin(alpha), 0, cos(alpha)]])
268+
Lwb = array(
269+
[
270+
[cos(alpha) * cos(beta), sin(beta), sin(alpha) * cos(beta)],
271+
[-cos(alpha) * sin(beta), cos(beta), -sin(alpha) * sin(beta)],
272+
[-sin(alpha), 0, cos(alpha)],
273+
]
274+
)
251275

252276
v_wind = Lwb.dot(v_body)
253277

@@ -272,19 +296,19 @@ def wind2body(v_wind, alpha, beta):
272296
v_body : array_like
273297
vector expressed in body coordinates
274298
"""
275-
if abs(alpha) > np.pi/2:
276-
raise ValueError('alpha should be -pi/2 <= alpha <= pi/2')
299+
if abs(alpha) > np.pi / 2:
300+
raise ValueError("alpha should be -pi/2 <= alpha <= pi/2")
277301

278302
if abs(beta) > np.pi:
279-
raise ValueError('beta should be -pi <= beta <= pi')
303+
raise ValueError("beta should be -pi <= beta <= pi")
280304

281-
Lbw = array([[cos(alpha) * cos(beta),
282-
-cos(alpha) * sin(beta),
283-
-sin(alpha)],
284-
[sin(beta), cos(beta), 0],
285-
[sin(alpha) * cos(beta),
286-
-sin(alpha) * sin(beta),
287-
cos(alpha)]])
305+
Lbw = array(
306+
[
307+
[cos(alpha) * cos(beta), -cos(alpha) * sin(beta), -sin(alpha)],
308+
[sin(beta), cos(beta), 0],
309+
[sin(alpha) * cos(beta), -sin(alpha) * sin(beta), cos(alpha)],
310+
]
311+
)
288312

289313
v_body = Lbw.dot(v_wind)
290314

@@ -315,10 +339,10 @@ def az_elev_dist(lla, lla_ref):
315339
lat_ref, lng_ref, h_ref = lla_ref
316340

317341
if abs(lat) > 90 or abs(lat_ref) > 90:
318-
raise ValueError('latitude should be -90º <= latitude <= 90º')
342+
raise ValueError("latitude should be -90º <= latitude <= 90º")
319343

320344
if abs(lng) > 180 or abs(lng_ref) > 180:
321-
raise ValueError('longitude should be -180º <= longitude <= 180º')
345+
raise ValueError("longitude should be -180º <= longitude <= 180º")
322346

323347
v = lla2ecef(lat, lng, h) - lla2ecef(lat_ref, lng_ref, h_ref)
324348

@@ -330,8 +354,9 @@ def az_elev_dist(lla, lla_ref):
330354
if v_unit_ned[0] == v_unit_ned[1] == 0:
331355
elevation = np.pi / 2
332356
else:
333-
elevation = np.arctan(-v_unit_ned[2] / np.sqrt(v_unit_ned[0]**2 +
334-
v_unit_ned[1]**2))
357+
elevation = np.arctan(
358+
-v_unit_ned[2] / np.sqrt(v_unit_ned[0] ** 2 + v_unit_ned[1] ** 2)
359+
)
335360

336361
distance = np.linalg.norm(v)
337362

0 commit comments

Comments
 (0)