def center_shift(self, offset=None, test_path=None, ind=None, cen_range=None): ''' Find the center of the sinogram and apply the shift to corect for the offset ''' sz = self._parent.data.shape(2) // 2 if test_path is not None: rotation.write_center(self._parent.data._data, theta=self._parent.meta.theta, dpath=test_path, ind=ind, cen_range=cen_range, sinogram_order=True) else: if offset is None: offset = sz - rotation.find_center(self._parent.data._data, self._parent.meta.theta, sinogram_order=True)[0] #offset = sz-rotation.find_center_pc(self._parent.data._data[:,0,:], self._parent.data._data[:,self._parent.data.shape(1)//2,:])p # Do nothing is the offset is less than 1 pixel if (numpy.abs(offset) >= 1): self._parent.data._data = interp.shift(self._parent.data._data, (0, 0, offset)) self._parent.meta.history[ 'process.center_shift(offset)'] = offset self._parent.message('Horizontal offset corrected.') else: self._parent.warning( "Center shift found an offset smaller than 1. Correction won't be applied" )
def test_find_center(self): sim = read_file('sinogram.npy') ang = np.linspace(0, np.pi, sim.shape[0]) cen = find_center(sim, ang) assert_allclose(cen, 45.28, rtol=1e-2)