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

geovectorslib.utils.wrap90deg()   A

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
    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