Total Complexity | 8 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import numpy as np |
||
2 | |||
3 | |||
4 | def cartesian(arrays): |
||
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]) |
||
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 |
||
27 | out[:,0] = np.repeat(arrays[0], m) |
||
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): |
||
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 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.