本文整理汇总了Python中numpy.fft.fftshift方法的典型用法代码示例。如果您正苦于以下问题:Python fft.fftshift方法的具体用法?Python fft.fftshift怎么用?Python fft.fftshift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.fft
的用法示例。
在下文中一共展示了fft.fftshift方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ptf
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def ptf(self):
"""
Phase transfer function
"""
PSF = self.__psfcaculator__()
PTF = __fftshift__(__fft2__(PSF))
PTF = __np__.angle(PTF)
b = 400
R = (200)**2
for i in range(b):
for j in range(b):
if (i-b/2)**2+(j-b/2)**2>R:
PTF[i][j] = 0
__plt__.imshow(abs(PTF),cmap=__cm__.rainbow)
__plt__.colorbar()
__plt__.show()
return 0
示例2: ift2
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def ift2(G, delta_f, FFT=None):
"""
Wrapper for inverse fourier transform
Parameters:
G: data to transform
delta_f: pixel seperation
FFT (FFT object, optional): An accelerated FFT object
"""
N = G.shape[0]
if FFT:
g = numpy.fft.fftshift(FFT(numpy.fft.fftshift(G))) * (N * delta_f) ** 2
else:
g = fft.ifftshift(fft.ifft2(fft.fftshift(G))) * (N * delta_f) ** 2
return g
示例3: impute_aligned_vols
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def impute_aligned_vols(t, v, vm, normalize=None):
assert (normalize is not None)
if normalize:
v = ((v - v.mean()) / v.std())
if (t is not None):
t = ((t - t.mean()) / t.std())
if (t is None):
return v
t_f = NF.fftshift(NF.fftn(t))
v_f = NF.fftshift(NF.fftn(v))
v_f[(vm == 0)] = t_f[(vm == 0)]
v_f_if = N.real(NF.ifftn(NF.ifftshift(v_f)))
if normalize:
v_f_if = ((v_f_if - v_f_if.mean()) / v_f_if.std())
if N.all(N.isfinite(v_f_if)):
return v_f_if
else:
print('warning: imputation failed')
return v
示例4: average
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def average(dj, mask_count_threshold):
vol_sum = None
mask_sum = None
for d in dj:
v = IF.read_mrc_vol(d['subtomogram'])
if (not N.all(N.isfinite(v))):
raise Exception('error loading', d['subtomogram'])
vm = IF.read_mrc_vol(d['mask'])
v_r = GR.rotate_pad_mean(v, angle=d['angle'], loc_r=d['loc'])
assert N.all(N.isfinite(v_r))
vm_r = GR.rotate_mask(vm, angle=d['angle'])
assert N.all(N.isfinite(vm_r))
if (vol_sum is None):
vol_sum = N.zeros(v_r.shape, dtype=N.float64, order='F')
vol_sum += v_r
if (mask_sum is None):
mask_sum = N.zeros(vm_r.shape, dtype=N.float64, order='F')
mask_sum += vm_r
ind = (mask_sum >= mask_count_threshold)
vol_sum_fft = NF.fftshift(NF.fftn(vol_sum))
avg = N.zeros(vol_sum_fft.shape, dtype=N.complex)
avg[ind] = (vol_sum_fft[ind] / mask_sum[ind])
avg = N.real(NF.ifftn(NF.ifftshift(avg)))
return {'v': avg, 'm': (mask_sum / len(dj)), }
示例5: test_definition
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
y = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
assert_array_almost_equal(fft.fftshift(x), y)
assert_array_almost_equal(fft.ifftshift(y), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
assert_array_almost_equal(fft.fftshift(x), y)
assert_array_almost_equal(fft.ifftshift(y), x)
示例6: test_inverse
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def test_inverse(self):
for n in [1, 4, 9, 100, 211]:
x = np.random.random((n,))
assert_array_almost_equal(fft.ifftshift(fft.fftshift(x)), x)
示例7: test_axes_keyword
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def test_axes_keyword(self):
freqs = [[0, 1, 2], [3, 4, -4], [-3, -2, -1]]
shifted = [[-1, -3, -2], [2, 0, 1], [-4, 3, 4]]
assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted)
assert_array_almost_equal(fft.fftshift(freqs, axes=0),
fft.fftshift(freqs, axes=(0,)))
assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs)
assert_array_almost_equal(fft.ifftshift(shifted, axes=0),
fft.ifftshift(shifted, axes=(0,)))
assert_array_almost_equal(fft.fftshift(freqs), shifted)
assert_array_almost_equal(fft.ifftshift(shifted), freqs)
示例8: test_axes_keyword
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def test_axes_keyword(self):
freqs = [[0, 1, 2], [3, 4, -4], [-3, -2, -1]]
shifted = [[-1, -3, -2], [2, 0, 1], [-4, 3, 4]]
assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted)
assert_array_almost_equal(fft.fftshift(freqs, axes=0),
fft.fftshift(freqs, axes=(0,)))
assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs)
assert_array_almost_equal(fft.ifftshift(shifted, axes=0),
fft.ifftshift(shifted, axes=(0,)))
示例9: test_axes_keyword
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def test_axes_keyword(self):
freqs = [[ 0, 1, 2], [ 3, 4, -4], [-3, -2, -1]]
shifted = [[-1, -3, -2], [ 2, 0, 1], [-4, 3, 4]]
assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted)
assert_array_almost_equal(fft.fftshift(freqs, axes=0),
fft.fftshift(freqs, axes=(0,)))
assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs)
assert_array_almost_equal(fft.ifftshift(shifted, axes=0),
fft.ifftshift(shifted, axes=(0,)))
示例10: analyze
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def analyze(f, axis=0):
"""
Compute the Fourier Transform of the discretely sampled function f : T^1 -> C.
Let f : T^1 -> C be a band-limited function on the circle.
The samples f(theta_k) correspond to points on a regular grid on the circle, as returned by spaces.T1.linspace:
theta_k = 2 pi k / N
for k = 0, ..., N - 1
This function computes
\hat{f}_n = (1/N) \sum_{k=0}^{N-1} f(theta_k) e^{-i n theta_k}
which, if f has band-limit less than N, is equal to:
\hat{f}_n = \int_0^{2pi} f(theta) e^{-i n theta} dtheta / 2pi,
= <f(theta), e^{i n theta}>
where dtheta / 2pi is the normalized Haar measure on T^1, and < , > denotes the inner product on Hilbert space,
with respect to which this transform is unitary.
The range of frequencies n is -floor(N/2) <= n <= ceil(N/2) - 1
:param f:
:param axis:
:return:
"""
# The numpy FFT returns coefficients in a different order than we want them,
# and using a different normalization.
fhat = fft(f, axis=axis)
fhat = fftshift(fhat, axes=axis)
return fhat / f.shape[axis]
示例11: analyze_naive
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def analyze_naive(f):
f_hat = np.zeros_like(f)
for n in range(f.size):
for k in range(f.size):
theta_k = k * 2 * np.pi / f.size
f_hat[n] += f[k] * np.exp(-1j * n * theta_k)
return fftshift(f_hat / f.size, axes=0)
示例12: analyze
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def analyze(f, axes=(0, 1)):
"""
Compute the Fourier Transform of the discretely sampled function f : T^2 -> C.
Let f : T^2 -> C be a band-limited function on the torus.
The samples f(theta_k, phi_l) correspond to points on a regular grid on the circle,
as returned by spaces.T1.linspace:
theta_k = phi_k = 2 pi k / N
for k = 0, ..., N - 1 and l = 0, ..., N - 1
This function computes
\hat{f}_n = (1/N) \sum_{k=0}^{N-1} f(theta_k) e^{-i n theta_k}
which, if f has band-limit less than N, is equal to:
\hat{f}_n = \int_0^{2pi} f(theta) e^{-i n theta} dtheta / 2pi,
= <f(theta), e^{i n theta}>
where dtheta / 2pi is the normalized Haar measure on T^1, and < , > denotes the inner product on Hilbert space,
with respect to which this transform is unitary.
The range of frequencies n is -floor(N/2) <= n <= ceil(N/2) - 1
:param f:
:param axis:
:return:
"""
# The numpy FFT returns coefficients in a different order than we want them,
# and using a different normalization.
f_hat = fft2(f, axes=axes)
f_hat = fftshift(f_hat, axes=axes)
size = np.prod([f.shape[ax] for ax in axes])
return f_hat / size
示例13: __psfcaculator__
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def __psfcaculator__(self,lambda_1=632*10**(-9),z=0.1):
"""
height: Exit pupil height
width: Exit pupil width
z: Distance from exit pupil to image plane
"""
a = self.__a__
b = __sqrt__(1-a**2)
l1 = 100;
x1 = __np__.linspace(-a, a, l1)
y1 = __np__.linspace(-b, b, l1)
[X,Y] = __np__.meshgrid(x1,y1)
Z = __zernikecartesian__(self.__coefficients__,a,X,Y)
d = 400 # background
A = __np__.zeros([d,d])
A[d//2-l1//2+1:d//2+l1//2+1,d//2-l1//2+1:d//2+l1//2+1] = Z
# fig = __plt__.figure()
# __plt__.imshow(A)
# __plt__.colorbar()
# __plt__.show()
abbe = __np__.exp(-1j*2*__np__.pi*A)
for i in range(len(abbe)):
for j in range(len(abbe)):
if abbe[i][j]==1:
abbe[i][j]=0
PSF = __fftshift__(__fft2__(__fftshift__(abbe)))**2
PSF = PSF/PSF.max()
return PSF
示例14: mtf
# 需要导入模块: from numpy import fft [as 别名]
# 或者: from numpy.fft import fftshift [as 别名]
def mtf(self,lambda_1=632*10**(-9),z=0.1,matrix = False):
"""
Modulate Transfer function
"""
PSF = self.__psfcaculator__(lambda_1=lambda_1,z=z)
MTF = __fftshift__(__fft2__(PSF))
MTF = MTF/MTF.max()
fig = __plt__.figure(figsize=(9, 6), dpi=80)
__plt__.imshow(abs(MTF),cmap=__cm__.bwr)
__plt__.colorbar()
__plt__.show()
if matrix == True:
return MTF
else:
return 0