Completed
Push — master ( fd2cae...1dc21f )
by J. Michael
08:43 queued 07:25
created

PolarResponse._interpolate_rsp()   A

Complexity

Conditions 4

Size

Total Lines 60
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 23
nop 1
dl 0
loc 60
rs 9.328
c 0
b 0
f 0

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
import h5py
0 ignored issues
show
introduced by
Unable to import 'h5py'
Loading history...
3
import scipy.interpolate as interpolate
0 ignored issues
show
introduced by
Unable to import 'scipy.interpolate'
Loading history...
4
5
6
7
class PolarResponse(object):
0 ignored issues
show
Coding Style introduced by
This class 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...
best-practice introduced by
Too many instance attributes (9/7)
Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
8
9
    def __init__(self, response_file):
10
11
        self._rsp_file = response_file
12
13
        self._interpolate_rsp()
14
15
    # def _get_hist(self, ene,degree,angle):
16
17
18
    #     with h5py.File(self._rsp_file,'r') as f:
19
20
21
22
    #        # bins = np.array(f['bins'].value)
23
24
    #     return  tmp
25
26
27
    def _interpolate_rsp(self):
28
        """
29
        Builds the interpolator for the response. This is currently incredibly slow
30
        and should be improved
31
32
        """
33
34
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
35
        # create a functions to get the histograms
36
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
37
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
38
        # now go through the response and extract things
39
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
40
        with h5py.File(self._rsp_file,'r') as f:
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
Coding Style Naming introduced by
The name f 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...
41
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
42
43
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
44
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
45
            energy = f['energy'].value
46
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
47
            ene_lo, ene_hi = [],[]
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
48
49
            for ene in energy:
50
51
                ene_lo.append(ene-2.5)
52
                ene_hi.append(ene+2.5)
53
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
54
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
55
            pol_ang = np.array(f['pol_ang'].value)
56
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
57
            pol_deg = np.array(f['pol_deg'].value)
58
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
59
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
60
            bins = np.array(f['bins'].value)
61
62
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
63
            bin_center = 0.5 *(bins[:-1] + bins[1:])
64
65
            all_interp = []
66
67
68
69
            for i, bm in enumerate(bin_center):
0 ignored issues
show
Coding Style Naming introduced by
The name bm 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...
Unused Code introduced by
The variable bm seems to be unused.
Loading history...
70
71
72
                this_interpolator = interpolate.RegularGridInterpolator((energy,pol_ang,pol_deg), f['matrix'][...,i])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Exactly one space required after comma
Loading history...
73
74
75
                all_interp.append(this_interpolator)
76
                
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
77
            self._all_interp = all_interp
78
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
79
            self._ene_lo = ene_lo
80
            self._ene_hi = ene_hi
81
            self._energy_mid = energy
82
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
83
            self._n_scatter_bins = len(bin_center)
84
            self._scattering_bins = bin_center
85
            self._scattering_bins_lo = bins[:-1]
86
            self._scattering_bins_hi = bins[1:]
87
88
89
    @property
90
    def ene_lo(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
91
        return self._ene_lo
92
93
    @property
94
    def ene_hi(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
95
        return self._ene_hi
96
97
    @property
98
    def energy_mid(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
99
        return self._energy_mid
100
101
    @property
102
    def n_scattering_bins(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
103
        return self._n_scatter_bins
104
105
    @property
106
    def scattering_bins(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
107
        return self._scattering_bins
108
109
    @property
110
    def scattering_bins_lo(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
111
        return self._scattering_bins_lo
112
113
    @property
114
    def scattering_bins_hi(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
115
        return self._scattering_bins_hi
116
117
    @property
118
    def interpolators(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
119
        return self._all_interp
120
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
121