-
Notifications
You must be signed in to change notification settings - Fork 0
/
subhalo_profile.py
267 lines (195 loc) · 9.06 KB
/
subhalo_profile.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 15 12:26:08 2023
@author: Admin
"""
import numpy as np
from profiley.nfw import TNFW, NFW
import matplotlib.pyplot as plt
from colossus.halo import concentration, profile_nfw
from colossus.cosmology import cosmology
import math
import pandas as pd
import random
def make_NFW_stars(mass, redshift, A, stellar_mass, distbin, plot):
params = {"flat": True, "H0": 100, "Om0": 0.3, "Ob0": 0.049, "sigma8": 0.81, "ns": 0.95}
cosmology.addCosmology("737", params)
cosmo = cosmology.setCosmology("737")
lens_z = redshift
concentration_model="duffy08"
c=concentration.concentration(
M=mass, mdef="200m", z=lens_z, model=concentration_model
)
# c=4.67*(mass/math.pow(10, 14))**(-0.11)
# halo_profile = profile_nfw.NFWProfile(M=mass, c=c, z=lens_z, mdef="200m")
subhalo_profile = NFW(mass, c, lens_z)
# eta=2
# tnfw = TNFW(mass, c, lens_z, tau, eta)
R = np.linspace(0.01, 1.5, 75)
# dSigma=np.squeeze(tnfw.projected_excess(r))/1000000
# dSigma=subhalo_profile.deltaSigma(R*1000)
dSigma= np.squeeze(subhalo_profile.projected_excess(R))/1000000
# R = np.linspace(0.01, 1.5, 75)
# dSigma=np.squeeze(tnfw.projected_excess(R))/1000000
starSigma=stellar_mass/(math.pi*R**2)/1000000
# dSigma=nfw.projected_excess(R)
halo_dSigma = np.genfromtxt(f'{distbin}(Mh70).txt', delimiter='\t', usecols=(1))*A
summed_halo=np.add(dSigma,halo_dSigma[::-1])
summed_halo=np.add(summed_halo,starSigma)/1000000
# summed_halo=np.mean([dSigma, halo_dSigma[::-1]], axis=0)
# summed_halo=np.subtract(dSigma,halo_dSigma[::-1])
host_halo=halo_dSigma[::-1]/1000000
subhalo=dSigma/1000000
star_halo=starSigma/1000000
if plot:
plt.plot(R, summed_halo, label='combined')
plt.plot(R,host_halo, label='halo offset', linestyle='--')
# plt.plot(R,offset_halo/1000000, label='excess', linestyle='--')
# plt.plot(R,offset_halo2/1000000, label='sigma', linestyle='--')
# plt.plot(R,offset_halo3/1000000, label='sigma(<R)', linestyle='--')
plt.plot(R,subhalo,label='subhalo tNFW', linestyle='--')
plt.plot(R,star_halo,label='stars', linestyle='--')
plt.ylim(-40,120)
plt.title(f'lens mass: {mass:.2e}, Z: {lens_z}, A: {A:.2},stellar mass: {stellar_mass:.2e}')
plt.legend()
plt.grid()
# print(summed_halo[39])
# print(np.min(summed_halo))
return R, host_halo, subhalo, star_halo
def make_NFW(mass, redshift, A, distbin, plot):
params = {"flat": True, "H0": 100, "Om0": 0.3, "Ob0": 0.049, "sigma8": 0.81, "ns": 0.95}
cosmology.addCosmology("737", params)
cosmo = cosmology.setCosmology("737")
lens_z = redshift
concentration_model="duffy08"
c=concentration.concentration(
M=mass, mdef="200m", z=lens_z, model=concentration_model
)
# c=4.67*(mass/math.pow(10, 14))**(-0.11)
# halo_profile = profile_nfw.NFWProfile(M=mass, c=c, z=lens_z, mdef="200m")
subhalo_profile = profile_nfw.NFWProfile(M=mass, c=c, z=lens_z, mdef="200m")
# tnfw = TNFW(mass, c, z, tau, eta)
R = np.linspace(0.01, 1.5, 75)
# dSigma=np.squeeze(tnfw.projected_excess(r))/1000000
dSigma=subhalo_profile.deltaSigma(R*1000)
# R = np.linspace(0.01, 1.5, 75)
# dSigma=np.squeeze(tnfw.projected_excess(R))/1000000*B
# star=math.pow(10, B)/R
# dSigma=nfw.projected_excess(R)
halo_dSigma = np.genfromtxt(f'{distbin}(Mh70).txt', delimiter='\t', usecols=(1))*A
summed_halo=np.add(dSigma,halo_dSigma[::-1])/1000000
# summed_halo=np.add(summed_halo,star)
# summed_halo=np.mean([dSigma, halo_dSigma[::-1]], axis=0)
# summed_halo=np.subtract(dSigma,halo_dSigma[::-1])
host_halo=halo_dSigma[::-1]/1000000
subhalo=dSigma/1000000
# star_halo=star/1000000
if plot:
plt.plot(R, summed_halo, label='combined')
plt.plot(R,host_halo, label='halo offset', linestyle='--')
# plt.plot(R,offset_halo/1000000, label='excess', linestyle='--')
# plt.plot(R,offset_halo2/1000000, label='sigma', linestyle='--')
# plt.plot(R,offset_halo3/1000000, label='sigma(<R)', linestyle='--')
plt.plot(R,subhalo,label='subhalo NFW', linestyle='--')
# plt.plot(R,star_halo,label='stars', linestyle='--')
plt.ylim(-40,120)
plt.title(f'lens mass: {mass:.2e}, Z: {lens_z}, A: {A:.2}')
plt.legend()
plt.grid()
# print(summed_halo[39])
# print(np.min(summed_halo))
return R, host_halo, subhalo
def make_profile(mass, redshift, tau, A, B, distbin, plot):
params = {"flat": True, "H0": 100, "Om0": 0.3, "Ob0": 0.049, "sigma8": 0.81, "ns": 0.95}
cosmology.addCosmology("737", params)
cosmo = cosmology.setCosmology("737")
z_array=[0.012, 0.05, 0.043, 0.034, 0.015, 0.008, 0.08, 0.017, 0.014]
# lens_z = random.choice(z_array)
lens_z = redshift
mass_array=[1.5e12, 1.2e12, 5e10, 6.6e12, 1e11, 1.2e11, 1.1e11, 4e10, 0.9e11, 2e12]
# mass = random.choice(mass_array)
concentration_model="duffy08"
c=concentration.concentration(
M=mass, mdef="200m", z=lens_z, model=concentration_model
)
# c=4.67*(mass/math.pow(10, 14))**(-0.11)
# halo_profile = profile_nfw.NFWProfile(M=mass, c=c, z=lens_z, mdef="200m")
# halo_profile = NFW(mass,c,lens_z)
# scale_radius = halo_profile.getParameterArray()[1]/1000
# trunc_array=np.linspace(0.01, 0.36, 10+1)
# trunc_radius=random.choice(trunc_array)
# trunc_radius=0.175
# tau=trunc_radius/scale_radius
# mass=math.pow(10,mass)
# print(mass)
eta=2
tnfw = TNFW(mass, c, lens_z, tau, eta)
R = np.linspace(0.01, 1.5, 75)
dSigma=np.squeeze(tnfw.projected_excess(R))/1000000*B
# offset_halo=np.squeeze(halo_profile.offset_projected_excess(R, 0.6))/1000000
# offset_halo2=np.squeeze(halo_profile.offset_projected(R, 0.6))/1000000
# offset_halo3=np.squeeze(halo_profile.offset_projected_cumulative(R, 0.6))/1000000
# dSigma=nfw.projected_excess(R)
halo_dSigma = np.genfromtxt(f'{distbin}(Mh70).txt', delimiter='\t', usecols=(1))*A
summed_halo=np.add(dSigma,halo_dSigma[::-1])/1000000
# summed_halo=np.mean([dSigma, halo_dSigma[::-1]], axis=0)
# summed_halo=np.subtract(dSigma,halo_dSigma[::-1])
host_halo=halo_dSigma[::-1]/1000000
subhalo=dSigma/1000000
if plot:
plt.plot(R, summed_halo, label='combined')
plt.plot(R,host_halo, label='halo', linestyle='--')
# plt.plot(R,offset_halo/1000000, label='excess', linestyle='--')
# plt.plot(R,offset_halo2/1000000, label='sigma', linestyle='--')
# plt.plot(R,offset_halo3/1000000, label='sigma(<R)', linestyle='--')
plt.plot(R,subhalo,label='subhalo', linestyle='--')
plt.ylim(-40,120)
plt.title(f'lens mass: {mass:.2e}, Z: {lens_z}, Rt/Rs: {tau:.2}, A: {A:.2}, B:{B:.2}')
plt.legend()
plt.grid()
# print(summed_halo[39])
# print(np.min(summed_halo))
return R, host_halo, subhalo
if __name__ == '__main__':
# rp,host,sub=make_profile(math.pow(10,12.74), 0.23, math.pow(10,3.48), 0.81 , float(1), '0609', True)
# fig, ax = plt.subplots()
# taus=[0.2, 0.4, 0.8, 1.2, 2, 3, 5, 10]
# df = pd.DataFrame()
# df['Rp']=np.linspace(0.01, 1.5, 75)
# for tau in taus:
# rp,host,sub=make_profile(1e12, 0.31, float(tau), 1 , float(1), '0306', False)
# ax.plot(rp,host+sub)
# # plt.ylim(-10,100)
# # plt.xlim(0,0.4)
# column_name = f'column_{tau}'
# df[column_name] = host+sub
# concentration_model="duffy08"
# c=concentration.concentration(
# M=1e12, mdef="200m", z=0.31, model=concentration_model
# )
# subhalo_profile = NFW(1e12, c, 0.31)
# # eta=2
# # tnfw = TNFW(mass, c, lens_z, tau, eta)
# R = np.linspace(0.01, 1.5, 75)
# # dSigma=np.squeeze(tnfw.projected_excess(r))/1000000
# # dSigma=subhalo_profile.deltaSigma(R*1000)
# dSigma= np.squeeze(subhalo_profile.projected_excess(R))/1000000
# # dSigma=nfw.projected_excess(R)
# halo_dSigma = np.genfromtxt('0306(Mh70).txt', delimiter='\t', usecols=(1))
# summed_halo=np.add(dSigma,halo_dSigma[::-1])/1000000
# ax.plot(R, summed_halo, label='nfw', color='red')
# ax.legend()
# plt.grid()
# plt.show()
# df['nfw'] = summed_halo
# csv_filename = 'tauandprofile.csv'
# df.to_csv(csv_filename, index=False)
# fig, ax = plt.subplots()
# for mass in np.arange(11.5,12.2,0.1):
# rp,host,sub=make_profile(math.pow(10,mass), 0.31, float(100), 0.81 , float(1), '0306', False)
# ax.plot(rp,host+sub,label=f'{mass}')
# plt.ylim(-10,100)
# # plt.xlim(0,0.4)
# ax.legend()
# plt.grid()
rp,host,sub, star=make_NFW_stars(1e12, 0.31, float(1), 1e12, '0306', True)