def compute_projection_matrix(projdirs, N, kern, kernsize, rad, projdirtype='dirs', sym=None, onlyRs=False, **kwargs): projdirs = np.asarray(projdirs, dtype=np.float32) if projdirtype == 'dirs': # Input is a set of projection directions dirhash = hash(projdirs.tostring()) if onlyRs and dirhash in precomputed_Rs: Rs = precomputed_Rs[dirhash] else: Rs = np.vstack( [geometry.rotmat3D_dir(d)[:, 0:2].reshape((1, 3, 2)) for d in projdirs]) if onlyRs: precomputed_Rs[dirhash] = Rs elif projdirtype == 'rots': # Input is a set of rotation matrices mapping image space to protein # space Rs = projdirs else: assert False, 'Unknown projdirtype, must be either dirs or rots' if sym is None: symRs = None else: symRs = np.vstack([np.require(R, dtype=np.float32).reshape( (1, 3, 3)) for R in sym.get_rotations()]) if onlyRs: return Rs else: return sincint.compute_interpolation_matrix(Rs, N, N, rad, kern, kernsize, symRs)
def compute_inplanerot_matrix(thetas, N, kern, kernsize, rad, N_src=None, onlyRs=False): dirhash = hash(thetas.tostring()) if N_src is None: N_src = N scale = 1 else: scale = float(N_src) / N if onlyRs and dirhash in precomputed_RIs: Rs = precomputed_RIs[dirhash] else: Rs = n.vstack([ scale * geom.rotmat2D(n.require(th, dtype=n.float32)).reshape( (1, 2, 2)) for th in thetas ]) if onlyRs: precomputed_RIs[dirhash] = Rs if onlyRs: return Rs else: return sincint.compute_interpolation_matrix(Rs, N, N_src, rad, kern, kernsize, None)
def compute_inplanerot_matrix(thetas,N,kern,kernsize,rad,N_src=None,onlyRs = False): dirhash = hash(thetas.tostring()) if N_src is None: N_src = N scale = 1 else: scale = float(N_src)/N if onlyRs and dirhash in precomputed_RIs: Rs = precomputed_RIs[dirhash] else: Rs = n.vstack([scale*geom.rotmat2D(n.require(th,dtype=n.float32)).reshape((1,2,2)) for th in thetas]) if onlyRs: precomputed_RIs[dirhash] = Rs if onlyRs: return Rs else: return sincint.compute_interpolation_matrix(Rs,N,N_src,rad,kern,kernsize,None)
def compute_projection_matrix(projdirs, N, kern, kernsize, rad, projdirtype='dirs', sym=None, onlyRs=False, **kwargs): projdirs = np.asarray(projdirs, dtype=np.float32) if projdirtype == 'dirs': # Input is a set of projection directions dirhash = hash(projdirs.tostring()) if onlyRs and dirhash in precomputed_Rs: Rs = precomputed_Rs[dirhash] else: Rs = np.vstack([ geometry.rotmat3D_dir(d)[:, 0:2].reshape((1, 3, 2)) for d in projdirs ]) if onlyRs: precomputed_Rs[dirhash] = Rs elif projdirtype == 'rots': # Input is a set of rotation matrices mapping image space to protein # space Rs = projdirs else: assert False, 'Unknown projdirtype, must be either dirs or rots' if sym is None: symRs = None else: symRs = np.vstack([ np.require(R, dtype=np.float32).reshape((1, 3, 3)) for R in sym.get_rotations() ]) if onlyRs: return Rs else: return sincint.compute_interpolation_matrix(Rs, N, N, rad, kern, kernsize, symRs)