cosmotool/python_sample/icgen/borgadaptor.py
2014-06-04 09:13:34 +02:00

21 lines
501 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, doshift=False):
dhat,L,N = fourier_analysis(borg)
if not doshift:
return dhat, L
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