示例#1
0
    def compute_operator(self,interp_params,inds=None):
        if inds is None:
            Rs = np.array([[geometry.rotmat3D_dir(d,t)[:,0:2] for t in self.thetas] for d in self.dirs])
            Rs = Rs.reshape((-1,3,2))        
        else:
            N_I = len(self.thetas)
            Rs = np.array([geometry.rotmat3D_dir(self.dirs[i/N_I],self.thetas[np.mod(i,N_I)])[:,0:2] for i in inds])

        return cops.compute_projection_matrix(Rs,sym=self.sym,projdirtype='rots',**interp_params)
示例#2
0
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)
示例#3
0
    def compute_operator(self, interp_params, inds=None):
        if inds is None:
            Rs = np.array(
                [[geometry.rotmat3D_dir(d, t)[:, 0:2] for t in self.thetas]
                 for d in self.dirs])
            Rs = Rs.reshape((-1, 3, 2))
        else:
            N_I = len(self.thetas)
            Rs = np.array([
                geometry.rotmat3D_dir(self.dirs[i / N_I],
                                      self.thetas[np.mod(i, N_I)])[:, 0:2]
                for i in inds
            ])

        return cops.compute_projection_matrix(Rs,
                                              sym=self.sym,
                                              projdirtype='rots',
                                              **interp_params)
示例#4
0
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)
示例#5
0
def plot_figures():
    oversampling_factor = 6
    psize = 3 * oversampling_factor
    freq = 0.05
    rad = 0.5 * 2.0 * psize
    beamstop_freq = 0.005
    beamstop_rad = beamstop_freq * 2.0 * psize

    # M = mrc.readMRC('particle/EMD-6044-cropped.mrc')
    # M[M < 0] = 0
    # M_totalmass = 2000000
    # if M_totalmass is not None:
    #     M *= M_totalmass / M.sum()
    # fM = density.real_to_fspace_with_oversampling(M, oversampling_factor=oversampling_factor)
    # fM = fM.real ** 2 + fM.imag ** 2
    # mrc.writeMRC("particle/EMD-6044-cropped_fM_totalmass_%d_oversampling_%d.mrc" % (M_totalmass, oversampling_factor), fM, psz=psize)
    # exit()

    fM = mrc.readMRC(
        'particle/EMD-6044-cropped_fM_totalmass_2000000_oversampling_6.mrc')

    N = fM.shape[0]
    TtoF = sincint.gentrunctofull(N=N, rad=rad, beamstop_rad=beamstop_rad)

    theta = np.arange(0, 2 * np.pi, 2 * np.pi / 60)
    degree_R, resolution_R = SK97Quadrature.compute_degree(N, 0.3, 1.0)
    dirs, weights = SK97Quadrature.get_quad_points(degree_R, None)
    Rs = np.vstack([
        geometry.rotmat3D_dir(vec)[:, 0:2].reshape((1, 3, 2)) for vec in dirs
    ])

    N_R = dirs.shape[0]
    N_I = theta.shape[0]
    N_T = TtoF.shape[1]

    # generate slicing operators
    dir_slice_interp = {
        'projdirs': dirs,
        'N': N,
        'kern': 'lanczos',
        'kernsize': 6,
        'projdirtype': 'dirs',
        'onlyRs': True,
        'rad': rad,
        'sym': None
    }  # 'zeropad': 0, 'dopremult': True
    R_slice_interp = {
        'projdirs': Rs,
        'N': N,
        'kern': 'lanczos',
        'kernsize': 6,
        'projdirtype': 'rots',
        'onlyRs': True,
        'rad': rad,
        'sym': None
    }  # 'zeropad': 0, 'dopremult': True
    inplane_interp = {
        'thetas': theta,
        'N': N,
        'kern': 'lanczos',
        'kernsize': 6,
        'onlyRs': True,
        'rad': rad
    }  # 'zeropad': 1, 'dopremult': True
    inplane_interp['N_src'] = N  # zp_N

    slice_ops = cryoops.compute_projection_matrix(**dir_slice_interp)
    inplane_ops = cryoops.compute_inplanerot_matrix(**inplane_interp)

    # generate slices and inplane-rotated slices
    slices_sampled = cryoem.getslices_interp(
        fM, slice_ops, rad, beamstop_rad=beamstop_rad).reshape((N_R, N_T))
    curr_img = TtoF.dot(slices_sampled[0]).reshape(N, N)
    rotd_sampled = cryoem.getslices_interp(curr_img,
                                           inplane_ops,
                                           rad,
                                           beamstop_rad=beamstop_rad).reshape(
                                               (N_I, N_T))

    ## plot figures
    fig, axes = plt.subplots(3, 4, figsize=(9.6, 7.2))
    for i, ax in enumerate(axes.flatten()):
        img = TtoF.dot(slices_sampled[i]).reshape(N, N)
        ax.imshow(img, origin='lower')
    fig.suptitle('slices_sampled')

    fig, axes = plt.subplots(3, 4, figsize=(9.6, 7.2))
    for i, ax in enumerate(axes.flatten()):
        img = TtoF.dot(slices_sampled[i]).reshape(N, N)
        ax.imshow(img, origin='lower')
    fig.suptitle('rotd_sampled')
    plt.show()
示例#6
0
    psize = 3.0 * 3
    freq = 0.005
    rad = freq * 2.0 * psize
    beamstop_freq = 0.003
    beamstop_rad = beamstop_freq * 2.0 * psize

    fM = mrc.readMRC('../particle/EMD-6044-cropped-non-negative-256.mrc')
    N = fM.shape[0]

    TtoF = sincint.gentrunctofull(N=N, rad=rad, beamstop_rad=beamstop_rad)

    theta = np.arange(0, 2 * np.pi, 2 * np.pi / 12)
    degree_R, resolution_R = SK97Quadrature.compute_degree(N, rad, 1.0)
    dirs, weights = SK97Quadrature.get_quad_points(degree_R, None)
    Rs = np.vstack([
        geometry.rotmat3D_dir(vec)[:, 0:2].reshape((1, 3, 2)) for vec in dirs
    ])

    N_R = dirs.shape[0]
    N_I = theta.shape[0]
    N_T = TtoF.shape[1]
    print(N_R, N_I, N_T)

    # generate slicing operators
    dir_slice_interp = {
        'projdirs': dirs,
        'N': N,
        'kern': 'lanczos',
        'kernsize': 6,
        'projdirtype': 'dirs',
        'onlyRs': True,