def fourierMult(fvolume, filter, human=False): from pytom.tompy.transform import fourier_full2reduced if human: filter = xp.fft.fftshift(filter) filter = fourier_full2reduced(filter) fvolume = fourier_full2reduced(fvolume) fvolume *= filter return fvolume
def apply(self, data, rotation=None): """ @param rotation: apply rotation to the wedge first """ # if no missing wedge if self.start_ang == -90 and self.end_ang == 90: return data if self._volume is not None and np.array_equal(self._volume_shape, data.shape): pass else: self._create_wedge_volume(data.shape) if rotation is not None: # rotate the wedge first assert len(rotation) == 3 from pytom.tompy.transform import rotate3d, fourier_reduced2full, fourier_full2reduced, fftshift, ifftshift isodd = self._volume_shape[2] % 2 filter_vol = fftshift(fourier_reduced2full(self._volume, isodd)) filter_vol = rotate3d(filter_vol, rotation[0], rotation[1], rotation[2], order=1) # linear interp! filter_vol = fourier_full2reduced(ifftshift(filter_vol)) else: filter_vol = self._volume from pytom.tompy.transform import fourier_filter res = fourier_filter(data, filter_vol, False) return res
def set_wedge_volume(self, wedge_vol, half=True, isodd=False): if half: self._volume = wedge_vol # human understandable version with 0-freq in the center from transform import fourier_reduced2full, fftshift self._whole_volume = fftshift( fourier_reduced2full(self._volume, isodd)) else: self._whole_volume = wedge_vol from transform import fourier_full2reduced, ifftshift self._volume = fourier_full2reduced(ifftshift(self._whole_volume))
def apply(self, data, rotation=None): if rotation is not None: # rotate the wedge first assert len(rotation) == 3 from transform import rotate3d, fourier_full2reduced, ifftshift filter_vol = rotate3d(self._whole_volume, rotation[0], rotation[1], rotation[2]) filter_vol = fourier_full2reduced(ifftshift(filter_vol)) else: filter_vol = self._volume from transform import fourier_filter res = fourier_filter(data, filter_vol, False) return res
def _create_wedge_volume(self, size): from transform import fftshift, fourier_full2reduced # if no missing wedge if self.start_ang == -90 and self.end_ang == 90: filter_vol = np.ones(size) self._volume = fourier_full2reduced(filter_vol) self._volume_shape = size return filter_vol = np.ones(size) x, z = scipy.mgrid[0.:size[0], 0.:size[2]] x -= size[0] / 2 ind = np.where(x) # find the non-zeros z -= size[2] / 2 angles = np.zeros(z.shape) angles[ind] = np.arctan(z[ind] / x[ind]) * 180 / np.pi angles = np.reshape(angles, (size[0], 1, size[2])) angles = np.repeat(angles, size[1], axis=1) filter_vol[angles > -self.start_ang] = 0 filter_vol[angles < -self.end_ang] = 0 filter_vol[size[0] / 2, :, :] = 0 filter_vol[size[0] / 2, :, size[2] / 2] = 1 # create a sphere and multiple it with the wedge from tools import create_sphere mask = create_sphere(size) filter_vol *= mask # shift and cut in half filter_vol = fftshift(filter_vol) self._volume = fourier_full2reduced(filter_vol) self._volume_shape = size
def rotateWeighting(weighting, rotation, mask=None, binarize=False): """ rotateWeighting: Rotates a frequency weighting volume around the center. If the volume provided is reduced complex, it will be rescaled to full size, ftshifted, rotated, iftshifted and scaled back to reduced size. @param weighting: A weighting volume in reduced complex convention @type weighting: cupy or numpy array @param rotation: rotation angles in zxz order @type rotation: list @param mask:=None is there a rotation mask? A mask with all = 1 will be generated otherwise. Such mask should be \ provided anyway. @type mask: cupy or numpy ndarray @return: weight as reduced complex volume @rtype: L{pytom_volume.vol_comp} """ from pytom_volume import vol, limit, vol_comp from pytom_volume import rotate from pytom.voltools import transform assert type(weighting) == vol or type( weighting ) == vol_comp, "rotateWeighting: input neither vol nor vol_comp" from pytom.tompy.transform import fourier_reduced2full, fourier_full2reduced weighting = fourier_reduced2full(weighting, isodd=weighting.shape[0] % 2 == 1) weighting = xp.fft.fftshift(weighting) weightingRotated = xp.zeros_like(weighting) transform(weighting, output=weightingRotated, rotation=rotation, rotation_order='rzxz', device=device, interpolation='filt_bspline') if not mask is None: weightingRotated *= mask weightingRotated = xp.fft.fftshift(weightingRotated) returnVolume = fourier_full2reduced(weightingRotated) if binarize: returnVolume[returnVolume < 0.5] = 0 returnVolume[returnVolume >= 0.5] = 1 return returnVolume