示例#1
0
    def compute_operator(self,interp_params,inds=None):
        if inds is None:
            dirs = self.dirs
        else:
            dirs = self.dirs[inds]

        return cops.compute_projection_matrix(dirs,sym=self.sym,**interp_params)
示例#2
0
    def compute_operator(self, interp_params, inds=None):
        if inds is None:
            dirs = self.dirs
        else:
            dirs = self.dirs[inds]

        return cops.compute_projection_matrix(dirs,
                                              sym=self.sym,
                                              **interp_params)
示例#3
0
    def compute_operator(self,interp_params,inds=None):
        if inds is None:
            Rs = n.array([[geom.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 = n.array([geom.rotmat3D_dir(self.dirs[i/N_I],self.thetas[n.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 shift_vis(model):
    N = model.shape[0]
    rad = 0.8
    kernel = 'lanczos'
    kernsize = 4

    xy, trunc_xy, truncmask = geometry.gencoords(N, 2, rad, True)
    N_T = trunc_xy.shape[0]
    premult = cryoops.compute_premultiplier(N,
                                            kernel=kernel,
                                            kernsize=kernsize)
    TtoF = sincint.gentrunctofull(N=N, rad=rad)

    fM = density.real_to_fspace(model)
    prefM = density.real_to_fspace(
        premult.reshape((1, 1, -1)) * premult.reshape(
            (1, -1, 1)) * premult.reshape((-1, 1, 1)) * model)

    pt = np.random.randn(3)
    pt /= np.linalg.norm(pt)
    psi = 2 * np.pi * np.random.rand()
    ea = geometry.genEA(pt)[0]
    ea[2] = psi
    print('project model for Euler angel: ({:.2f}, {:.2f}, {:.2f}) degree'.
          format(*np.rad2deg(ea)))

    rot_matrix = geometry.rotmat3D_EA(*ea)[:, 0:2]
    slop = cryoops.compute_projection_matrix([rot_matrix], N, kernel, kernsize,
                                             rad, 'rots')
    # trunc_slice = slop.dot(prefM.reshape((-1,)))
    trunc_slice = cryoem.getslices(prefM, slop)
    fourier_slice = TtoF.dot(trunc_slice).reshape(N, N)
    real_proj = density.fspace_to_real(fourier_slice)

    fig, axes = plt.subplots(4, 4, figsize=(12.8, 8))

    im_real = axes[0, 0].imshow(real_proj)
    im_fourier = axes[1, 0].imshow(np.log(np.abs(fourier_slice)))

    for i, ax in enumerate(axes[:, 1:].T):
        shift = np.random.randn(2) * (N / 4.0)
        S = cryoops.compute_shift_phases(shift.reshape(1, 2), N, rad)[0]

        shift_trunc_slice = S * trunc_slice
        shift_fourier_slice = TtoF.dot(shift_trunc_slice).reshape(N, N)
        shift_real_proj = density.fspace_to_real(shift_fourier_slice)

        ax[0].imshow(shift_real_proj)
        ax[1].imshow(np.log(np.abs(shift_fourier_slice)))
        ax[2].imshow(np.log(shift_fourier_slice.real))
        ax[3].imshow(np.log(shift_fourier_slice.imag))

    fig.tight_layout()
    plt.show()
示例#5
0
def premult_test(model, kernel='lanczos', kernsize=6):
    if isinstance(model, str):
        M = mrc.readMRC(model)
    elif isinstance(model, np.ndarray):
        M = model

    shape = np.asarray(M.shape)
    assert (shape - shape.mean()).sum() == 0

    N = M.shape[0]
    rad = 0.6

    premult = cryoops.compute_premultiplier(N, kernel, kernsize)
    TtoF = sincint.gentrunctofull(N=N, rad=rad)
    premulter =   premult.reshape((1, 1, -1)) \
                * premult.reshape((1, -1, 1)) \
                * premult.reshape((-1, 1, 1))

    fM = density.real_to_fspace(M)
    prefM = density.real_to_fspace(premulter * M)

    pt = np.random.randn(3)
    pt /= np.linalg.norm(pt)
    psi = 2 * np.pi * np.random.rand()
    ea = geometry.genEA(pt)[0]
    ea[2] = psi
    print('project model for Euler angel: ({:.2f}, {:.2f}, {:.2f}) degree'.
          format(*np.rad2deg(ea)))

    rot_matrix = geometry.rotmat3D_EA(*ea)[:, 0:2]
    slop = cryoops.compute_projection_matrix([rot_matrix], N, kernel, kernsize,
                                             rad, 'rots')
    trunc_slice = slop.dot(fM.reshape((-1, )))
    premult_trunc_slice = slop.dot(prefM.reshape((-1, )))
    proj = density.fspace_to_real(TtoF.dot(trunc_slice).reshape(N, N))
    premult_proj = density.fspace_to_real(
        TtoF.dot(premult_trunc_slice).reshape(N, N))

    fig, ax = plt.subplots(1, 3, figsize=(14.4, 4.8))
    im_proj = ax[0].imshow(proj, origin='lower')
    fig.colorbar(im_proj, ax=ax[0])
    ax[0].set_title('no premulter')
    im_pre = ax[1].imshow(premult_proj, origin='lower')
    fig.colorbar(im_pre, ax=ax[1])
    ax[1].set_title('with premulter')
    im_diff = ax[2].imshow(proj - premult_proj, origin='lower')
    fig.colorbar(im_diff, ax=ax[2])
    ax[2].set_title('difference of two image')
    fig.tight_layout()
    plt.show()
示例#6
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)
示例#7
0
def project(model, euler_angles, rad=0.95, truncate=False):
    if isinstance(model, str):
        M = mrc.readMRC(model)
    elif isinstance(model, np.ndarray):
        M = model
    
    N = M.shape[0]
    kernel = 'lanczos'
    ksize = 6

    premult = cryoops.compute_premultiplier(N, kernel, ksize)
    TtoF = sincint.gentrunctofull(N=N, rad=rad)
    premulter =   premult.reshape((1, 1, -1)) \
                * premult.reshape((1, -1, 1)) \
                * premult.reshape((-1, 1, 1))
    # premulter = 1
    fM = density.real_to_fspace(premulter * M)

    euler_angles = euler_angles.reshape((-1, 3))
    num_projs = euler_angles.shape[0]
    if truncate:
        projs = np.zeros((num_projs, TtoF.shape[1]), dtype=fM.dtype)
    else:
        projs = np.zeros((num_projs, N, N), dtype=M.dtype)
    for i, ea in enumerate(euler_angles):
        rot_matrix = geometry.rotmat3D_EA(*ea)[:, 0:2]
        slop = cryoops.compute_projection_matrix([rot_matrix], N, kernel, ksize, rad, 'rots')
        trunc_slice = slop.dot(fM.reshape((-1,)))
        if truncate:
            projs[i, :] = trunc_slice
        else:
            projs[i, :, :] = density.fspace_to_real(TtoF.dot(trunc_slice).reshape(N, N))

    if num_projs == 1 and not truncate:
        projs = projs.reshape((N, N))

    return projs
示例#8
0
    def __init__(self, model, dataset_params, ctf_params,
                 interp_params={'kern': 'lanczos', 'kernsize': 4.0, 'zeropad': 0, 'dopremult': True},
                 load_cache=True):

        self.dataset_params = dataset_params

        if model is not None:
            # assert False
            assert isinstance(model, np.ndarray), "Unexpected data type for input model"

            self.num_pixels = model.shape[0]
            N = self.num_pixels
            self.num_images = dataset_params['num_images']
            assert self.num_images > 1, "it's better to make num_images larger than 1."
            self.pixel_size = float(dataset_params['pixel_size'])
            euler_angles = dataset_params['euler_angles']
            self.is_sym = get_symmetryop(dataset_params.get('symmetry', None))

            if euler_angles is None and self.is_sym is None:
                pt = np.random.randn(self.num_images, 3)
                pt /= np.linalg.norm(pt, axis=1, keepdims=True)
                euler_angles = geometry.genEA(pt)
                euler_angles[:, 2] = 2 * np.pi * np.random.rand(self.num_images)
            elif euler_angles is None and self.is_sym is not None:
                euler_angles = np.zeros((self.num_images, 3))
                for i, ea in enumerate(euler_angles):
                    while True:
                        pt = np.random.randn(3)
                        pt /= np.linalg.norm(pt)
                        if self.is_sym.in_asymunit(pt.reshape(-1, 3)):
                            break
                    ea[0:2] = geometry.genEA(pt)[0][0:2]
                    ea[2] = 2 * np.pi * np.random.rand()
            self.euler_angles = euler_angles.reshape((-1, 3))

            if ctf_params is not None:
                self.use_ctf = True
                ctf_map = ctf.compute_full_ctf(None, N, ctf_params['psize'],
                    ctf_params['akv'], ctf_params['cs'], ctf_params['wgh'],
                    ctf_params['df1'], ctf_params['df2'], ctf_params['angast'],
                    ctf_params['dscale'], ctf_params.get('bfactor', 500))
                self.ctf_params = copy(ctf_params)
                if 'bfactor' in self.ctf_params.keys():
                    self.ctf_params.pop('bfactor')
            else:
                self.use_ctf = False
                ctf_map = np.ones((N**2,), dtype=density.real_t)

            kernel = 'lanczos'
            ksize = 6
            rad = 0.95
            # premult = cryoops.compute_premultiplier(N, kernel, ksize)
            TtoF = sincint.gentrunctofull(N=N, rad=rad)
            base_coords = geometry.gencoords(N, 2, rad)
            # premulter =   premult.reshape((1, 1, -1)) \
            #             * premult.reshape((1, -1, 1)) \
            #             * premult.reshape((-1, 1, 1))
            # fM = density.real_to_fspace(premulter * model)
            fM = model

            # if load_cache:
            #     try:
            print("Generating Dataset ... :")
            tic = time.time()
            imgdata = np.empty((self.num_images, N, N), dtype=density.real_t)
            for i, ea in zip(range(self.num_images), self.euler_angles):
                R = geometry.rotmat3D_EA(*ea)[:, 0:2]
                slop = cryoops.compute_projection_matrix(
                    [R], N, kernel, ksize, rad, 'rots')
                # D = slop.dot(fM.reshape((-1,)))
                rotated_coords = R.dot(base_coords.T).T + int(N/2)
                D = interpn((np.arange(N),) * 3, fM, rotated_coords)
                np.maximum(D, 0.0, out=D)
                
                intensity = ctf_map.reshape((N, N)) * TtoF.dot(D).reshape((N, N))
                np.maximum(1e-8, intensity, out=intensity)
                intensity = np.float_( np.random.poisson(intensity) )
                imgdata[i] = np.require(intensity, dtype=density.real_t)
            self.imgdata = imgdata
            print("  cost {} seconds.".format(time.time()-tic))

            self.set_transform(interp_params)
            # self.prep_processing()

        else:
            euler_angles = []    
            with open(self.dataset_params['gtpath']) as par:
                par.readline()
                # 'C                 PHI      THETA        PSI        SHX        SHY       FILM        DF1        DF2     ANGAST'
                while True:
                    try:
                        line = par.readline().split()
                        euler_angles.append([float(line[1]), float(line[2]), float(line[3])])
                    except Exception:
                        break
            self.euler_angles = np.deg2rad(np.asarray(euler_angles))
            num_images = self.dataset_params.get('num_images', 200)
            imgdata = mrc.readMRCimgs(self.dataset_params['inpath'], 0, num_images)

            self.imgdata = np.transpose(imgdata, axes=(2, 0, 1))

            self.num_images = self.imgdata.shape[0]
            self.num_pixels = self.imgdata.shape[1]
            N = self.num_pixels

            self.pixel_size = self.dataset_params['resolution']
            self.is_sym = self.dataset_params.get('symmetry', None)

            self.use_ctf = False
            ctf_map = np.ones((N**2,), dtype=density.real_t)
            self.set_transform(interp_params)
示例#9
0
def genphantomdata(N_D, phantompath, ctfparfile):
    mscope_params = {
        'akv': 200,
        'wgh': 0.07,
        'cs': 2.0,
        'psize': 2.8,
        'bfactor': 500.0
    }
    N = 128
    rad = 0.95
    shift_sigma = 3.0
    sigma_noise = 25.0
    M_totalmass = 80000
    kernel = 'lanczos'
    ksize = 6

    premult = cryoops.compute_premultiplier(N, kernel, ksize)

    tic = time.time()

    N_D = int(N_D)
    N = int(N)
    rad = float(rad)
    psize = mscope_params['psize']
    bfactor = mscope_params['bfactor']
    shift_sigma = float(shift_sigma)
    sigma_noise = float(sigma_noise)
    M_totalmass = float(M_totalmass)

    srcctf_stack = CTFStack(ctfparfile, mscope_params)
    genctf_stack = GeneratedCTFStack(
        mscope_params, parfields=['PHI', 'THETA', 'PSI', 'SHX', 'SHY'])

    TtoF = sincint.gentrunctofull(N=N, rad=rad)
    Cmap = n.sort(
        n.random.random_integers(0,
                                 srcctf_stack.get_num_ctfs() - 1, N_D))

    M = mrc.readMRC(phantompath)
    cryoem.window(M, 'circle')
    M[M < 0] = 0
    if M_totalmass is not None:
        M *= M_totalmass / M.sum()

    V = density.real_to_fspace(
        premult.reshape((1, 1, -1)) * premult.reshape(
            (1, -1, 1)) * premult.reshape((-1, 1, 1)) * M)

    print "Generating data..."
    sys.stdout.flush()
    imgdata = n.empty((N_D, N, N), dtype=density.real_t)

    pardata = {'R': [], 't': []}

    prevctfI = None
    for i, srcctfI in enumerate(Cmap):
        ellapse_time = time.time() - tic
        remain_time = float(N_D - i) * ellapse_time / max(i, 1)
        print "\r%.2f Percent.. (Elapsed: %s, Remaining: %s)      " % (
            i / float(N_D) * 100.0, format_timedelta(ellapse_time),
            format_timedelta(remain_time)),
        sys.stdout.flush()

        # Get the CTF for this image
        cCTF = srcctf_stack.get_ctf(srcctfI)
        if prevctfI != srcctfI:
            genctfI = genctf_stack.add_ctf(cCTF)
            C = cCTF.dense_ctf(N, psize, bfactor).reshape((N**2, ))
            prevctfI = srcctfI

        # Randomly generate the viewing direction/shift
        pt = n.random.randn(3)
        pt /= n.linalg.norm(pt)
        psi = 2 * n.pi * n.random.rand()
        EA = geom.genEA(pt)[0]
        EA[2] = psi
        shift = n.random.randn(2) * shift_sigma

        R = geom.rotmat3D_EA(*EA)[:, 0:2]
        slop = cryoops.compute_projection_matrix([R], N, kernel, ksize, rad,
                                                 'rots')
        S = cryoops.compute_shift_phases(shift.reshape((1, 2)), N, rad)[0]

        D = slop.dot(V.reshape((-1, )))
        D *= S

        imgdata[i] = density.fspace_to_real((C * TtoF.dot(D)).reshape(
            (N, N))) + n.require(n.random.randn(N, N) * sigma_noise,
                                 dtype=density.real_t)

        genctf_stack.add_img(genctfI,
                             PHI=EA[0] * 180.0 / n.pi,
                             THETA=EA[1] * 180.0 / n.pi,
                             PSI=EA[2] * 180.0 / n.pi,
                             SHX=shift[0],
                             SHY=shift[1])

        pardata['R'].append(R)
        pardata['t'].append(shift)

    print "\rDone in ", time.time() - tic, " seconds."
    return imgdata, genctf_stack, pardata, mscope_params
示例#10
0
xy, trunc_xy, truncmask = geometry.gencoords(N, 2, rad, True)
# premult = cryoops.compute_premultiplier(N, kernel='lanczos', kernsize=6)
premult = cryoops.compute_premultiplier(N, kernel, ksize)
TtoF = sincint.gentrunctofull(N=N, rad=rad)

fM = density.real_to_fspace(M)
prefM = density.real_to_fspace(
    premult.reshape((1, 1, -1)) * premult.reshape(
        (1, -1, 1)) * premult.reshape((-1, 1, 1)) * M)

EAs_grid = healpix.gen_EAs_grid(nside=2, psi_step=360)
Rs = [geometry.rotmat3D_EA(*EA)[:, 0:2] for EA in EAs_grid]
slice_ops = cryoops.compute_projection_matrix(Rs,
                                              N,
                                              kern='lanczos',
                                              kernsize=ksize,
                                              rad=rad,
                                              projdirtype='rots')

slices_sampled = cryoem.getslices(fM, slice_ops).reshape(
    (EAs_grid.shape[0], trunc_xy.shape[0]))

premult_slices_sampled = cryoem.getslices(prefM, slice_ops).reshape(
    (EAs_grid.shape[0], trunc_xy.shape[0]))

S = cryoops.compute_shift_phases(
    np.asarray([100, -20]).reshape((1, 2)), N, rad)[0]

trunc_slice = slices_sampled[0]
premult_trunc_slice = premult_slices_sampled[0]
premult_trunc_slice_shift = S * premult_slices_sampled[0]
def genphantomdata(N_D, phantompath, ctfparfile):
    # mscope_params = {'akv': 200, 'wgh': 0.07,
    #                  'cs': 2.0, 'psize': 2.8, 'bfactor': 500.0}
    mscope_params = {'akv': 200, 'wgh': 0.07,
                     'cs': 2.0, 'psize': 3.0, 'bfactor': 500.0}
    
    M = mrc.readMRC(phantompath)

    N = M.shape[0]
    rad = 0.95
    shift_sigma = 3.0
    sigma_noise = 25.0
    M_totalmass = 80000
    kernel = 'lanczos'
    ksize = 6

    premult = cryoops.compute_premultiplier(N, kernel, ksize)

    tic = time.time()

    N_D = int(N_D)
    N = int(N)
    rad = float(rad)
    psize = mscope_params['psize']
    bfactor = mscope_params['bfactor']
    shift_sigma = float(shift_sigma)
    sigma_noise = float(sigma_noise)
    M_totalmass = float(M_totalmass)

    srcctf_stack = CTFStack(ctfparfile, mscope_params)
    genctf_stack = GeneratedCTFStack(mscope_params, parfields=[
                                     'PHI', 'THETA', 'PSI', 'SHX', 'SHY'])

    TtoF = sincint.gentrunctofull(N=N, rad=rad)
    Cmap = np.sort(np.random.random_integers(
        0, srcctf_stack.get_num_ctfs() - 1, N_D))

    cryoem.window(M, 'circle')
    M[M < 0] = 0
    if M_totalmass is not None:
        M *= M_totalmass / M.sum()

    V = density.real_to_fspace(
        premult.reshape((1, 1, -1)) * premult.reshape((1, -1, 1)) * premult.reshape((-1, 1, 1)) * M)

    print("Generating data...")
    sys.stdout.flush()
    imgdata = np.empty((N_D, N, N), dtype=density.real_t)

    pardata = {'R': [], 't': []}

    prevctfI = None
    for i, srcctfI in enumerate(Cmap):
        ellapse_time = time.time() - tic
        remain_time = float(N_D - i) * ellapse_time / max(i, 1)
        print("\r%.2f Percent.. (Elapsed: %s, Remaining: %s)" % (i / float(N_D)
                                                                 * 100.0, format_timedelta(ellapse_time), format_timedelta(remain_time)))
        sys.stdout.flush()

        # Get the CTF for this image
        cCTF = srcctf_stack.get_ctf(srcctfI)
        if prevctfI != srcctfI:
            genctfI = genctf_stack.add_ctf(cCTF)
            C = cCTF.dense_ctf(N, psize, bfactor).reshape((N**2,))
            prevctfI = srcctfI

        # Randomly generate the viewing direction/shift
        pt = np.random.randn(3)
        pt /= np.linalg.norm(pt)
        psi = 2 * np.pi * np.random.rand()
        EA = geometry.genEA(pt)[0]
        EA[2] = psi
        shift = np.random.randn(2) * shift_sigma

        R = geometry.rotmat3D_EA(*EA)[:, 0:2]
        slop = cryoops.compute_projection_matrix(
            [R], N, kernel, ksize, rad, 'rots')
        S = cryoops.compute_shift_phases(shift.reshape((1, 2)), N, rad)[0]

        D = slop.dot(V.reshape((-1,)))
        D *= S

        imgdata[i] = density.fspace_to_real((C * TtoF.dot(D)).reshape((N, N))) + np.require(
            np.random.randn(N, N) * sigma_noise, dtype=density.real_t)

        genctf_stack.add_img(genctfI,
                             PHI=EA[0] * 180.0 / np.pi, THETA=EA[1] * 180.0 / np.pi, PSI=EA[2] * 180.0 / np.pi,
                             SHX=shift[0], SHY=shift[1])

        pardata['R'].append(R)
        pardata['t'].append(shift)

    print("\rDone in ", time.time() - tic, " seconds.")
    return imgdata, genctf_stack, pardata, mscope_params
示例#12
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()
示例#13
0
        '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()):
示例#14
0
rad = 1
kernel = 'lanczos'
ksize = 4

xy, trunc_xy, truncmask = geometry.gencoords(N, 2, rad, True)
# premult = cryoops.compute_premultiplier(N, kernel='lanczos', kernsize=6)
premult = cryoops.compute_premultiplier(N, kernel, ksize)
TtoF = sincint.gentrunctofull(N=N, rad=rad)

fM = density.real_to_fspace(M)
prefM = density.real_to_fspace(premult.reshape(
        (1, 1, -1)) * premult.reshape((1, -1, 1)) * premult.reshape((-1, 1, 1)) * M)

EAs_grid = healpix.gen_EAs_grid(nside=2, psi_step=360)
Rs = [geometry.rotmat3D_EA(*EA)[:, 0:2] for EA in EAs_grid]
slice_ops = cryoops.compute_projection_matrix(Rs, N, kern='lanczos', kernsize=ksize, rad=rad, projdirtype='rots')

slices_sampled = cryoem.getslices(fM, slice_ops).reshape((EAs_grid.shape[0], trunc_xy.shape[0]))

premult_slices_sampled = cryoem.getslices(prefM, slice_ops).reshape((EAs_grid.shape[0], trunc_xy.shape[0]))

S = cryoops.compute_shift_phases(np.asarray([100, -20]).reshape((1,2)), N, rad)[0]

trunc_slice = slices_sampled[0]
premult_trunc_slice = premult_slices_sampled[0]
premult_trunc_slice_shift = S * premult_slices_sampled[0]

fourier_slice = TtoF.dot(trunc_slice).reshape((N, N))
real_proj = density.fspace_to_real(fourier_slice)
premult_fourier_slice = TtoF.dot(premult_trunc_slice).reshape((N, N))
premult_fourier_slice_shift = TtoF.dot(premult_trunc_slice_shift).reshape((N, N))