Conditions | 4 |
Total Lines | 60 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | import numpy as np |
||
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 | |||
35 | # create a functions to get the histograms |
||
36 | |||
37 | |||
38 | # now go through the response and extract things |
||
39 | |||
40 | with h5py.File(self._rsp_file,'r') as f: |
||
41 | |||
42 | |||
43 | |||
44 | |||
45 | energy = f['energy'].value |
||
46 | |||
47 | ene_lo, ene_hi = [],[] |
||
48 | |||
49 | for ene in energy: |
||
50 | |||
51 | ene_lo.append(ene-2.5) |
||
52 | ene_hi.append(ene+2.5) |
||
53 | |||
54 | |||
55 | pol_ang = np.array(f['pol_ang'].value) |
||
56 | |||
57 | pol_deg = np.array(f['pol_deg'].value) |
||
58 | |||
59 | |||
60 | bins = np.array(f['bins'].value) |
||
61 | |||
62 | |||
63 | bin_center = 0.5 *(bins[:-1] + bins[1:]) |
||
64 | |||
65 | all_interp = [] |
||
66 | |||
67 | |||
68 | |||
69 | for i, bm in enumerate(bin_center): |
||
70 | |||
71 | |||
72 | this_interpolator = interpolate.RegularGridInterpolator((energy,pol_ang,pol_deg), f['matrix'][...,i]) |
||
73 | |||
74 | |||
75 | all_interp.append(this_interpolator) |
||
76 | |||
77 | self._all_interp = all_interp |
||
78 | |||
79 | self._ene_lo = ene_lo |
||
80 | self._ene_hi = ene_hi |
||
81 | self._energy_mid = energy |
||
82 | |||
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 | |||
121 |
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.