Conditions | 8 |
Total Lines | 67 |
Code Lines | 52 |
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 self.parameters['regularisation_method'] == 'PD_TV': |
||
149 | self._regularisation_.update({'device_regulariser': self.parameters['GPU_index']}) |
||
150 | # if one selects PWLS or SWLS models then raw data is also required (2 inputs) |
||
151 | if (self.parameters['data_fidelity'] == 'PWLS') or (self.parameters['data_fidelity'] == 'SWLS'): |
||
152 | rawdata3D = data[1].astype(np.float32) |
||
153 | rawdata3D[rawdata3D > 10 ** 15] = 0.0 |
||
154 | rawdata3D = np.swapaxes(rawdata3D, 0, 1) / np.max(np.float32(rawdata3D)) |
||
155 | self._data_.update({'projection_raw_data': rawdata3D}) |
||
156 | self._data_.update({'beta_SWLS': self.parameters['data_beta_SWLS'] * np.ones(self.Horiz_det)}) |
||
157 | |||
158 | # set parameters and initiate a TomoBar class object for FISTA reconstruction |
||
159 | RectoolsIter = RecToolsIR(DetectorsDimH=self.Horiz_det, # DetectorsDimH # detector dimension (horizontal) |
||
160 | DetectorsDimV=self.Vert_det, # DetectorsDimV # detector dimension (vertical) for 3D case only |
||
161 | CenterRotOffset=CenterOffset, # The center of rotation combined with the shift offsets |
||
162 | AnglesVec=-self.anglesRAD, # the vector of angles in radians |
||
163 | ObjSize=self.vol_shape[0], # a scalar to define the reconstructed object dimensions |
||
164 | datafidelity=self.parameters['data_fidelity'], # data fidelity, choose LS, PWLS, SWLS |
||
165 | device_projector=self.parameters['GPU_index']) |
||
166 | |||
167 | # Run FISTA reconstruction algorithm here |
||
168 | recon = RectoolsIter.FISTA(self._data_, self._algorithm_, self._regularisation_) |
||
169 | |||
170 | if self.parameters['reconstruction_method'] == 'FBP3D': |
||
171 | RectoolsDIR = RecToolsDIR(DetectorsDimH=self.Horiz_det, # DetectorsDimH # detector dimension (horizontal) |
||
172 | DetectorsDimV=self.Vert_det, # DetectorsDimV # detector dimension (vertical) for 3D case only |
||
173 | CenterRotOffset=CenterOffset, # The center of rotation combined with the shift offsets |
||
174 | AnglesVec=-self.anglesRAD, # the vector of angles in radians |
||
175 | ObjSize=self.vol_shape[0], # a scalar to define the reconstructed object dimensions |
||
176 | device_projector=self.parameters['GPU_index']) |
||
177 | |||
178 | recon = RectoolsDIR.FBP(projdata3D) #perform FBP3D |
||
179 | |||
180 | if self.parameters['reconstruction_method'] == 'CGLS3D': |
||
181 | # set parameters and initiate a TomoBar class object for FISTA reconstruction |
||
182 | RectoolsIter = RecToolsIR(DetectorsDimH=self.Horiz_det, # DetectorsDimH # detector dimension (horizontal) |
||
183 | DetectorsDimV=self.Vert_det, # DetectorsDimV # detector dimension (vertical) for 3D case only |
||
184 | CenterRotOffset=CenterOffset, # The center of rotation combined with the shift offsets |
||
185 | AnglesVec=-self.anglesRAD, # the vector of angles in radians |
||
186 | ObjSize=self.vol_shape[0], # a scalar to define the reconstructed object dimensions |
||
187 | datafidelity=self.parameters['data_fidelity'], # data fidelity, choose LS, PWLS, SWLS |
||
188 | device_projector=self.parameters['GPU_index']) |
||
189 | |||
190 | # Run CGLS reconstruction algorithm here |
||
191 | recon = RectoolsIter.CGLS(self._data_, self._algorithm_) |
||
192 | |||
193 | recon = np.swapaxes(recon, 0, 1) |
||
194 | return recon |
||
195 | |||
215 |