Upload example_code_loadingTNG.py
#2
by
ChristineYe8
- opened
- example_code_loadingTNG.py +63 -0
example_code_loadingTNG.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# illustrative script on how to use the GRIZY color data file. and loading TNG data. The links do not work.
|
| 2 |
+
|
| 3 |
+
import illustris_python as il
|
| 4 |
+
import asdf
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# loading TNG catalog data
|
| 8 |
+
basePath = "./TNG300-1/output"
|
| 9 |
+
subhalos = il.groupcat.loadSubhalos(basePath, 55)
|
| 10 |
+
halos = il.groupcat.loadHalos(basePath, 55)
|
| 11 |
+
|
| 12 |
+
dmoPath = "./TNG300-1-Dark/output"
|
| 13 |
+
halos_dmo = il.groupcat.loadHalos(dmoPath, 55)
|
| 14 |
+
subhalos_dmo = il.groupcat.loadSubhalos(dmoPath, 55)
|
| 15 |
+
fp_matching = np.load("./halo_matching_055_addtree.npz")['indices_fp']
|
| 16 |
+
dmo_matching = np.load("./halo_matching_055_addtree.npz")['indices_dmo']
|
| 17 |
+
|
| 18 |
+
# loading the GRIZY photometry data that we generated following section 2.2
|
| 19 |
+
f = asdf.open("./HYDRO-TNG300-1/photo_bands_55_DESI.asdf")
|
| 20 |
+
borydata = f['data']
|
| 21 |
+
grizy = borydata['grizy']
|
| 22 |
+
sh_index = borydata['SubhaloIndex']
|
| 23 |
+
mstar = borydata['SubhaloMstar']
|
| 24 |
+
|
| 25 |
+
# generating DESI like LRGs using the colors and the TNG halo and subhalo catalogs
|
| 26 |
+
def desi_lrg(grizy, sh_index, mag_shift = -0.4):
|
| 27 |
+
cg, cr, ci, cz, cy = grizy.T
|
| 28 |
+
masks = (cr - cz > (cz + mag_shift - 16.83) * 0.45) & (cr - cz > (cz + mag_shift - 13.80) * 0.19)
|
| 29 |
+
print("total number of subhalos", len(sh_index), "number of desi lrgs", len(sh_index[masks]))
|
| 30 |
+
return sh_index[masks]
|
| 31 |
+
|
| 32 |
+
# getting LRG indices in the catalog
|
| 33 |
+
magshift = -0.4
|
| 34 |
+
desi_lrg_indices_doubleslide = desi_lrg(grizy, sh_index, magshift) # these are subhalo indices in fp
|
| 35 |
+
|
| 36 |
+
# getting central and satellite indices
|
| 37 |
+
subhalo_grnr = subhalos['SubhaloGrNr']
|
| 38 |
+
_, central_inds = np.unique(subhalo_grnr, return_index=True)
|
| 39 |
+
lrg_indices_central_doubleslide = np.intersect1d(central_inds, desi_lrg_indices_doubleslide)
|
| 40 |
+
lrg_indices_satellites_doubleslide \
|
| 41 |
+
= desi_lrg_indices_doubleslide[~np.in1d(desi_lrg_indices_doubleslide, lrg_indices_central_doubleslide)]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# similarly to select ELG indices in the subhalo catalog we provide the following script
|
| 46 |
+
def desi_elg(grizy, sh_index, mag_shift = 0.0):
|
| 47 |
+
|
| 48 |
+
# add noise
|
| 49 |
+
maglimits = np.array([24, 23.4, 22.5])
|
| 50 |
+
cg = get_scatter(grizy[:,0], maglimits[0])+mag_shift
|
| 51 |
+
cr = get_scatter(grizy[:,1], maglimits[1])+mag_shift
|
| 52 |
+
ci = grizy[:,2]+mag_shift
|
| 53 |
+
cz = get_scatter(grizy[:,3], maglimits[2])+mag_shift
|
| 54 |
+
cy = grizy[:,4]+mag_shift
|
| 55 |
+
|
| 56 |
+
masks = (cg < 23.6) & (cg > 20) & (cr - cz > 0.3) & (cr - cz < 1.6) \
|
| 57 |
+
* (cg - cr < 1.15*(cr - cz) - 0.15) & (cg - cr < -1.2*(cr - cz) + 1.6) \
|
| 58 |
+
* (cg < maglimits[0]) & (cr < maglimits[1]) & (cz < maglimits[2])
|
| 59 |
+
print("total number of subhalos", len(sh_index), "number of desi elgs", len(sh_index[masks]))
|
| 60 |
+
return sh_index[masks]
|
| 61 |
+
|
| 62 |
+
magshift = 0.6
|
| 63 |
+
desi_elg_indices = desi_elg(grizy, sh_index, magshift)
|