<jupyter_start><jupyter_text>Testing density extraction from snapshots<jupyter_code># This is the content of test density plane
fpm_plane, lt_plane, smooth_fpm_plane, smooth_lt_plane = test_density_plane(return_results=True)
# Showing the comparison of non-smooth fields
figure(figsize=[15,5])
subplot(131)
imshow(lt_plane)
title('density plane from lenstools')
colorbar()
subplot(132)
imshow(fpm_plane[0])
title('density plane from flowpm')
colorbar()
subplot(133)
imshow(lt_plane - fpm_plane[0])
title('residuals')
colorbar()
# Showing the comparison of smoothed fields
figure(figsize=[15,5])
subplot(131)
imshow(smooth_lt_plane)
colorbar()
subplot(132)
imshow(smooth_fpm_plane)
colorbar()
subplot(133)
imshow(abs(smooth_lt_plane - smooth_fpm_plane)/smooth_lt_plane)
colorbar()
def radial_profile(power_spectrum_2d):
    """
    Compute the radial profile of 2d image
    :param data: 2d image
    :return: radial profile
    """
    center = power_spectrum_2d.shape[0]/2
    v, u = np.indices((power_spectrum_2d.shape))
    k = np.sqrt((u - center)**2 + (v - center)**2)
    k = k.astype('int32')

    tbin = np.bincount(k.ravel(), power_spectrum_2d.ravel())
    nr = np.bincount(k.ravel())
    radialprofile = tbin / nr
    return radialprofile

def measure_power_spectrum(map_data, pixel_size, resolution):
    """
    measures power 2d data
    :param map_data: map (n x n)
    :param pixel_size: pixel size (rad/pixel)
    :return: ell
    :return: power spectrum
    """
    data_ft = np.abs(np.fft.fft2(map_data))
    data_ft_shifted = np.fft.fftshift(data_ft) 
    power_spectrum_2d = np.abs(data_ft_shifted * np.conjugate(data_ft_shifted)) / 512**2
    nyquist = np.int(data_ft_shifted.shape[0] / 2)
    radialprofile = radial_profile(power_spectrum_2d)
    power_spectrum_1d = radialprofile[:nyquist] * (pixel_size)**2

    # Convert frequencies to angular multipoles \ell
    k = np.arange(power_spectrum_1d.shape[0])
    ell = 2. * np.pi * k / pixel_size / 360

    return ell, power_spectrum_1d
_, ps1 = measure_power_spectrum(smooth_lt_plane, 1., 64)
_, ps2 = measure_power_spectrum(smooth_fpm_plane, 1., 64)
loglog(ps1, label='lenstools')
loglog(ps2, '--', label='flowpm')
legend()
ylim(1e-22,1e-6)<jupyter_output><empty_output><jupyter_text>Testing computation of convergence maps with the Born approximation<jupyter_code># This is the content of test density plane
lt_map, fpm_map = test_convergence_Born(return_results=True)
figure(figsize=[15,5])
subplot(131)
imshow(lt_map); colorbar()
title('kappa from lenstools')
subplot(132)
imshow(fpm_map[0].numpy().reshape([64,64,-1])[:,:,-1]); colorbar()
title('kappa from flowpm')

subplot(133)
imshow(lt_map - fpm_map[0].numpy().reshape([64,64,-1])[:,:,-1]); colorbar()
title('residuals')
from numpy.testing import assert_allclose
assert_allclose(lt_map, fpm_map[0].numpy().reshape([64,64,-1])[:,:,-1], atol=5e-4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13789546079779919, 'fraction_numerical': 0.03679504814305364, 'mean_word_length': 5.581447963800905, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '210187', 'license': 'MIT', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1074, 'n_words': 214, 'path': 'notebooks/dev/test_raytracing.ipynb', 'repo_name': 'santiagocasas/flowpm', 'size': '2908'}