Passed
Push — master ( 3972dc...1ec1dd )
by Giacomo
15:14
created

hawc_hal.sphere_dist.sphere_dist()   A

Complexity

Conditions 1

Size

Total Lines 29
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 29
rs 9.75
c 0
b 0
f 0
cc 1
nop 4
1
from numba import jit
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
introduced by
Unable to import 'numba'
Loading history...
2
import numpy as np
0 ignored issues
show
introduced by
Unable to import 'numpy'
Loading history...
3
4
5
# A fast way to compute angular distances
6
@jit("float64[:](float64, float64, float64[:], float64[:])", nopython=True)
7
def sphere_dist(ra1, dec1, ra2, dec2):  # pragma: no cover
8
    """
9
    Compute angular distance using the Haversine formula. Use this one when you know you will never ask for points at
10
    their antipodes. If this is not the case, use the angular_distance function which is slower, but works also for
11
    antipodes.
12
13
    :param ra1: first RA (deg)
14
    :param dec1: first Dec (deg)
15
    :param ra2: second RA (deg)
16
    :param dec2: second Dec (deg)
17
18
    :returns: angular separation distance (deg)
19
    """
20
21
    deg2rad = 0.017453292519943295
22
    rad2deg = 57.29577951308232
23
24
    lon1 = ra1 * deg2rad
25
    lat1 = dec1 * deg2rad
26
    lon2 = ra2 * deg2rad
27
    lat2 = dec2 * deg2rad
28
    dlon = lon2 - lon1
29
    dlat = lat2 - lat1
30
31
    a = np.sin(dlat/2.0)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon /2.0)**2
0 ignored issues
show
Coding Style Naming introduced by
Variable name "a" doesn't conform to snake_case naming style ('(([a-z_][a-z0-9_]2,30)|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
32
    c = 2 * np.arcsin(np.sqrt(a))
0 ignored issues
show
Coding Style Naming introduced by
Variable name "c" doesn't conform to snake_case naming style ('(([a-z_][a-z0-9_]2,30)|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
33
34
    return c * rad2deg
35