19 lines
445 B
Python
19 lines
445 B
Python
|
import numpy as np
|
||
|
|
||
|
def fourier_analysis(borg_vol):
|
||
|
L = (borg_vol.ranges[1]-borg_vol.ranges[0])
|
||
|
N = borg_vol.density.shape[0]
|
||
|
|
||
|
return np.fft.rfftn(borg_vol.density)*(L/N)**3, L, N
|
||
|
|
||
|
def half_pixel_shift(borg):
|
||
|
|
||
|
dhat,L,N = fourier_analysis(borg)
|
||
|
|
||
|
ik = np.fft.fftfreq(N,d=L/N)*2*np.pi
|
||
|
phi = 0.5*L/N*(ik[:,None,None]+ik[None,:,None]+ik[None,None,:(N/2+1)])
|
||
|
phase = np.cos(phi)+1j*np.sin(phi)
|
||
|
|
||
|
return dhat*phase, L
|
||
|
|