def cross_correlate(plan, normalize=True): #norm_template = np.sum(plan.template.d_data) fft(plan.volume, plan.volume_fft, plan.fwd_plan) fft(plan.template.d_data, plan.template_fft, plan.fwd_plan) conj(plan.template_fft, overwrite=True) volume_fft = plan.volume_fft * plan.template_fft ifft(volume_fft, plan.ccc_map, plan.inv_plan)
def calc_stdV(plan): fft(plan.volume, plan.volume_fft, plan.fwd_plan) fft(plan.maskPadded, plan.template_fft, plan.fwd_plan) conj(plan.template_fft, overwrite=True) volume_fft = plan.volume_fft * plan.template_fft ifft(volume_fft, plan.stdV, plan.inv_plan, scale=True) plan.stdV = plan.stdV / (plan.p)
def meanVolUnderMask(volume, mask, out, p=1): fft(volume, plan.volume_fft, plan.fwd_plan) fft(mask, plan.template_fft, plan.fwd_plan) conj(plan.template_fft, overwrite=True) volume_fft = plan.volume_fft * plan.template_fft ifft(volume_fft, out, plan.inv_plan, scale=True) out = out / (plan.p)
def cross_correlate(plan, normalize=True):#volume, template, volume_fft, plan, inv_plan, template_fft, ccc_map, norm_volume, normalize=True,): norm_template = np.sum(plan.template.d_data) fft(plan.template.d_data, plan.template_fft, plan.fwd_plan) conj(plan.template_fft, overwrite=True) volume_fft = plan.volume_fft * plan.template_fft ifft(volume_fft, plan.ccc_map, plan.inv_plan) if normalize: plan.ccc_map = plan.ccc_map / plan.norm_volume / norm_template
def cross_correlate(plan, normalize=True): #norm_template = sum(plan.mask.d_data) fft(plan.volume, plan.volume_fft, plan.fwd_plan) fft(plan.templatePadded, plan.template_fft, plan.fwd_plan) conj(plan.template_fft, overwrite=True) volume_fft = plan.volume_fft * plan.template_fft ifft(volume_fft, plan.ccc_map, plan.inv_plan, scale=True) plan.ccc_map /= np.float32(plan.p.get()) * plan.stdV
def __calc_A_shift_gpu(self, shift_x, shift_y): psis_gpu = self.converter.get_prolates_as_images() # TODO: need to assert that returns indeed a gpuarray n_psis = len(psis_gpu) if shift_x == 0 and shift_y == 0: return np.eye(n_psis) A_shift = gpuarray.zeros((n_psis, n_psis),'complex64') non_neg_freqs = self.converter.get_non_neg_freq_inds() psis_gpu_non_neg_freqs = psis_gpu[non_neg_freqs] psis_non_neg_shifted = circ_shift_kernel.circ_shift(psis_gpu_non_neg_freqs, shift_x, shift_y) psis_non_neg_shifted = self.converter.mask_points_inside_the_circle(psis_non_neg_shifted) psis_non_neg_shifted = psis_non_neg_shifted.reshape(len(psis_non_neg_shifted), -1) psis_gpu = psis_gpu.reshape(n_psis, -1) A_shift[non_neg_freqs] = linalg.dot(psis_non_neg_shifted, psis_gpu, transb='C') zero_freq_inds = self.converter.get_zero_freq_inds() pos_freq_inds = self.converter.get_pos_freq_inds() neg_freq_inds = self.converter.get_neg_freq_inds() A_shift[neg_freq_inds, zero_freq_inds] = A_shift[pos_freq_inds, zero_freq_inds] A_shift[neg_freq_inds, pos_freq_inds] = A_shift[pos_freq_inds, neg_freq_inds] A_shift[neg_freq_inds, neg_freq_inds] = A_shift[pos_freq_inds, pos_freq_inds] A_shift[neg_freq_inds] = linalg.conj(A_shift[neg_freq_inds]) # TODO: get rid of the transpose # return np.transpose(A_shift).copy() return np.transpose(A_shift).get().copy()
def test_conj_complex128(self): a = np.array([[1+1j, 2-2j, 3+3j, 4-4j], [5+5j, 6-6j, 7+7j, 8-8j]], np.complex128) a_gpu = gpuarray.to_gpu(a) r_gpu = linalg.conj(a_gpu) assert np.all(np.conj(a) == r_gpu.get())