| Conditions | 4 |
| Total Lines | 59 |
| Code Lines | 24 |
| 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 h5py |
||
| 26 | def _interpolate_rsp(self): |
||
| 27 | """ |
||
| 28 | Builds the interpolator for the response. This is currently incredibly slow |
||
| 29 | and should be improved |
||
| 30 | |||
| 31 | """ |
||
| 32 | |||
| 33 | # now go through the response and extract things |
||
| 34 | |||
| 35 | with h5py.File(self._rsp_file, 'r') as f: |
||
| 36 | |||
| 37 | energy = f['energy'].value |
||
| 38 | |||
| 39 | ene_lo, ene_hi = [], [] |
||
| 40 | |||
| 41 | # the bin widths are hard coded right now. |
||
| 42 | # this should be IMPROVED! |
||
| 43 | |||
| 44 | for ene in energy: |
||
| 45 | |||
| 46 | ene_lo.append(ene - 2.5) |
||
| 47 | ene_hi.append(ene + 2.5) |
||
| 48 | |||
| 49 | pol_ang = np.array(f['pol_ang'].value) |
||
| 50 | |||
| 51 | pol_deg = np.array(f['pol_deg'].value) |
||
| 52 | |||
| 53 | bins = np.array(f['bins'].value) |
||
| 54 | |||
| 55 | # get the bin centers as these are where things |
||
| 56 | # should be evaluated |
||
| 57 | |||
| 58 | bin_center = 0.5 * (bins[:-1] + bins[1:]) |
||
| 59 | |||
| 60 | all_interp = [] |
||
| 61 | |||
| 62 | # now we construct a series of interpolation |
||
| 63 | # functions that are called during the fit. |
||
| 64 | # we use some nice matrix math to handle this |
||
| 65 | |||
| 66 | for i, bm in enumerate(bin_center): |
||
| 67 | |||
| 68 | this_interpolator = interpolate.RegularGridInterpolator( |
||
| 69 | (energy, pol_ang, pol_deg), f['matrix'][..., i]) |
||
| 70 | |||
| 71 | all_interp.append(this_interpolator) |
||
| 72 | |||
| 73 | # finally we attach all of this to the class |
||
| 74 | |||
| 75 | self._all_interp = all_interp |
||
| 76 | |||
| 77 | self._ene_lo = ene_lo |
||
| 78 | self._ene_hi = ene_hi |
||
| 79 | self._energy_mid = energy |
||
| 80 | |||
| 81 | self._n_scatter_bins = len(bin_center) |
||
| 82 | self._scattering_bins = bin_center |
||
| 83 | self._scattering_bins_lo = bins[:-1] |
||
| 84 | self._scattering_bins_hi = bins[1:] |
||
| 85 | |||
| 178 |