def __init__(self, initial_parameters=None, density_contrasts=None, num_filtering_scales=50, path=None, window_function="top hat", number_of_processors=10): """ Instantiates :class:`Inertia` given the Args: """ if initial_parameters is None: initial_parameters = parameters.InitialConditionsParameters( path=path) self.initial_parameters = initial_parameters self.delta_class = density.DensityContrasts( initial_parameters=initial_parameters, num_filtering_scales=num_filtering_scales, window_function=window_function) self.shear_class = shear.Shear( initial_parameters=initial_parameters, num_filtering_scales=num_filtering_scales, number_of_processors=number_of_processors) DensityPeaks.__init__(self, initial_parameters=initial_parameters, density_contrasts=density_contrasts, num_filtering_scales=num_filtering_scales, path=path, window_function=window_function)
def density_test(): shear_scale = range(50) s = shear.Shear(path="/Users/lls/Documents/CODE/", shear_scale=shear_scale) d = density.Density(path="/Users/lls/Documents/CODE/", shear_scale=shear_scale) # Density density_fourier = s._density_scale_fourier den_shear = np.array([ np.real(np.fft.ifftn(density_fourier[i]).reshape(s.shape**3, )) for i in shear_scale ]) den_correct = d._density np.testing.assert_allclose(den_correct.transpose(), den_shear) print("Passed density test") # Density contrast contrast_shear_fourier = np.array([ s.rescale_density_to_density_contrast_in_fourier_space( density_fourier[i]) for i in shear_scale ]) contrast_shear = np.array([ np.real(np.fft.ifftn(contrast_shear_fourier[i]).reshape(s.shape**3, )) for i in shear_scale ]) mean_density = d._mean_density contrast_correct = (den_correct - mean_density) / mean_density np.testing.assert_allclose(contrast_correct, contrast_shear) print("Passed density contrast test")
def reality_test_fourier_space(): s = shear.Shear(path="/Users/lls/Documents/CODE/", shear_scale=20) den = s._density_scale_fourier phi = s.get_potential_from_density_fourier_space(den, s.shape, s.boxsize) shear_fourier = s.get_shear_from_potential_in_fourier_space( phi, s.shape, s.boxsize) for i in range(s.shape): for j in range(s.shape): for k in range(s.shape): np.testing.assert_allclose(np.conj(shear_fourier[i, j, k]), shear_fourier[-i, -j, -k])
def trace_test_real_space(): s = shear.Shear(path="/Users/lls/Documents/CODE/", shear_scale=20) den = s._density_scale_fourier den_contrast = s.rescale_density_to_density_contrast_in_fourier_space(den) den_contrast_real = np.real( np.fft.ifftn(den_contrast).reshape(s.shape**3, )) shear_real = s.get_shear_tensor_at_scale(den) np.testing.assert_allclose(np.trace(shear_real, axis1=1, axis2=2), den_contrast_real, verbose=True, rtol=1e-07)
def test_sum_eigenvalues(): s = shear.Shear(path="/Users/lls/Documents/CODE/", shear_scale=20) den = s._density_scale_fourier den_contrast = s.rescale_density_to_density_contrast_in_fourier_space(den) den_contrast_real = np.real( np.fft.ifftn(den_contrast).reshape(s.shape**3, )) eig = s.shear_eigenvalues np.testing.assert_allclose(np.sum(eig, axis=1), den_contrast_real, verbose=True, rtol=1e-06)
def trace_test_fourier_space(): s = shear.Shear(path="/Users/lls/Documents/CODE/", shear_scale=20) den = s._density_scale_fourier den_contrast = s.rescale_density_to_density_contrast_in_fourier_space( den).reshape(s.shape**3, ) phi = s.get_potential_from_density_fourier_space(den, s.shape, s.boxsize) shear_fourier = s.get_shear_from_potential_in_fourier_space( phi, s.shape, s.boxsize).reshape(s.shape**3, 3, 3) np.testing.assert_allclose(np.trace(shear_fourier, axis1=1, axis2=2), den_contrast, verbose=True, rtol=1e-07)
def test_sum_eigenvalues_for_all_50_ranges(): s = shear.Shear(path="/Users/lls/Documents/CODE/", shear_scale=range(50)) eig = s.shear_eigenvalues sum_eig = np.zeros((s.shape**3, 50)) for i in range(50): eig_i = eig[:, int(3 * i):int(3 * i) + 3] sum_eig[:, i] = np.sum(eig_i, axis=1) d = density.Density(path="/Users/lls/Documents/CODE/") densities = d._density mean_densities = d._mean_density contrasts = (densities - mean_densities) / mean_densities np.testing.assert_allclose(sum_eig, contrasts, verbose=True, rtol=1e-06)
def reality_test_real_space(): s = shear.Shear(path="/Users/lls/Documents/CODE/", shear_scale=range(50)) densities = s._density_scale_fourier for i in range(densities.shape[0]): den = densities[i] assert den.shape == (s.shape, s.shape, s.shape) phi = s.get_potential_from_density_fourier_space( den, s.shape, s.boxsize) shear_fourier = s.get_shear_from_potential_in_fourier_space( phi, s.shape, s.boxsize) shear_real = np.fft.ifftn(shear_fourier, axes=(0, 1, 2)).reshape( (s.shape**3, 3, 3)) assert np.imag(shear_real).max() < 1e-15