Passed
Push — master ( 20ef60...3972dc )
by Giacomo
10:31
created

get_gnomonic_projection()   A

Complexity

Conditions 4

Size

Total Lines 67
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 67
rs 9.0399
c 0
b 0
f 0
cc 4
nop 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
from healpy import projaxes as PA
0 ignored issues
show
introduced by
Unable to import 'healpy'
Loading history...
3
import matplotlib.pyplot as plt
0 ignored issues
show
introduced by
Unable to import 'matplotlib.pyplot'
Loading history...
Unused Code introduced by
Unused matplotlib.pyplot imported as plt
Loading history...
4
5
6
def get_gnomonic_projection(figure, hpx_map, **kwargs):
7
    """
8
    Returns an array containing the Gnomonic projection of the provided Healpix map.
9
10
    This is equivalent to hp.gnomview of Healpy BUT the projected array is NOT plotted in the figure, so you can
11
    plot it later on.
12
13
    :param figure: a matplotlib Figure
14
    :param hpx_map: the healpix map
15
    :param **kwargs: keywords accepted by hp.gnomview
16
    :return: the array containing the projection.
17
    """
18
19
    defaults = {'coord': 'C',
20
                'rot': None,
21
                'format': '%g',
22
                'flip': 'astro',
23
                'xsize': 200,
24
                'ysize': None,
25
                'reso': 1.5,
26
                'nest': False,
27
                'min': None,
28
                'max': None,
29
                'cmap': None,
30
                'norm': None}
31
32
    for key, default_value in defaults.items():
33
34
        if key not in kwargs:
35
36
            kwargs[key] = default_value
37
38
    ## Colas, 2018-07-11: The following fails for really tall figures,
39
    ## as happens with 2D binning. Top ends up negative, probably matplotlib bug.
40
    ## So hard code extent instead. Keep the code for now if we want to fix it.
41
    # left, bottom, right, top = np.array(plt.gca().get_position()).ravel()
42
    # extent = (left, bottom, right - left, top - bottom)
43
    # margins = (0.01, 0.0, 0.0, 0.02)
44
    # extent = (extent[0] + margins[0],
45
    #           extent[1] + margins[1],
46
    #           extent[2] - margins[2] - margins[0],
47
    #           extent[3] - margins[3] - margins[1])
48
    extent = (0.05, 0.05, 0.9, 0.9)
49
50
    ax = PA.HpxGnomonicAxes(figure, extent,
0 ignored issues
show
Coding Style Naming introduced by
Variable name "ax" 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...
51
                            coord=kwargs['coord'],
52
                            rot=kwargs['rot'],
53
                            format=kwargs['format'],
54
                            flipconv=kwargs['flip'])
55
56
    # Suppress warnings about nans
57
    with np.warnings.catch_warnings():
58
59
        np.warnings.filterwarnings('ignore')
60
61
        img = ax.projmap(hpx_map,
62
                         nest=kwargs['nest'],
63
                         coord=kwargs['coord'],
64
                         vmin=kwargs['min'],
65
                         vmax=kwargs['max'],
66
                         xsize=kwargs['xsize'],
67
                         ysize=kwargs['ysize'],
68
                         reso=kwargs['reso'],
69
                         cmap=kwargs['cmap'],
70
                         norm=kwargs['norm'])
71
72
    return img
73