-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzwcl2341_plots.py
283 lines (177 loc) · 8.5 KB
/
zwcl2341_plots.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/bin/env python
from astroquery.sdss import SDSS
from astropy import coordinates as coords
import matplotlib.pyplot as plt
from astropy.coordinates import Angle
import numpy as np
from astropy.stats import biweight_scale
from astropy.io import ascii
from astropy import units as u
from astropy.coordinates import SkyCoord
from matplotlib.pyplot import show, plot, draw
from multiprocessing import Process
from scipy.constants import pi
import scipy.constants as constants
import statistics as stats
import astropy.cosmology as cp
import sys
from astropy.io import fits
from matplotlib.patches import Circle
import pandas as pd
import csv
import astropy.cosmology as cp
def zwcl_galaxy_distribution(galaxy_ra,galaxy_dec,zsp,cluster_centre,R_200):
def histogram(sample,bins,color):
n, bins, patches = plt.hist(sample, bins=bins, color=color, alpha=0.1, rwidth=0.85)
cluster_z=bins[np.argmax(n)]
return cluster_z
# pos = coords.SkyCoord('23h43m39.700s +0d19m51.000s', frame='icrs')
# xid = SDSS.query_region(pos, radius='1deg',spectro=True,data_release=17,photoobj_fields=['objid','ra','dec','u','g','r','i'],specobj_fields=['z','class'])
#xid = SDSS.query_sql(query)
#xid.colnames
redshift=np.array(zsp)[(zsp >= 0.26) & (zsp <= 0.29)]
galaxy_ra=np.array(galaxy_ra)[(zsp >= 0.26) & (zsp <= 0.29)]
galaxy_dec=np.array(galaxy_dec)[(zsp >= 0.26) & (zsp <= 0.29)]
cluster_z=histogram(redshift,500,'#0504aa')
cluster_z_n=histogram(redshift,100,'#0504aa')
cluster_z_median= np.median(redshift)
print('cluster z 500 bin size:',cluster_z)
print('cluster z 100 bin size:',cluster_z_n)
print('cluster z median:',cluster_z_median)
print('total number of galaxies in SDSS is',len(redshift))
print('min redshift in SDSS is',min(redshift))
print('max redshift in SDSS is',max(redshift))
print('RA and DEC of galaxies in redshift range:',len(galaxy_ra))
ra_radian = np.array(galaxy_ra)*np.pi/180
dec_radian = np.array(galaxy_dec)*np.pi/180
h=0.7
H0=h*100
cosmo = cp.FlatLambdaCDM(H0=h*100, Om0=0.30)
sc = SkyCoord(ra_radian, dec_radian, unit='rad', representation_type='unitspherical')
cartesian=sc.cartesian
x_coord=(np.cos(dec_radian) * np.cos(ra_radian))
y_coord=(np.cos(dec_radian) * np.sin(ra_radian))
z_coord=(np.sin(dec_radian))
z_filter=np.array(redshift)
cluster_centre_ra_radian=cluster_centre.ra.radian
cluster_centre_dec_radian=cluster_centre.dec.radian
cluster_centre=[cluster_centre.ra.value,cluster_centre.dec.value]
sc_cluster_centre= SkyCoord(cluster_centre_ra_radian, cluster_centre_dec_radian, unit='rad', representation_type='unitspherical')
cartesian_cluster_centre=sc_cluster_centre.cartesian
cluster_centre_x=cartesian_cluster_centre.x.value
cluster_centre_y=cartesian_cluster_centre.y.value
cluster_centre_z=cartesian_cluster_centre.z.value
comoving_centre_x=cosmo.comoving_distance((cluster_z_median)*cluster_centre_x).value
comoving_centre_y=cosmo.comoving_distance((cluster_z_median)*cluster_centre_y).value
comoving_centre_z=cosmo.comoving_distance((cluster_z_median)*cluster_centre_z).value
# reference to centre
comoving_x=((cosmo.comoving_distance(z_filter)*x_coord).value)
comoving_y=((cosmo.comoving_distance(z_filter)*y_coord).value)
comoving_z =((cosmo.comoving_distance(z_filter)*z_coord).value)
# R_200= 0.1388
fig1 = plt.figure()
fig2 = plt.figure()
fig3 = plt.figure()
ay1 = fig1.add_subplot(1,1,1, aspect='auto',projection='3d')
ay2 = fig2.add_subplot(1,1,1, aspect='equal')
ay3 = fig3.add_subplot(1,1,1, aspect='equal')
# 2D physical coordinates
ay1.scatter(comoving_x, comoving_y, comoving_z, color='black', alpha=0.5)
ay1.set_xlabel("X in Mpc")
ay1.set_ylabel("Y in Mpc")
ay1.set_zlabel("Z in Mpc")
ay1.set_title("3-D distribution of galaxies in a 1.5 deg radius centered on Zwcl 2341")
ay2.scatter(comoving_y, comoving_z,color='black', alpha=0.5)
ay2.set_xlabel("Y in Mpc")
ay2.set_ylabel("Z in Mpc")
circle=plt.Circle((comoving_centre_y, comoving_centre_z), R_200, edgecolor= 'blue',
facecolor='None', linewidth=2, alpha=1 ,ls = 'dashed') #, )
ay2.add_patch(circle)
ay2.text(0,0, "R_200", ha="left", va="top",fontsize=10)
fig2.savefig("Y_Z_Mpc")
print(comoving_centre_y,comoving_centre_z)
R_200= 0.103
# 2D angular coordinates
ay3.scatter(galaxy_ra, galaxy_dec,color='black', alpha=0.5)
ay3.set_xlim(min(galaxy_ra),max(galaxy_ra))
ay3.set_ylim(min(galaxy_dec),max(galaxy_dec))
ay3.set_xlabel("RA in deg")
ay3.set_ylabel("DEC in deg")
ay3.set_title("1.5 deg SDSS DR17 galaxies of Zwcl 2341 (Shishir catalogue)")
circle=plt.Circle((cluster_centre[0], cluster_centre[1]), R_200, edgecolor= 'blue',
facecolor='None', linewidth=2, alpha=1 ,ls = 'dashed') #, )
ay3.add_patch(circle)
ay3.text(0,0, "R_200", ha="left", va="top",fontsize=10)
fig3.savefig("Y_Z_Mpc")
plt.show()
return(galaxy_ra,galaxy_dec,redshift)
def velocity_dispersion(galaxy_ra,galaxy_dec,zsp,cluster_centre,R_200):
redshift=np.array(zsp)[(zsp >= 0.26) & (zsp <= 0.29)]
galaxy_ra=np.array(galaxy_ra)[(zsp >= 0.26) & (zsp <= 0.29)]
galaxy_dec=np.array(galaxy_dec)[(zsp >= 0.26) & (zsp <= 0.29)]
def histogram(sample,bins,color):
n, bins, patches = plt.hist(sample, bins=bins, color=color, alpha=0.1, rwidth=0.85)
cluster_z=bins[np.argmax(n)]
return cluster_z
cluster_centre_ra_radian=cluster_centre.ra.radian
cluster_centre_dec_radian=cluster_centre.dec.radian
cluster_centre=[cluster_centre.ra.value,cluster_centre.dec.value]
ra_5Mpc_circle=[]
dec_5Mpc_circle=[]
z_5Mpc_circle=[]
for i in range(len(galaxy_ra)):
if np.sqrt((galaxy_ra[i]-cluster_centre[0])**2+(galaxy_dec[i]-cluster_centre[1])**2)<= R_200:
ra_5Mpc_circle.append(galaxy_ra[i])
dec_5Mpc_circle.append(galaxy_dec[i])
z_5Mpc_circle.append(redshift[i])
print('arcmin circle',len(z_5Mpc_circle))
new_cluster_z=histogram(z_5Mpc_circle,50,'#0504ab')
print('new cluster z:' ,new_cluster_z)
cluster_z_filter=[]
for i in range(len(z_5Mpc_circle)):
if (z_5Mpc_circle[i] >= new_cluster_z - 0.015) and (z_5Mpc_circle[i] <= new_cluster_z + 0.015):
cluster_z_filter.append(z_5Mpc_circle[i])
print(max(cluster_z_filter),min(cluster_z_filter),len(cluster_z_filter))
#Cluster members
v_rec_vel=np.array(np.array(cluster_z_filter)*constants.c)
median_rec_vel=stats.median(v_rec_vel)
v_rest_vel=np.array(v_rec_vel - median_rec_vel) /(1+median_rec_vel/constants.c)
biscl_2 = biweight_scale(v_rest_vel)
sigma_clip=np.array(v_rest_vel)[(v_rest_vel>-3*biscl_2)&(v_rest_vel<3*biscl_2)]
print(' rest velocity calculated from the biweight scale',(biscl_2/10**3))
sigma_cluster_z = biweight_scale(sigma_clip)/10**3
print(' rest velocity calculated from the biweight scale sigma clip',sigma_cluster_z )
plt.show()
return(sigma_cluster_z,new_cluster_z )
def redshift_plots(zsp,zph,sigma_cluster_z,new_cluster_z ):
mask_array=~np.logical_or(np.isnan(zsp), np.isnan(zph))
zph_final=zph[mask_array]
zsp_final=zsp[mask_array]
print(len(zph_final),'length spectro and photo array')
sigma_z= (sigma_cluster_z*10**3) /constants.c
plt.scatter(zph_final,zsp_final)
plt.title('Photometric redshift vs spectrosopic redshift for galaxies at 0.7 > z > 0')
plt.xlabel('photometric redshift')
plt.ylabel('spectroscopic redshift')
plt.xlim(0,0.7)
plt.ylim(0,0.7)
# plt.xlim(new_cluster_z-(30*(sigma_z)),new_cluster_z+(30*(sigma_z)))
# plt.ylim(new_cluster_z-(30*(sigma_z)),new_cluster_z+(30*(sigma_z)))
plt.show()
def radio_SFR_plots(radio_flux,solar_mass,zsp_1):
h=0.7
H0=h*100
cosmo = cp.FlatLambdaCDM(H0=h*100, Om0=0.30)
lumo_distance=np.array(cosmo.luminosity_distance(zsp_1))
SFR_constant = 3.18e-22
S_14=(radio_flux/(1283e6**-0.8)) * (1400e6**-0.8)
radio_lumo=4*np.pi*(S_14*10**-26)*(lumo_distance*3.086e22)**2
print('radio lumonisties',radio_lumo)
SFR = SFR_constant*radio_lumo
print('SFR',SFR)
plt.scatter( solar_mass,SFR, color='black', alpha=0.5)
plt.xlabel("SFR in M_solar/yea r")
plt.ylabel("Log(Solar mass)")
plt.ylim(0,800)
plt.title("SFR vs solar mass")
plt.show()