geovectorslib.utils   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A wrap90deg() 0 9 1
A wrap180deg() 0 14 1
A wrap360deg() 0 9 1
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