geovectorslib.utils.wrap360deg()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
import numpy as np
2
3
4
def wrap90deg(deg: np.ndarray) -> np.ndarray:
5
    """
6
    Make sure that degrees (e.g. lats) is within -90;90 range.
7
8
    Ref: https://www.movable-type.co.uk/scripts/latlong-vincenty.html
9
    """
10
    mask = (deg < -90) | (deg > 90)
11
    deg[mask] = np.abs((deg[mask] % 360 + 270) % 360 - 180) - 90
12
    return deg
13
14
15
def wrap180deg(deg: np.ndarray) -> np.ndarray:
16
    """
17
    Make sure that degrees (e.g. lon) is within +/-(0-180) range.
18
19
    Ref: https://www.movable-type.co.uk/scripts/latlong-vincenty.html
20
    """
21
    # experimental value to fix https://github.com/omdv/geovectors/issues/2
22
    eps = 1e-6
23
24
    mask = (deg <= -180) | (deg >= 180)
25
    deg[mask] = (deg[mask] + 540) % 360 - 180
26
27
    deg = np.where(deg > 180 - eps, -180, deg)
28
    return deg
29
30
31
def wrap360deg(deg: np.ndarray) -> np.ndarray:
32
    """
33
    Make sure that degrees (e.g. heading) is within 360 range.
34
35
    Ref: https://www.movable-type.co.uk/scripts/latlong-vincenty.html
36
    """
37
    mask = (deg < 0) | (deg > 360)
38
    deg[mask] = (deg[mask] % 360 + 360) % 360
39
    return deg
40