| Conditions | 7 |
| Total Lines | 65 |
| Code Lines | 50 |
| 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 | # Copyright 2019 Diamond Light Source Ltd. |
||
| 128 | def process_frames(self, data): |
||
| 129 | cor, angles, self.vol_shape, init = self.get_frame_params() |
||
| 130 | self.anglesRAD = np.deg2rad(angles.astype(np.float32)) |
||
| 131 | projdata3D = data[0].astype(np.float32) |
||
| 132 | dim_tuple = np.shape(projdata3D) |
||
| 133 | self.Horiz_det = dim_tuple[self.det_dimX_ind] |
||
| 134 | half_det_width = 0.5 * self.Horiz_det |
||
| 135 | projdata3D[projdata3D > 10 ** 15] = 0.0 |
||
| 136 | projdata3D = np.swapaxes(projdata3D, 0, 1) |
||
| 137 | self._data_.update({'projection_norm_data': projdata3D}) |
||
| 138 | |||
| 139 | # dealing with projection shifts and the CoR |
||
| 140 | cor_astra = half_det_width - np.mean(cor) |
||
| 141 | CenterOffset = cor_astra.item() - 0.5 |
||
| 142 | if np.sum(self.projection_shifts) != 0.0: |
||
| 143 | CenterOffset = np.zeros(np.shape(self.projection_shifts)) |
||
| 144 | CenterOffset[:, 0] = (cor_astra.item() - 0.5) - self.projection_shifts[:, 0] |
||
| 145 | CenterOffset[:, 1] = -self.projection_shifts[:, 1] - 0.5 |
||
| 146 | |||
| 147 | if self.parameters['reconstruction_method'] == 'FISTA3D': |
||
| 148 | # if one selects PWLS or SWLS models then raw data is also required (2 inputs) |
||
| 149 | if (self.parameters['data_fidelity'] == 'PWLS') or (self.parameters['data_fidelity'] == 'SWLS'): |
||
| 150 | rawdata3D = data[1].astype(np.float32) |
||
| 151 | rawdata3D[rawdata3D > 10 ** 15] = 0.0 |
||
| 152 | rawdata3D = np.swapaxes(rawdata3D, 0, 1) / np.max(np.float32(rawdata3D)) |
||
| 153 | self._data_.update({'projection_raw_data': rawdata3D}) |
||
| 154 | self._data_.update({'beta_SWLS': self.parameters['data_beta_SWLS'] * np.ones(self.Horiz_det)}) |
||
| 155 | |||
| 156 | # set parameters and initiate a TomoBar class object for FISTA reconstruction |
||
| 157 | RectoolsIter = RecToolsIR(DetectorsDimH=self.Horiz_det, # DetectorsDimH # detector dimension (horizontal) |
||
| 158 | DetectorsDimV=self.Vert_det, # DetectorsDimV # detector dimension (vertical) for 3D case only |
||
| 159 | CenterRotOffset=CenterOffset, # The center of rotation combined with the shift offsets |
||
| 160 | AnglesVec=-self.anglesRAD, # the vector of angles in radians |
||
| 161 | ObjSize=self.vol_shape[0], # a scalar to define the reconstructed object dimensions |
||
| 162 | datafidelity=self.parameters['data_fidelity'], # data fidelity, choose LS, PWLS, SWLS |
||
| 163 | device_projector=self.parameters['GPU_index']) |
||
| 164 | |||
| 165 | # Run FISTA reconstruction algorithm here |
||
| 166 | recon = RectoolsIter.FISTA(self._data_, self._algorithm_, self._regularisation_) |
||
| 167 | |||
| 168 | if self.parameters['reconstruction_method'] == 'FBP3D': |
||
| 169 | RectoolsDIR = RecToolsDIR(DetectorsDimH=self.Horiz_det, # DetectorsDimH # detector dimension (horizontal) |
||
| 170 | DetectorsDimV=self.Vert_det, # DetectorsDimV # detector dimension (vertical) for 3D case only |
||
| 171 | CenterRotOffset=CenterOffset, # The center of rotation combined with the shift offsets |
||
| 172 | AnglesVec=-self.anglesRAD, # the vector of angles in radians |
||
| 173 | ObjSize=self.vol_shape[0], # a scalar to define the reconstructed object dimensions |
||
| 174 | device_projector=self.parameters['GPU_index']) |
||
| 175 | |||
| 176 | recon = RectoolsDIR.FBP(projdata3D) #perform FBP3D |
||
| 177 | |||
| 178 | if self.parameters['reconstruction_method'] == 'CGLS3D': |
||
| 179 | # set parameters and initiate a TomoBar class object for FISTA reconstruction |
||
| 180 | RectoolsIter = RecToolsIR(DetectorsDimH=self.Horiz_det, # DetectorsDimH # detector dimension (horizontal) |
||
| 181 | DetectorsDimV=self.Vert_det, # DetectorsDimV # detector dimension (vertical) for 3D case only |
||
| 182 | CenterRotOffset=CenterOffset, # The center of rotation combined with the shift offsets |
||
| 183 | AnglesVec=-self.anglesRAD, # the vector of angles in radians |
||
| 184 | ObjSize=self.vol_shape[0], # a scalar to define the reconstructed object dimensions |
||
| 185 | datafidelity=self.parameters['data_fidelity'], # data fidelity, choose LS, PWLS, SWLS |
||
| 186 | device_projector=self.parameters['GPU_index']) |
||
| 187 | |||
| 188 | # Run CGLS reconstruction algorithm here |
||
| 189 | recon = RectoolsIter.CGLS(self._data_, self._algorithm_) |
||
| 190 | |||
| 191 | recon = np.swapaxes(recon, 0, 1) |
||
| 192 | return recon |
||
| 193 | |||
| 213 |