本文整理汇总了Python中numpy.fft.fftn方法的典型用法代码示例。如果您正苦于以下问题:Python fft.fftn方法的具体用法?Python fft.fftn怎么用?Python fft.fftn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.fft
的用法示例。
在下文中一共展示了fft.fftn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_lct
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def run_lct(self, meas, X, Y, Z, S, x_max, y_max):
self.max_dist = int(self.T * self.v/2 / self.channels[0])
slope_x = self.dx * x_max / (self.fend/self.B * self.max_dist) * (1 + ((self.fstart/self.B)/(self.fend/self.B))**2)
slope_y = self.dy * y_max / (self.fend/self.B * self.max_dist) * (1 + ((self.fstart/self.B)/(self.fend/self.B))**2)
# params
psf, fpsf = lct.getPSF(X, Y, Z, S, slope_x, slope_y)
mtx, mtxi = lct.interpMtx(Z, S, self.fstart/self.B * self.max_dist, self.fend/self.B * self.max_dist)
def pad_array(x, S, Z, X, Y):
return np.pad(x, ((S*Z//2, S*Z//2), (Y//2, Y//2), (X//2, X//2)), 'constant')
def trim_array(x, S, Z, X, Y):
return x[S*int(np.floor(Z/2))+1:-S*int(np.ceil(Z/2))+1, Y//2+1:-Y//2+1, X//2+1:-X//2+1]
invpsf = np.conj(fpsf) / (abs(fpsf)**2 + 1 / self.snr)
tdata = np.matmul(mtx, meas.reshape((Z, -1))).reshape((-1, Y, X))
fdata = fftn(pad_array(tdata, S, Z, X, Y))
tvol = abs(trim_array(ifftn(fdata * invpsf), S, Z, X, Y))
out = np.matmul(mtxi, tvol.reshape((S*Z, -1))).reshape((-1, Y, X))
return out
示例2: getPSF
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def getPSF(X, Y, Z, S, slope_x, slope_y):
x = np.linspace(-1, 1, 2*X)
y = np.linspace(-1, 1, 2*Y)
z = np.linspace(0,2,2*S*Z)
grid_z, grid_y, grid_x = np.meshgrid(z, y, x, indexing='ij')
psf = np.abs(slope_x**2 * grid_x**2 + slope_y**2 * grid_y**2 - grid_z)
psf = psf == np.tile(np.min(psf, axis=0, keepdims=True), (2*S*Z, 1, 1))
psf = psf.astype(np.float32)
psf = psf / np.sum(psf)
psf = np.roll(psf, X, axis=2)
psf = np.roll(psf, Y, axis=1)
fpsf = fftn(psf)
return psf, fpsf
示例3: lct
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def lct(x1, y1, t1, v, vol, snr):
X = len(x1)
Y = len(y1)
Z = len(t1)
S = 2
slope = np.max(x1) / (np.max(t1) * v/2)
slope = np.max(y1) / (np.max(t1) * v/2)
psf, fpsf = getPSF(X, Y, Z, S, slope)
mtx, mtxi = interpMtx(Z, S, 0, np.max(t1)*v)
def pad_array(x, S, Z, X):
return np.pad(x, ((S*Z//2, S*Z//2), (X//2, X//2), (Y//2, Y//2)), 'constant')
def trim_array(x, S, Z, X):
return x[S*(Z//2)+1:-S*(Z//2)+1, X//2+1:-X//2+1, Y//2+1:-Y//2+1]
invpsf = np.conj(fpsf) / (abs(fpsf)**2 + 1 / snr)
tdata = np.matmul(mtx, vol)
fdata = fftn(pad_array(tdata, S, Z, X))
tvol = abs(trim_array(ifftn(fdata * invpsf), S, Z, X))
vol = np.matmul(mtxi, tvol)
return vol
示例4: fl2norm2
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def fl2norm2(xf, axis=(0, 1)):
r"""Compute the squared :math:`\ell_2` norm in the DFT domain.
Compute the squared :math:`\ell_2` norm in the DFT domain, taking
into account the unnormalised DFT scaling, i.e. given the DFT of a
multi-dimensional array computed via :func:`fftn`, return the
squared :math:`\ell_2` norm of the original array.
Parameters
----------
xf : array_like
Input array
axis : sequence of ints, optional (default (0,1))
Axes on which the input is in the frequency domain
Returns
-------
x : float
:math:`\|\mathbf{x}\|_2^2` where the input array is the result of
applying :func:`fftn` to the specified axes of multi-dimensional
array :math:`\mathbf{x}`
"""
xfs = xf.shape
return (np.linalg.norm(xf)**2) / np.prod(np.array([xfs[k] for k in axis]))
示例5: run_test_c2c_impl
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def run_test_c2c_impl(self, shape, axes, inverse=False, fftshift=False):
shape = list(shape)
shape[-1] *= 2 # For complex
known_data = np.random.normal(size=shape).astype(np.float32).view(np.complex64)
idata = bf.ndarray(known_data, space='cuda')
odata = bf.empty_like(idata)
fft = Fft()
fft.init(idata, odata, axes=axes, apply_fftshift=fftshift)
fft.execute(idata, odata, inverse)
if inverse:
if fftshift:
known_data = np.fft.ifftshift(known_data, axes=axes)
# Note: Numpy applies normalization while CUFFT does not
norm = reduce(lambda a, b: a * b, [known_data.shape[d]
for d in axes])
known_result = gold_ifftn(known_data, axes=axes) * norm
else:
known_result = gold_fftn(known_data, axes=axes)
if fftshift:
known_result = np.fft.fftshift(known_result, axes=axes)
x = (np.abs(odata.copy('system') - known_result) / known_result > RTOL).astype(np.int32)
a = odata.copy('system')
b = known_result
compare(odata.copy('system'), known_result)
示例6: get_numpy
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def get_numpy(shape, fftn_shape=None, **kwargs):
import numpy.fft as numpy_fft
f = {
"fft2": numpy_fft.fft2,
"ifft2": numpy_fft.ifft2,
"rfft2": numpy_fft.rfft2,
"irfft2": lambda X: numpy_fft.irfft2(X, s=shape),
"fftshift": numpy_fft.fftshift,
"ifftshift": numpy_fft.ifftshift,
"fftfreq": numpy_fft.fftfreq,
}
if fftn_shape is not None:
f["fftn"] = numpy_fft.fftn
fft = SimpleNamespace(**f)
return fft
示例7: get_scipy
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def get_scipy(shape, fftn_shape=None, **kwargs):
import numpy.fft as numpy_fft
import scipy.fftpack as scipy_fft
# use numpy implementation of rfft2/irfft2 because they have not been
# implemented in scipy.fftpack
f = {
"fft2": scipy_fft.fft2,
"ifft2": scipy_fft.ifft2,
"rfft2": numpy_fft.rfft2,
"irfft2": lambda X: numpy_fft.irfft2(X, s=shape),
"fftshift": scipy_fft.fftshift,
"ifftshift": scipy_fft.ifftshift,
"fftfreq": scipy_fft.fftfreq,
}
if fftn_shape is not None:
f["fftn"] = scipy_fft.fftn
fft = SimpleNamespace(**f)
return fft
示例8: potential
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def potential(self, q, steps):
hx = steps[0]
hy = steps[1]
hz = steps[2]
Nx = q.shape[0]
Ny = q.shape[1]
Nz = q.shape[2]
out = np.zeros((2*Nx-1, 2*Ny-1, 2*Nz-1))
out[:Nx, :Ny, :Nz] = q
K1 = self.sym_kernel(q.shape, steps)
K2 = np.zeros((2*Nx-1, 2*Ny-1, 2*Nz-1))
K2[0:Nx, 0:Ny, 0:Nz] = K1
K2[0:Nx, 0:Ny, Nz:2*Nz-1] = K2[0:Nx, 0:Ny, Nz-1:0:-1] #z-mirror
K2[0:Nx, Ny:2*Ny-1,:] = K2[0:Nx, Ny-1:0:-1, :] #y-mirror
K2[Nx:2*Nx-1, :, :] = K2[Nx-1:0:-1, :, :] #x-mirror
t0 = time.time()
if pyfftw_flag:
nthreads = int(conf.OCELOT_NUM_THREADS)
if nthreads < 1:
nthreads = 1
K2_fft = pyfftw.builders.fftn(K2, axes=None, overwrite_input=False, planner_effort='FFTW_ESTIMATE',
threads=nthreads, auto_align_input=False, auto_contiguous=False, avoid_copy=True)
out_fft = pyfftw.builders.fftn(out, axes=None, overwrite_input=False, planner_effort='FFTW_ESTIMATE',
threads=nthreads, auto_align_input=False, auto_contiguous=False, avoid_copy=True)
out_ifft = pyfftw.builders.ifftn(out_fft()*K2_fft(), axes=None, overwrite_input=False, planner_effort='FFTW_ESTIMATE',
threads=nthreads, auto_align_input=False, auto_contiguous=False, avoid_copy=True)
out = np.real(out_ifft())
else:
out = np.real(ifftn(fftn(out)*fftn(K2)))
t1 = time.time()
logger.debug('fft time:' + str(t1-t0) + ' sec')
out[:Nx, :Ny, :Nz] = out[:Nx,:Ny,:Nz]/(4*pi*epsilon_0*hx*hy*hz)
return out[:Nx, :Ny, :Nz]
示例9: bench_random
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def bench_random(self):
from numpy.fft import fftn as numpy_fftn
print()
print(' Multi-dimensional Fast Fourier Transform')
print('===================================================')
print(' | real input | complex input ')
print('---------------------------------------------------')
print(' size | scipy | numpy | scipy | numpy ')
print('---------------------------------------------------')
for size,repeat in [((100,100),100),((1000,100),7),
((256,256),10),
((512,512),3),
]:
print('%9s' % ('%sx%s' % size), end=' ')
sys.stdout.flush()
for x in [random(size).astype(double),
random(size).astype(cdouble)+random(size).astype(cdouble)*1j
]:
y = fftn(x)
#if size > 500: y = fftn(x)
#else: y = direct_dft(x)
assert_array_almost_equal(fftn(x),y)
print('|%8.2f' % measure('fftn(x)',repeat), end=' ')
sys.stdout.flush()
assert_array_almost_equal(numpy_fftn(x),y)
print('|%8.2f' % measure('numpy_fftn(x)',repeat), end=' ')
sys.stdout.flush()
print(' (secs for %s calls)' % (repeat))
sys.stdout.flush()
示例10: fftd
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def fftd(I, dims=None):
# Compute fft
if dims is None:
X = fftn(I)
elif dims == 2:
X = fft2(I, axes=(0, 1))
else:
X = fftn(I, axes=tuple(range(dims)))
return X
示例11: fftnc
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def fftnc(x, axes, ortho=True):
tmp = fft.fftshift(x, axes=axes)
tmp = fft.fftn(tmp, axes=axes, norm="ortho" if ortho else None)
return fft.ifftshift(tmp, axes=axes)
示例12: filter_given_curve
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def filter_given_curve(v, curve):
grid = GV.grid_displacement_to_center(v.shape, GV.fft_mid_co(v.shape))
rad = GV.grid_distance_to_center(grid)
rad = N.round(rad).astype(N.int)
b = N.zeros(rad.shape)
for (i, a) in enumerate(curve):
b[(rad == i)] = a
vf = ifftn(ifftshift((fftshift(fftn(v)) * b)))
vf = N.real(vf)
return vf
示例13: __init__
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def __init__(self, images, band_width_radius=1.0):
im_f = {}
for k in range(len(images)):
im = images[k]
im = fftshift(fftn(im))
im_f[k] = im
self.im_f = im_f # fft transformed images
self.ks = set()
self.img_siz = im_f[k].shape
self.set_fft_mid_co()
self.set_rad()
self.band_width_radius = band_width_radius
示例14: __init__
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def __init__(self, images, masks, band_width_radius=1.0):
im_f = {}
for k in images:
im = images[k]
im = fftshift(fftn(im))
im_f[k] = im
self.im_f = im_f # fft transformed images
self.ms = masks # masks
self.ks = set()
self.img_siz = im_f[k].shape
self.set_fft_mid_co()
self.set_rad()
self.band_width_radius = band_width_radius
示例15: fourier_transform
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftn [as 别名]
def fourier_transform(v):
return fftshift(fftn(v))