Beispiel #1
0
    def test_fftn_error_on_wrong_plan(self, dtype, enable_nd):
        # This test ensures the context manager plan is picked up

        from cupyx.scipy.fftpack import get_fft_plan
        from cupy.fft import fftn
        assert config.enable_nd_planning == enable_nd

        # can't get a plan, so skip
        if self.axes is not None:
            if self.s is not None:
                if len(self.s) != len(self.axes):
                    return
            elif len(self.shape) != len(self.axes):
                return

        a = testing.shaped_random(self.shape, cupy, dtype)
        bad_in_shape = tuple(2 * i for i in self.shape)
        if self.s is None:
            bad_out_shape = bad_in_shape
        else:
            bad_out_shape = tuple(2 * i for i in self.s)
        b = testing.shaped_random(bad_in_shape, cupy, dtype)
        plan_wrong = get_fft_plan(b, bad_out_shape, self.axes)

        with pytest.raises(ValueError) as ex, plan_wrong:
            fftn(a, s=self.s, axes=self.axes, norm=self.norm)
        # targeting a particular error
        assert 'The CUFFT plan and a.shape do not match' in str(ex.value)
def fourierReconstructGPU(vol_img,
                          vol_bp,
                          vol_phi,
                          vol_the,
                          recPosVol=[0, 0, 0],
                          vol_offsetProjections=[0, 0, 0]):
    from pytom_numpy import vol2npy
    import cupy as cp
    from pytom.voltools import transform
    from cupy.fft import fftshift, ifftn, fftn
    import numpy
    from cupyx.scipy.ndimage import rotate
    interpolation = 'filt_bspline'
    projections = vol2npy(vol_img)
    projections = cp.array(projections)
    proj_angles = vol2npy(vol_the)[0, 0, :]
    dims = (projections.shape[0], projections.shape[0], projections.shape[0])
    tot = cp.zeros(dims, cp.complex64)

    for n in range(projections.shape[2]):
        org = cp.zeros(dims, dtype=cp.complex64)
        rot = cp.zeros(dims, dtype=cp.complex64)
        ff = fftshift(fftn(fftshift(projections[:, :, n])))

        org[:, :, dims[0] // 2] = ff
        #print(n,ff.shape, org.shape)
        if 0:
            rot.real = rotate(org.real,
                              proj_angles[n],
                              axes=(2, 0),
                              reshape=False)
            rot.imag = rotate(org.imag,
                              proj_angles[n],
                              axes=(2, 0),
                              reshape=False)
        else:
            rot.real = transform(org.real,
                                 rotation=(0, proj_angles[n], 0),
                                 rotation_order='sxyz',
                                 interpolation=interpolation)
            rot.imag = transform(org.imag,
                                 rotation=(0, proj_angles[n], 0),
                                 rotation_order='sxyz',
                                 interpolation=interpolation)
        tot += rot
        del org, rot

    if dims[0] % 2:
        t = cp.zeros_like(tot)
        t[1:, 1:, 1:] = tot[:-1, :-1, :-1]
    else:
        t = tot

    return fftshift((ifftn(fftshift(t)).real)).get()