Passed
Push — master ( 07db9e...a24c88 )
by Oleg
01:22
created

geovectorslib.utils   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
A wrap90deg() 0 9 1
A wrap360deg() 0 9 1
A wrap180deg() 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
    mask = (deg <= -180) | (deg >= 180)
22
    deg[mask] = (deg[mask] + 540) % 360 - 180
23
    return deg
24
25
26
def wrap360deg(deg: 'np.ndarray') -> 'np.ndarray':
27
    """
28
    Make sure that degrees (e.g. heading) is within 360 range.
29
30
    Ref: https://www.movable-type.co.uk/scripts/latlong-vincenty.html
31
    """
32
    mask = (deg < 0) | (deg > 360)
33
    deg[mask] = (deg[mask] % 360 + 360) % 360
34
    return deg
35