mirror of
https://github.com/Richard-Sti/csiborgtools.git
synced 2024-12-22 23:08:02 +00:00
9e4b34f579
* Update README * Update density field reader * Update name of SDSSxALFAFA * Fix quick bug * Add little fixes * Update README * Put back fit_init * Add paths to initial snapshots * Add export * Remove some choices * Edit README * Add Jens' comments * Organize imports * Rename snapshot * Add additional print statement * Add paths to initial snapshots * Add masses to the initial files * Add normalization * Edit README * Update README * Fix bug in CSiBORG1 so that does not read fof_00001 * Edit README * Edit README * Overwrite comments * Add paths to init lag * Fix Quijote path * Add lagpatch * Edit submits * Update README * Fix numpy int problem * Update README * Add a flag to keep the snapshots open when fitting * Add a flag to keep snapshots open * Comment out some path issue * Keep snapshots open * Access directly snasphot * Add lagpatch for CSiBORG2 * Add treatment of x-z coordinates flipping * Add radial velocity field loader * Update README * Add lagpatch to Quijote * Fix typo * Add setter * Fix typo * Update README * Add output halo cat as ASCII * Add import * Add halo plot * Update README * Add evaluating field at radial distanfe * Add field shell evaluation * Add enclosed mass computation * Add BORG2 import * Add BORG boxsize * Add BORG paths * Edit run * Add BORG2 overdensity field * Add bulk flow clauclation * Update README * Add new plots * Add nbs * Edit paper * Update plotting * Fix overlap paths to contain simname * Add normalization of positions * Add default paths to CSiBORG1 * Add overlap path simname * Fix little things * Add CSiBORG2 catalogue * Update README * Add import * Add TNG density field constructor * Add TNG density * Add draft of calculating BORG ACL * Fix bug * Add ACL of enclosed density * Add nmean acl * Add galaxy bias calculation * Add BORG acl notebook * Add enclosed mass calculation * Add TNG300-1 dir * Add TNG300 and BORG1 dir * Update nb
829 KiB
829 KiB
In [1]:
import numpy as np
import matplotlib.pyplot as plt
from h5py import File
from scipy.stats import spearmanr
import csiborgtools
%matplotlib inline
%load_ext autoreload
%autoreload 2
In [2]:
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
In [3]:
reader = csiborgtools.read.CSiBORG2Field(17417, "main")
In [4]:
density = reader.density_field("SPH", 1024)
In [5]:
def smoothen_field(field, smooth_scale, boxsize, threads=1, make_copy=False):
"""
Smooth a field with a Gaussian filter.
"""
W_k = SL.FT_filter(boxsize, smooth_scale, field.shape[0], "Gaussian",
threads)
if make_copy:
field = numpy.copy(field)
return SL.field_smoothing(field, W_k, threads)
In [6]:
slabA = density[512, ...]
density_smoothed = csiborgtools.field.smoothen_field(density, 2, 676.6, threads=4, make_copy=True)
slabB = density_smoothed[512, ...]
density_smoothed = csiborgtools.field.smoothen_field(density, 8, 676.6, threads=4, make_copy=True)
slabC = density_smoothed[512, ...]
In [7]:
np.savez("./smoothed_field.npz", smooth_0=slabA, smooth_2=slabB, smooth8=slabC)
In [12]:
plt.figure()
plt.imshow(np.log10(slabB))
plt.show()
In [ ]:
In [3]:
nsa_alfalfa = csiborgtools.SDSSxALFALFA()()
nsa = csiborgtools.SDSS()()
In [14]:
fval1_cb2, smooth_scales = csiborgtools.summary.read_interpolated_field(
nsa_alfalfa, "csiborg2_random", "density", "SPH", 1024, paths)
fval2_cb2, smooth_scales = csiborgtools.summary.read_interpolated_field(
nsa_alfalfa, "csiborg2_main", "density", "SPH", 1024, paths)
In [21]:
plt.figure()
plt.hist(np.log10(fval1_cb2[0, :, 2]), bins="auto", density=1, histtype="step",
label="Random")
plt.hist(np.log10(fval2_cb2[10, :, 2]), bins="auto", density=1, histtype="step",
label="CSiBORG")
# plt.yscale("log")
plt.legend()
plt.xlabel(r"$\log \rho ~ [h^2 M_\odot / \mathrm{kpc}^3]$")
plt.ylabel("Normalized counts")
plt.tight_layout()
plt.savefig("../plots/test_samples.png", dpi=450)
plt.show()
In [ ]:
In [ ]:
In [ ]:
In [27]:
fval_rand, smooth_scales = csiborgtools.summary.read_interpolated_field(survey, "csiborg2_random", "density", "SPH", 1024, paths)
In [51]:
survey.keys
Out[51]:
In [90]:
col = np.log10(survey["SERSIC_B300"])
In [91]:
fval.shape
Out[91]:
In [96]:
k = 3
n = 5
print(smooth_scales[k])
print("MAIN ", spearmanr(col, fval[n, :, k]))
print("RAND ", spearmanr(col, fval_rand[n, :, k]))
plt.figure()
plt.scatter(col, fval[n, :, k], s=1)
# plt.scatter(col, fval_rand[n, :, k], s=1)
plt.yscale("log")
plt.show()
In [ ]:
In [100]:
k = 3
y1 = np.mean(fval[:, :, k], axis=0)
y2 = np.mean(fval_rand[:, :, k], axis=0)
print("MAIN ", spearmanr(col, y1))
print("RAND ", spearmanr(col, y2))
plt.figure()
plt.scatter(col, y1, s=1)
plt.yscale("log")
plt.show()
In [ ]:
In [ ]:
In [10]:
survey.selection_mask.shape
Out[10]:
In [ ]:
paths.field_interpolated()
In [4]:
radvel_path = paths.field("radvel", "SPH", 1024, 16217, "csiborg2_main")
In [9]:
d = np.load(radvel_path)
In [8]:
!du -h /mnt/extraspace/rstiskalek/csiborg_postprocessing/environment/radvel_csiborg2_main_SPH_16217_1024.npy
In [5]:
# x1 = d["val"]
In [7]:
x2 = d["val"]
In [22]:
d["smooth_scales"]
Out[22]:
In [29]:
k = -1
m = np.isfinite(x1[:, k]) & np.isfinite(x2[:, k])
In [30]:
print(spearmanr(x1[m, k], x2[m, k]))
plt.figure()
plt.scatter(x1[m, k], x2[m, k], s=1)
plt.xscale("log")
plt.yscale("log")
plt.show()
In [13]:
Out[13]:
In [ ]:
In [9]:
x1.shape
Out[9]:
In [ ]:
In [ ]:
In [4]:
field.density_field("SPH", 1024)
Out[4]:
In [ ]:
In [206]:
mreader = csiborgtools.read.CSiBORG2MergerTreeReader(16517, "main")
In [238]:
cat["dist"][4]
Out[238]:
In [251]:
d = mreader.main_progenitor(3000)
In [252]:
np.max(d["MaxNextProgenitorMass"] / d["MainProgenitorMass"])
Out[252]:
In [253]:
plt.figure()
plt.plot(d["Redshift"], d["MainProgenitorMass"])
plt.plot(d["Redshift"], d["MaxNextProgenitorMass"])
plt.yscale("log")
plt.show()
In [ ]:
In [202]:
n = 0
main_progenitor = tree["TreeMainProgenitor"]
next_progenitor = tree["TreeNextProgenitor"]
snapnum = tree["SnapNum"]
for i in range(5):
print(i)
next_progenitor
# print(main_progenitor[n], snapnum[main_progenitor[n]])
# print(next_progenitor[n], snapnum[next_progenitor[n]])
print("")
n = main_progenitor[n]
In [ ]:
In [ ]:
In [ ]:
In [180]:
# z, y = mreader.fof_progenitor(30)
d = mreader.main_progenitor(30)
In [181]:
plt.figure()
plt.plot(d["Redshift"], d["MainProgenitorMass"], label="Main progenitor")
# plt.plot(z, y, label="FoF group")
plt.legend()
plt.yscale("log")
plt.show()
In [ ]:
In [164]:
plt.figure()
plt.plot(y)
plt.yscale("log")
plt.show()
In [ ]:
In [132]:
cat = csiborgtools.read.CSiBORG2Catalogue(16517, 99, "main")
In [136]:
cat["totmass"]
Out[136]:
In [ ]:
In [131]:
d1 = mreader.fof_progenitor(1)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
d1["Group_M_Crit200"]
In [129]:
plt.figure()
plt.plot(d1["Redshift"], d1["MainProgenitorMass"])
# plt.plot(z1, m1)
plt.yscale("log")
plt.show()
In [ ]:
In [ ]:
In [22]:
f = h5py.File(paths.trees(16517, "csiborg2_main"), 'r')
print(f.keys())
In [31]:
f["TreeHalos"].keys()
Out[31]:
In [35]:
offset = f["TreeTable/StartOffset"][:]
length = f["TreeTable/Length"][:]
groupnr = f["TreeHalos/GroupNr"][:]
snapnum = f["TreeHalos/SnapNum"][:]
treeid = f["TreeHalos/TreeID"][:]
treeid[mask][groupnr[mask] == 300000]
In [48]:
treeid = f["TreeHalos/TreeID"][:]
In [43]:
mask = snapnum==99
In [58]:
treeid[mask][groupnr[mask] == 300000]
Out[58]:
In [ ]:
In [41]:
cat
Out[41]:
In [39]:
for n in range(3):
i = offset[n]
j = i + length[n]
m = snapnum[i:j] == 99
In [24]:
f["TreeHalos/GroupNr"]
Out[24]:
In [ ]:
In [ ]:
In [136]:
f["TreeTable/StartOffset"][:]
Out[136]:
In [137]:
f["TreeTable/Length"][:]
Out[137]:
In [138]:
for key in f["TreeHalos"].keys():
print(key)
In [ ]:
In [150]:
cat["GroupContamination"]
Out[150]:
In [147]:
n = 0
tot = 0
while True:
print(n, snap[n])
if n == -1:
break
tot += m[n]
n = nexthalo[n]
In [141]:
cat["totmass"]
Out[141]:
In [145]:
tot * 1e10 / 2.9051551e+15
Out[145]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [118]:
f["TreeHalos/GroupNr"][:400]
Out[118]:
In [ ]:
In [108]:
x = f["TreeHalos/TreeMainProgenitor"][:73895]
s = f["TreeHalos/SnapNum"][:73895]
x
Out[108]:
In [102]:
y = f["TreeHalos/TreeFirstProgenitor"][:73895]
y
Out[102]:
In [104]:
np.where(x != y)
Out[104]:
In [ ]:
In [ ]:
In [62]:
cat["Group_M_Crit200"]
Out[62]:
In [50]:
cat["totmass"] * 1e-10
Out[50]:
In [75]:
np.where(f["TreeHalos"]["SnapNum"][:1000] == 98)
Out[75]:
In [77]:
f["TreeHalos"]["TreeFirstHaloInFOFgroup"][:1000][330]
Out[77]:
In [44]:
f["TreeHalos/SnapNum"][73895:73895+100]
Out[44]:
In [ ]:
In [ ]:
In [5]:
snap_final = csiborgtools.read.CSiBORG2Snapshot(1, 99, "varysmall")
snap_init = csiborgtools.read.CSiBORG2Snapshot(1, 0, "varysmall")
In [6]:
# print("Loading final")
# pid_final = snap_final.particle_ids()
# print("Loading init")
# pid_init = snap_init.particle_ids()
In [23]:
hid = 7
pos_final = snap_final.halo_coordinates(hid)
In [24]:
pos_init = snap_init.halo_coordinates(hid)
In [25]:
pos_final.shape
Out[25]:
In [27]:
plt.figure()
# plt.scatter(pos_init[:,0], pos_init[:, 1], s=0.1)
plt.scatter(pos_final[:,0], pos_final[:, 1], s=0.1)
plt.show()
In [46]:
cat = csiborgtools.read.CSiBORG2Catalogue(15617, 99, "main", bounds={"dist": (None, 120)})
In [47]:
x = cat["dist"]
y = cat["GroupContamination"]
In [48]:
plt.figure()
plt.scatter(x / 0.676, y, s=0.1)
plt.show()
In [ ]:
In [ ]:
In [ ]:
In [10]:
cat.keys()
Out[10]:
In [56]:
len(cat)
Out[56]:
In [55]:
cat["m200c"]
In [ ]:
In [46]:
cat["index"]
Out[46]:
In [43]:
cat._read_fof_catalogue("xx")
In [49]:
getattr(cat, "npart")
Out[49]:
In [ ]:
In [42]:
cat["totmass"] / cat["npart"]
Out[42]:
In [ ]:
In [ ]:
In [30]:
cat["cartesian_pos"]
Out[30]:
In [31]:
cat._read_fof_catalogue("x")
Out[31]:
In [ ]:
In [29]:
cat.cache_keys()
Out[29]:
In [37]:
x = np.arange(10)
In [41]:
np.vstack([x.reshape(-1, 1), x.reshape(-1, 1)]).shape
Out[41]:
In [45]:
np.hstack([x, x]).shape
Out[45]:
In [29]:
np.vstack([x, x]).shape
Out[29]:
In [11]:
x = snapshot.halo_coordinates(0)
In [10]:
x
Out[10]:
In [ ]:
In [ ]:
In [ ]:
In [23]:
x
Out[23]:
In [ ]:
In [10]:
snapshot.hid2offset
In [ ]:
In [16]:
d = {i: (j, k) for i, j, k in offset}
In [20]:
d[1]
Out[20]:
In [ ]:
In [10]:
ids = snapshot.particle_ids()
In [3]:
from h5py import File
with File("/mnt/extraspace/rstiskalek/csiborg1/chain_7516/snapshot_00946.hdf5", 'r') as f:
print(f.keys())
In [ ]:
In [9]:
ids
Out[9]:
In [ ]:
In [ ]:
In [27]:
d1["val"].shape
Out[27]:
In [28]:
d2["val"].shape
Out[28]:
In [ ]:
In [22]:
surv = csiborgtools.SDSSxALFALFA()(apply_selection=True)
In [25]:
surv.selection_mask.size
Out[25]:
In [1]:
x
In [8]:
d["val"].shape
Out[8]:
In [ ]:
In [43]:
paths.get_ics("quijote")
Out[43]:
In [78]:
paths.get_snapshots(1, "quijote")
Out[78]:
In [82]:
str("ICs").zfill(3)
Out[82]:
In [80]:
paths.snapshot(980, 7444, "csiborg")
Out[80]:
In [ ]:
In [ ]:
with h5py.File("/mnt/extraspace/rstiskalek/quijote/fiducial_processed/chain_0/fof_004.hdf5", 'r') as f:
print(f.keys())
In [5]:
pos0
Out[5]:
In [ ]:
In [ ]:
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
In [ ]:
In [ ]:
In [ ]:
Omega0 0.307000011205673
OmegaBaryon 0.0
OmegaLambda 0.693000018596649
In [26]:
box._omega_l
Out[26]:
In [20]:
box.Om0
Out[20]:
In [ ]:
In [18]:
box.box2vel(1)
Out[18]:
In [ ]:
2.654327164967911e+19
In [5]:
paths.get_ics("csiborg2_main")
Out[5]:
In [11]:
paths.get_snapshots(15517, "csiborg2_main")
Out[11]:
In [ ]:
In [9]:
!ls /mnt/extraspace/rstiskalek/csiborg2_main/chain_15517/output
In [ ]:
In [4]:
cat = csiborgtools.read.CSiBORGCatalogue(7444, paths, catalogue_name="halo_catalogue", halo_finder="FOF",
bounds={"dist": (0, 50)})
In [6]:
d = np.load(paths.field("density", "PCS", 512, 7444, False, None))
In [12]:
over = d / d.mean() - 1
In [16]:
import Pk_library as PKL
In [18]:
Pk = PKL.Pk(over, 677.6, 0, "PCS", 1, True)
# 3D P(k)
k = Pk.k3D
Pk0 = Pk.Pk[:,0] #monopole
Pk2 = Pk.Pk[:,1] #quadrupole
Pk4 = Pk.Pk[:,2] #hexadecapole
Pkphase = Pk.Pkphase #power spectrum of the phases
Nmodes = Pk.Nmodes3D
In [21]:
plt.figure()
plt.plot(k, Pk0, label='monopole')
plt.xscale('log')
plt.yscale('log')
plt.show()
In [15]:
plt.figure()
plt.imshow(np.log10(over[0, :, :] + 1))
plt.colorbar()
plt.show()
In [6]:
pos = cat["snapshot_final/pos"]
In [8]:
pos = pos[:]
In [ ]:
In [ ]:
In [7]:
totmass = numpy.sum(cat["snapshot_final/mass"][:])
In [10]:
totmass / (677.7 * 1000)**3 / 0.3
Out[10]:
In [ ]:
In [8]:
virgo = csiborgtools.virgo
print(virgo)
X = np.array([virgo["dist"], virgo["RA"], virgo["DEC"]]).reshape(-1, 3)
dist, indxs = cat.angular_neighbours(X, False, 20, radial_tolerance=5)
dist, indxs = dist[0], indxs[0]
In [7]:
dist
Out[7]:
In [308]:
k = np.argmax(cat["mtot"])
k = np.argsort(cat["mtot"])[::-1][8]
c = cat["cartesian_pos"][k]
print(np.log10(cat["mtot"][k]))
In [309]:
indx1 = cat.select_in_box(c, 20)
pos1 = cat["cartesian_pos"][indx1]
indx2 = pcat.select_in_box(c, 20)
pos2 = pcat["cartesian_pos"][indx2]
m1 = cat["mtot"][indx1]
m2 = pcat["summed_mass"][indx2]
In [311]:
plt.figure()
plt.scatter(pos1[:, 0], pos1[:, 1], c=np.log10(m1))
plt.colorbar()
plt.scatter(pos2[:, 0], pos2[:, 1], marker="x", c=np.log10(m2))
plt.show()
In [293]:
virgo = csiborgtools.virgo
print(virgo)
X = np.array([virgo["dist"], virgo["RA"], virgo["DEC"]]).reshape(-1, 3)
dist, indxs = cat.angular_neighbours(X, False, 20, radial_tolerance=5)
dist, indxs = dist[0], indxs[0]
In [294]:
print(cat["mtot"][indxs])
k = np.argmax(cat["mtot"][indxs])
kk = indxs[k]
dist[k], np.log10(cat["mtot"][indxs[k]]), cat["index"][indxs[k]]
In [ ]:
In [234]:
print(np.argsort(pcat["summed_mass"])[::-1][:10])
k = 46519
In [163]:
np.log10(pcat["summed_mass"][k]), pcat["dist"][k], pcat["is_main"][k], pcat["index"][k]
Out[163]:
In [235]:
data = merger_reader.walk_main_progenitor(20520136, 951, True)
In [236]:
# pos, mass, x = csiborgtools.read.track_halo_manually(cats, 21344979, maxdist=5, max_dlogm=1)
hist = csiborgtools.read.track_halo_manually(cats, 20520136, maxdist=0.25, max_dlogm=0.5)
In [237]:
hist
Out[237]:
In [238]:
plt.figure()
plt.scatter(hist["x"], hist["y"], c=hist["snapshot_index"])
plt.show()
plt.figure()
plt.plot(hist["snapshot_index"], hist["mass"])
# m = data["desc_snapshot_index"] > 0
# plt.plot(data["desc_snapshot_index"][m], data["desc_mass"][m])
plt.yscale("log")
plt.show()
In [222]:
plt.figure()
plt.scatter(pos[:, 0], pos[:, 1], c=np.log10(mass))
plt.colorbar()
plt.scatter(x[0], x[1], c="r", marker='x')
plt.show()
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [47]:
hist
Out[47]:
In [27]:
data
Out[27]:
In [28]:
mladen = np.genfromtxt("/mnt/extraspace/rstiskalek/CSiBORG/cleaned_mtree/ramses_out_7444/mergertree_00951_halo-21344979.txt", skip_header=1)
In [31]:
mladen
Out[31]:
In [ ]:
In [ ]:
In [18]:
plt.figure()
plt.plot(data["desc_snapshot_index"], data["desc_mass"])
m = mladen[:, 0] > 700
plt.plot(mladen[:,0][m], (mladen[:,3][m] - mladen[:, 5][m]) * 0.7)
plt.yscale("log")
plt.show()
In [ ]:
In [298]:
snaps = paths.get_snapshots(7468, "csiborg")
In [299]:
nsnaps = range(800, 944 + 1)
from tqdm import tqdm
cats = {}
for nsnap in tqdm(nsnaps):
cats[nsnap] = csiborgtools.read.CSiBORGPHEWCatalogue(
nsnap, 7468, paths, bounds={"dist": (None, 155.5), "is_main": True})
In [230]:
cats[944]["dist"][cats[944]["hid_to_array_index"][20467619]]
Out[230]:
In [454]:
# hid = cats[944]["index"][np.argmax(cats[944]["summed_mass"])]
hid = 20467619
In [455]:
hist = csiborgtools.read.track_halo_manually(cats, hid)
# x, y = csiborgtools.read.track_halo_manually(cats, hid)
In [456]:
plt.figure()
plt.scatter(hist["snapshot_index"], hist["mass"] / hist["mass"][0], c=hist["desc_dist"])
plt.colorbar()
# plt.yscale("log")
plt.show()
In [457]:
plt.figure()
plt.scatter(hist["x"], hist["y"], c=hist["snapshot_index"])
plt.colorbar()
plt.show()
In [458]:
plt.figure()
plt.scatter(hist["snapshot_index"], hist["desc_dist"])
plt.show()
In [459]:
x = np.arange(len(pos_history))
In [293]:
plt.figure()
plt.plot(dist_history)
plt.show()
In [276]:
plt.figure()
plt.scatter(pos_history[:, 0], pos_history[:, 1], c=x)
plt.colorbar()
plt.show()
plt.figure()
plt.plot(mass_history)
plt.show()
In [148]:
nsnap0 = 944
k = cats[nsnap0]["hid_to_array_index"][hid]
pos = cats[nsnap0]["cartesian_pos"][k]
In [166]:
nsnap = 939
cats[nsnap0]["dist"][k]
indxs = cats[nsnap].select_in_box(pos, 5)
nearby_pos = cats[nsnap]["cartesian_pos"][indxs]
nearby_mass = cats[nsnap]["summed_mass"][indxs]
In [167]:
plt.figure()
plt.scatter(nearby_pos[:, 0], nearby_pos[:, 1], c=np.log10(nearby_mass))
plt.colorbar()
plt.scatter(pos[0], pos[1], c="r", marker="x")
plt.xlim(pos[0] - 5, pos[0] + 5)
plt.show()
In [ ]:
In [ ]:
In [50]:
plt.figure()
plt.plot(mass_history)
plt.show()
In [51]:
plt.figure()
plt.scatter(dist, rank, c=rank)
plt.colorbar()
plt.show()
In [ ]:
In [147]:
dist
Out[147]:
In [ ]:
In [144]:
np.log10(dx)
Out[144]:
In [143]:
np.log10(mass)
Out[143]:
In [140]:
np.abs(np.log10(dx / mass))
Out[140]:
In [ ]:
In [107]:
plt.figure()
plt.scatter(dist, dm)
plt.show()
In [ ]:
In [ ]:
In [133]:
pcat = csiborgtools.read.CSiBORGPHEWCatalogue(
940, 7468, paths, bounds={"dist": (None, 155.5), "is_main": True})
In [134]:
k = np.argmax(pcat["summed_mass"])
In [135]:
# center = pcat["cartesian_pos"][k]
In [136]:
indxs = pcat.select_in_box(center, 10)
In [137]:
pos = pcat["cartesian_pos"][indxs]
mass = np.log10(pcat["summed_mass"][indxs])
In [138]:
plt.figure()
plt.scatter(pos[:, 0], pos[:, 1], c=mass)
plt.colorbar()
plt.scatter(center[0], center[1], c="r", marker="x")
plt.show()
In [55]:
pcat["is_main"].sum() / len(pcat)
Out[55]:
In [46]:
pcat.keys()
Out[46]:
In [42]:
x = pcat["mass_cl"]
In [43]:
y = pcat["summed_mass"]
In [44]:
plt.figure()
plt.scatter(x, y, s=1)
plt.xscale("log")
plt.yscale("log")
plt.show()
In [23]:
indxs = pcat.select_in_box([338.85, 338.85, 338.85], 40, False)
In [24]:
pos = pcat["cartesian_pos"][indxs]
# indxs
In [26]:
)
In [25]:
plt.figure()
plt.scatter(pos[:, 0], pos[:, 2])
plt.show()
In [ ]:
In [105]:
clumparr = reader.read_phew_clumps(951, 7444, True)
# clindex = clumparr['index']
# clindex_to_array_index = {clindex[i]: i for i in range(clindex.size)}
In [ ]:
In [ ]:
In [103]:
x, y = reader.find_parents(clumparr, verbose=True)
In [98]:
m = clumparr["index"] == clumparr["parent"]
plt.figure()
plt.scatter(clumparr["mass_cl"][m], y[m], s=1)
plt.xscale('log')
plt.yscale('log')
plt.show()
In [ ]:
In [ ]:
In [55]:
clindex = clumparr["index"]
parindex = clumparr["parent"]
clindex_to_array_index = {clindex[i]: i for i in range(clindex.size)}
In [70]:
i = 2333
cl = clindex[i]
par = parindex[i]
print(cl, par)
while cl != par:
print(cl, par)
element = clindex_to_array_index[par]
cl = clindex[element]
par = parindex[element]
cl, par
Out[70]:
In [75]:
clumparr[1338]
Out[75]:
In [74]:
clindex_to_array_index[57675]
Out[74]:
In [57]:
cl, par
Out[57]:
In [49]:
clumparr[92]
Out[49]:
In [53]:
clindex_to_array_index[244]
Out[53]:
In [54]:
clumparr[66]
Out[54]:
In [44]:
clumparr[]
Out[44]:
In [47]:
clindex_to_array_index[16]
Out[47]:
In [48]:
clumparr[13]
Out[48]:
In [ ]:
In [26]:
x[0] == clumparr["index"]
Out[26]:
In [31]:
m = clumparr["index"] == clumparr["parent"]
plt.figure()
plt.scatter(clumparr["mass_cl"][~m], y[~m], s=0.5)
plt.axline((1e12, 1e12), slope=1, color="black", linestyle="--")
plt.xscale("log")
plt.yscale("log")
plt.show()
In [71]:
clindex_to_array_index = {clindex[i]: i for i in range(clindex.size)}
In [ ]:
a
In [110]:
clumparr2 = reader.read_phew_clumps(951, 7444, True)
In [109]:
m.sum() / m.size
Out[109]:
In [107]:
plt.figure()
m = clumparr2["index"] == clumparr2["parent"]
# plt.scatter(clumparr2["mass_cl"][m], clumparr2["summed_mass"][m], s=1)
plt.scatter(clumparr2["mass_cl"][~m], clumparr2["summed_mass"][~m], s=1)
plt.axline((1e12, 1e12), slope=1, color="black", linestyle="--")
plt.xscale("log")
plt.yscale("log")
plt.show()
In [ ]:
In [ ]:
In [83]:
clindex
Out[83]:
In [86]:
par = 21824378
%timeit clindex_to_array_index[par]
In [85]:
clindex_to_array_index[par]
Out[85]:
In [87]:
%timeit numpy.where(clindex == par)[0][0]
In [ ]:
In [ ]:
In [18]:
numpy.where(clumparr["index"] == 3)[0][0]
Out[18]:
In [25]:
def is_sorted_np(arr):
return np.all(arr[:-1] <= arr[1:])
In [29]:
from numba import jit
In [47]:
def is_sorted(arr):
for i in range(1, len(arr)):
if arr[i-1] > arr[i]:
return False
return True
@jit(nopython=True, boundscheck=False, fastmath=True)
def is_sorted2(arr):
for i in range(1, len(arr)):
if arr[i-1] > arr[i]:
return False
return True
In [49]:
is_sorted2(clumparr["index"])
Out[49]:
In [ ]:
In [28]:
%timeit is_sorted_np(clumparr["index"])
In [20]:
ks = np.argsort(clumparr["index"])
In [24]:
np.alltrue(clumparr["index"][ks] == clumparr["index"])
Out[24]:
In [ ]:
In [ ]:
In [10]:
reader.find_parents(clumparr, verbose=True)
In [ ]: