-
Notifications
You must be signed in to change notification settings - Fork 0
/
Isaacs_approximation.py
132 lines (99 loc) · 3.4 KB
/
Isaacs_approximation.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
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 22 11:42:59 2023
@author: Admin
"""
import pandas as pd
from profiley.nfw import TNFW, NFW
import matplotlib.pyplot as plt
from colossus.halo import concentration, profile_nfw
from colossus.cosmology import cosmology
import numpy as np
from astropy.table import Table
from scipy.interpolate import interp1d
from scipy.optimize import curve_fit
from subhalo_profile import make_profile
import math
bin='0306'
if bin=='0609':
lowlim=0.6
highlim=0.9
elif bin=='0306':
lowlim=0.3
highlim=0.6
elif bin=='0103':
lowlim=0.1
highlim=0.3
lenses = Table.read("./data/redmapper_mnc_allz.fits")
data_mask = (
(lenses["R"] >= lowlim)
& (lenses["R"] < highlim)
& (lenses["PMem"] > 0.8)
# & (lenses["zspec"] > -1)
)
lenses = lenses[data_mask]
z=np.mean(lenses['z_any'])
print(z)
# z=np.mean(lenses['zspec'])
def subhalo_profile(r,mass,tau,A):
# def subhalo_profile(r,mass, A):
# print(mass)
# print(tau)
# print(z)
# print(A)
# tau=200
mass=math.pow(10, mass)
concentration_model="duffy08"
c=concentration.concentration(
M=mass, mdef="200m", z=z, model=concentration_model
)
# c=4.67*(mass/math.pow(10, 14))**(-0.11)
eta=2
tnfw = TNFW(mass, c, z, tau, eta)
# R = np.linspace(0.01, 1.5, 75)
dSigma=np.squeeze(tnfw.projected_excess(r))/1000000
# dSigma=nfw.projected_excess(R)
halo_table = np.genfromtxt(f'{bin}(Mh70).txt', delimiter='\t', usecols=(0, 1), dtype=float)
halo_r=halo_table[:,0]/1000
halo_ds=halo_table[:,1]
f = interp1d(halo_r, halo_ds, kind='cubic')
halo_dSigma=f(r)*A
summed_halo=np.add(dSigma,halo_dSigma)/1000000
return summed_halo
# Read the CSV file
# df = pd.read_csv(f'D:/GitHub/summer-research/output-roman(correct)/roman_esd_ShapePipe_redmapper_clusterDist{lowlim}_randomsTrue_1.csv')
df = pd.read_csv(f'D:/roman_esd_ShapePipe_redmapper_clusterDist{lowlim}_randomsTrue_1.csv')
# df=pd.read_csv(f'D:/GitHub/summer-research/output/{bin}.txt',
# delim_whitespace = True,
# names = ['rp','ds','ds_err'],
# comment = '#')
# Save the "ds" and "rp" columns as variables
ds = df['ds']
rp = df['rp']
ds_err=df['ds_err']
init=[12, 1, 1]
param_bounds=([10, 0,-np.inf], [np.inf, np.inf, np.inf])
popt, pcov = curve_fit(subhalo_profile, rp, ds, p0=init, bounds=param_bounds, sigma=ds_err, absolute_sigma=True,
method='dogbox')
# print(pcov)
# print(popt)
# Extract the optimized parameters
# lens_mass, lens_tau , lens_z, param_A = popt
lens_mass, lens_tau, param_A= popt
lens_z=z
fit = subhalo_profile(rp, lens_mass, lens_tau, param_A)
r_full,ds_halo, ds_sub=make_profile(math.pow(10,lens_mass), lens_z, lens_tau, param_A, B=1, distbin=bin, plot=False)
# r_full,ds_full=make_profile(1e12, 0.35, 35, 0.6, distbin=bin, plot=False)
# plt.plot(rp, ds, 'bo', label='Isaac Data')
# plt.plot(rp, fit, 'r-', label='interp Curve')
plt.plot(r_full, ds_halo+ds_sub, 'g-', label='fitted Curve')
plt.errorbar(rp, ds, ds_err, fmt='o',label='dsigma Data')
plt.plot(r_full, ds_halo, '--', label='halo')
plt.plot(r_full, ds_sub, '--', label='subhalo')
plt.xlabel('R (Mpc)')
plt.ylabel('M/pc^2')
plt.grid()
plt.ylim(-40,120)
plt.title(f'{bin} lens log(mass): {lens_mass:.2f}, Z: {lens_z:.2}, tau: {lens_tau:.2f}, A: {param_A:.2}')
plt.legend()
plt.show()