def translation_align_given_rotation_angles(v1, m1, v2, m2, angs): """ for each angle, do a translation search """ v1f = fftn(v1) v1f[0, 0, 0] = 0.0 v1f = fftshift(v1f) a = [{}] * len(angs) for i, ang in enumerate(angs): v2r = GR.rotate_pad_mean(v2, angle=ang) v2rf = fftn(v2r) v2rf[0, 0, 0] = 0.0 v2rf = fftshift(v2rf) m2r = GR.rotate_pad_zero(m2, angle=ang) m1_m2r = m1 * m2 # masked images v1fm = v1f * m1_m2r v2rfm = v2rf * m1_m2r # normalize values v1fmn = v1fm / N.sqrt(N.square(N.abs(v1fm)).sum()) v2rfmn = v2rfm / N.sqrt(N.square(N.abs(v2rfm)).sum()) lc = translation_align__given_unshifted_fft(ifftshift(v1fmn), ifftshift(v2rfmn)) a[i] = {'ang': ang, 'loc': lc['loc'], 'score': lc['cor']} return a
def inv_transform_mask(phi, w, n): """ Generates the mask rotated by the angles specified by the inverse of phi """ ang = [phi['q_rot'], phi['q_tilt'], phi['q_psi']] loc = [0.0, 0.0, 0.0] ang, loc = ang_loc.reverse_transform_ang_loc(ang, loc) w_rot = rotate.rotate_pad_zero(w, angle=ang, loc_r=loc) return w_rot
def generate_toy_model(dim_siz=64, model_id=0): siz = N.array([dim_siz, dim_siz, dim_siz]) mid = siz / 2.0 xg = N.mgrid[0:siz[0], 0:siz[1], 0:siz[2]] if model_id == 0: # four gauss functions short_dia = 0.4 mid_dia = 0.8 long_dia = 1.2 e0 = generate_toy_model__gaussian( dim_siz=dim_siz, xg=xg, xm=(mid + N.array([siz[0] / 4.0, 0.0, 0.0])), dias=[long_dia, short_dia, short_dia]) e1 = generate_toy_model__gaussian( dim_siz=dim_siz, xg=xg, xm=(mid + N.array([0.0, siz[1] / 4.0, 0.0])), dias=[short_dia, long_dia, short_dia]) e2 = generate_toy_model__gaussian( dim_siz=dim_siz, xg=xg, xm=(mid + N.array([0.0, 0.0, siz[2] / 4.0])), dias=[short_dia, short_dia, long_dia]) e3 = GR.rotate_pad_zero(N.array(e0, order='F'), angle=N.array([N.pi / 4.0, 0.0, 0.0]), loc_r=N.array([0.0, 0.0, 0.0])) e = e0 + e1 + e2 + e3 return e
def inv_transform_mask(phi, w, n): ang = [phi['q_rot'], phi['q_tilt'], phi['q_psi']] loc = [0.0, 0.0, 0.0] ang, loc = ang_loc.reverse_transform_ang_loc(ang, loc) w_rot = rotate.rotate_pad_zero(w, angle=ang, loc_r=loc) return w_rot