def correlation_array(self): "The correlation function from the input power, on the grid" pa = empty((self.N, ) * self.dim) pa[...] = self.power_array() return self.V * np.real( dft.ifft(pa, L=self.boxlength, a=self.fourier_a, b=self.fourier_b)[0])
def gaussian_power_array(self): "The power spectrum required for a Gaussian field to produce the input power on a lognormal field" gca = empty((self.N, ) * self.dim) gca[...] = self.gaussian_correlation_array() gpa = np.abs( dft.fft(gca, L=self.boxlength, a=self.fourier_a, b=self.fourier_b))[0] gpa[self.k() == 0] = 0 return gpa
def delta_x(self): "The real-space over-density field, from the input power spectrum" dk = empty((self.N, ) * self.dim, dtype='complex128') dk[...] = self.delta_k() dk[...] = np.sqrt(self.V) * dft.ifft( dk, L=self.boxlength, a=self.fourier_a, b=self.fourier_b)[0] dk = np.real(dk) sg = np.var(dk) return np.exp(dk - sg / 2) - 1
def delta_x(self): "The realised field in real-space from the input power spectrum" # Here we multiply by V because the (inverse) fourier-transform of the (dimensionless) power has # units of 1/V and we require a unitless quantity for delta_x. dk = empty((self.N, ) * self.dim, dtype='complex128') dk[...] = self.delta_k() dk[...] = self.V * dft.ifft( dk, L=self.boxlength, a=self.fourier_a, b=self.fourier_b)[0] dk = np.real(dk) if self.ensure_physical: np.clip(dk, -1, np.inf, dk) return dk