csiborgtools/notebooks/overlap/lagrangian_patch_example.ipynb
2024-09-18 23:42:17 +01:00

244 KiB

Lagrangian patch example

In [1]:
import numpy as np

import matplotlib.pyplot as plt
import scienceplots

import csiborgtools


%matplotlib inline

%load_ext autoreload
%autoreload 2
In [49]:
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
bounds = {"dist": (0, 155)}

nsim0 = 7444 + 24 * 61
nsnap_final = paths.get_snapshots(nsim0, "csiborg1")[-1]
snap0_initial = csiborgtools.read.CSiBORG1Snapshot(nsim0, nsnap=1)
cat0 = csiborgtools.read.CSiBORG1Catalogue(nsim0, paths, snapshot=snap0_initial, bounds=bounds)

nsimx = 9844
nsnap_final = paths.get_snapshots(nsimx, "csiborg1")[-1]
snapx_initial = csiborgtools.read.CSiBORG1Snapshot(nsimx, nsnap=1)
catx = csiborgtools.read.CSiBORG1Catalogue(nsimx, paths, snapshot=snapx_initial, bounds=bounds)

pair_overlapper = csiborgtools.summary.PairOverlap(cat0, catx, 13.25, )
In [50]:
k = np.argsort(cat0["totmass"])[::-1][1]

print(np.log10(cat0["totmass"][k]))
print(cat0["dist"][k])

hid0 = cat0["index"][k]
15.319891
74.15419337073868
In [51]:
print("Overlaps are ", pair_overlapper.overlap(True)[k])
hidx = catx["index"][pair_overlapper["match_indxs"][k][0]]
Overlaps are  [7.8512335e-01 9.1506150e-03 2.9659141e-03 3.0178351e-03 2.0852157e-04]
In [52]:
overlapper = csiborgtools.match.ParticleOverlap(**{"box_size": 2048, "bckg_halfsize": 512})

pos0_initial = snap0_initial.halo_coordinates(hid0)
pos0_initial = csiborgtools.match.pos2cell(pos0_initial / cat0.boxsize, 2048)
mass0_initial = snap0_initial.halo_masses(hid0)


posx_initial = snapx_initial.halo_coordinates(hidx)
posx_initial = csiborgtools.match.pos2cell(posx_initial / catx.boxsize, 2048)
massx_initial = snapx_initial.halo_masses(hidx)
In [55]:
smooth_kwargs = {"sigma": 1, "mode": "constant", "cval": 0}
# smooth_kwargs = None

delta1_initial, delta2_initial, cellmins, __ = overlapper.make_deltas(
    pos0_initial, posx_initial, mass0_initial, massx_initial, smooth_kwargs=smooth_kwargs, )

x0 = cellmins[0] / 2048 * 677.7
xf = (cellmins[0] + delta1_initial.shape[0]) / 2048 * 677.7

y0 = cellmins[1] / 2048 * 677.7
yf = (cellmins[1] + delta1_initial.shape[1]) / 2048 * 677.7
In [56]:
with plt.style.context("science"):
    # plt.rcParams.update({'font.size': 9})

    fig, axs = plt.subplots(1, 2, figsize=(8.3, 0.6* 8.3), sharey=True, sharex=True)
    fig.subplots_adjust(wspace=0.05, hspace=0.05)

    kwargs = {"origin": "lower", "cmap": "viridis", "vmin": 0,
              "extent": [x0, xf, y0, yf]}

    axs[0].imshow(np.mean(delta1_initial, axis=-1), **kwargs)
    axs[1].imshow(np.mean(delta2_initial, axis=-1), **kwargs)

    for i in range(2):
        axs[i].set_xlabel(r"$x ~ [\mathrm{cMpc} / h]$")
    axs[0].set_ylabel(r"$y ~ [\mathrm{cMpc} / h]$")

    axs[0].set_title(f"MCMC step {nsim0}")
    axs[1].set_title(f"MCMC step {nsimx}")

    fig.tight_layout()
    fig.savefig("../../plots/lagrangian_patch_example.pdf", bbox_inches="tight", dpi=450)
    fig.show()
/tmp/ipykernel_2722989/1176586521.py:10: RuntimeWarning: Mean of empty slice
  axs[0].imshow(np.nanmean(delta1_initial, axis=-1), **kwargs)
/tmp/ipykernel_2722989/1176586521.py:11: RuntimeWarning: Mean of empty slice
  axs[1].imshow(np.nanmean(delta2_initial, axis=-1), **kwargs)
No description has been provided for this image
In [ ]: