-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_halos_with_stars.py
96 lines (76 loc) · 2.7 KB
/
find_halos_with_stars.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import matplotlib
matplotlib.use('Agg')
import tangos
import tangos_properties_tremmel
import numpy as np
import pylab as plt
import sys
import h5py as h5
#in romulusC
#12 = 636, z = 3.0, t = 2.15 Gyr
#16 = 960, z = 2.03, t = 3.24 Gyr
#23 = 1536, z = 1.19, t = 5.18 Gyr
#49 - = 3035, z = 0.3
#56 = 3360, z = 0.2
#61 = 3697, z = 0.1
#71 - z = 0
#in romulus25
#104 = 6069, z = 0.31
#110 = 6656, z = 0.21
#116 = 7394, z = 0.1
#note: if tangos doesn't load use miniconda python
def find_halos_with_stars(timestep, output):
halos = tangos.get_simulation("h1.cosmo50").timesteps[timestep].halos
#halos = tangos.get_simulation("cosmo25").timesteps[110].halos
halo_id = []
Rvir = []
dist_to_cluster = []
Mvir = []
Mstar = []
Mgas = []
MColdGas = []
MHIGas = []
Rvir = []
R200 = []
center = []
Contam = []
cluster_center = halos[0]['shrink_center']
for i in range(len(halos[:1000])):
halo = halos[i]
mstar = halo['Mstar']
mgas = halo['Mgas']
if i%50 == 0:
print(i)
if mstar > 1e8:
print(i, mstar/1e12)
halo_id.append(i)
Contam.append(halo['contamination_fraction'])
Rvir.append(halo['max_radius'])
r200 = halo.calculate('radius(200)')
R200.append(r200)
center.append(halo['shrink_center'])
dist_to_cluster.append(np.linalg.norm(np.subtract(halo['shrink_center'], cluster_center)))
Mvir.append(halo['Mvir'])
Mstar.append(mstar)
Mgas.append(mgas)
MColdGas.append(halo['MColdGas'])
MHIGas.append(halo['MHIGas'])
h5file = h5.File('/nobackup/ibutsky/data/romulusC_halo_data_%i'%(output), 'w')
h5file.create_dataset('contamination', data = np.array(Contam))
h5file.create_dataset('r200', data = np.array(R200))
h5file.create_dataset('halo_id', data = np.array(halo_id))
h5file.create_dataset('rvir', data = np.array(Rvir))
h5file.create_dataset('mvir', data = np.array(Mvir))
h5file.create_dataset('mstar', data = np.array(Mstar))
h5file.create_dataset('mgas', data = np.array(Mgas))
h5file.create_dataset('mcoldgas', data = np.array(MColdGas))
h5file.create_dataset('mhigas', data = np.array(MHIGas))
h5file.create_dataset('center', data = np.array(center))
h5file.create_dataset('dist_to_cluster', data = np.array(dist_to_cluster))
h5file.flush()
timestep_list = [12, 13, 14, 15, 16]
output_list = [636, 672, 768, 864, 960]
timestep_list = [23]#, 56, 61]
output_list = [1536]#, 3360, 3697]
for timestep, output in zip(timestep_list, output_list):
find_halos_with_stars(timestep, output)