Passed
Push — master ( 573345...9597ff )
by Giacomo
06:15
created

hawc_hal.util.cartesian_()   A

Complexity

Conditions 5

Size

Total Lines 28
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 28
rs 9.3333
c 0
b 0
f 0
cc 5
nop 2
1
import numpy as np
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 'numpy'
Loading history...
2
3
4
def cartesian(arrays):
0 ignored issues
show
Coding Style introduced by
This function 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...
5
    return np.dstack(
6
        np.meshgrid(*arrays, indexing='ij')
7
        ).reshape(-1, len(arrays))
8
9
10
def cartesian_(arrays, out=None):
11
    """
12
    Generate a cartesian product of input arrays.
13
    """
14
15
    # A re-entrant function
16
17
    dtype = arrays[0].dtype
18
19
    n = np.prod([x.size for x in arrays])
0 ignored issues
show
Coding Style Naming introduced by
The name n does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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...
20
21
    # This happen only the first iteration
22
    if out is None:
23
24
        out = np.zeros([n, len(arrays)], dtype=dtype)
25
26
    m = n / arrays[0].size
0 ignored issues
show
Coding Style Naming introduced by
The name m does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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...
27
    out[:,0] = np.repeat(arrays[0], m)
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
28
29
    if arrays[1:]:
30
31
        cartesian_(arrays[1:], out=out[0:m, 1:])
32
33
        for j in range(1, arrays[0].size):
34
35
            out[j*m:(j+1)*m, 1:] = out[0:m, 1:]
36
37
    return out
38
39
40
def ra_to_longitude(ra):
0 ignored issues
show
Coding Style Naming introduced by
The name ra does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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...
Coding Style introduced by
This function 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...
41
42
    if ra > 180.0:
43
44
        longitude = -180 + (ra - 180.0)
45
46
    else:
47
48
        longitude = ra
49
50
    return longitude
51