-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlineprofile.py
78 lines (51 loc) · 1.57 KB
/
lineprofile.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
import numpy as np
import matplotlib.pyplot as plt
# Computes lineprofile
def lineprofile(fluxc, redsc):
print "Computing line profile..."
xarr = np.array([])
yarr = np.array([])
Ny_dense, Nx_dense = np.shape(fluxc)
#print "Mean redshift={}".format(np.mean(redsc))
#print "Median redshift={}".format(np.median(redsc))
#print "std redshift={}".format(np.std(redsc))
energ = 1.0
for jj in range(Ny_dense):
for ii in range(Nx_dense):
fy = fluxc[jj, ii]
xii = redsc[jj, ii]
if xii > 0.0:
xarr = np.append(xarr, xii*energ)
yarr = np.append(yarr, fy)
xind = np.argsort(xarr)
xarrs = xarr[xind]
yarrs = yarr[xind]
#plt.plot(xarrs, yarrs)
#plt.plot(xarrs)
#plt.show()
#Discard 0.5% of tails (=nonsense values)
NN = len(xarrs)
emin = xarrs[np.int(0.002*NN)]
emax = xarrs[np.int(0.998*NN)]
#emin = np.min(xarrs)*0.99
#emax = np.max(xarrs)*1.01
Nr = 100
es = np.linspace(emin, emax, Nr)
yy2 = np.zeros((Nr))
xst = 0
for ii in range(1,Nr):
for jj in range(xst, NN):
if es[ii-1] <= xarrs[jj] < es[ii]:
yy2[ii] += yarrs[jj]
elif xarrs[jj] >= es[ii]:
xst = jj
break
#close the profile
es = np.append(es, es[-1]+0.001)
yy2 = np.append(yy2, 0.0)
es = np.insert(es, 0, es[0]-0.001)
yy2 = np.insert(yy2, 0, 0.0)
#normalize
des = np.diff(es)[1]
yy2 = yy2 / np.sum(yy2*des)
return es, yy2