-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNH3FirstGuess.py
87 lines (75 loc) · 2.72 KB
/
NH3FirstGuess.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
import numpy.fft as fft
import numpy as np
def NH3FirstGuess(pskobj,vmin=-250.0,vmax=250):
ckms = 2.99792458e5
voff_lines = np.array([19.8513,
19.3159,
7.88669,
7.46967,
7.35132,
0.460409,
0.322042,
-0.0751680,
-0.213003,
0.311034,
0.192266,
-0.132382,
-0.250923,
-7.23349,
-7.37280,
-7.81526,
-19.4117,
-19.5500])
tau_wts = np.array([0.0740740,
0.148148,
0.0925930,
0.166667,
0.0185190,
0.0370370,
0.0185190,
0.0185190,
0.0925930,
0.0333330,
0.300000,
0.466667,
0.0333330,
0.0925930,
0.0185190,
0.166667,
0.0740740,
0.148148])
deltanu = -1*voff_lines/ckms*23.6944955e9
#guess at typical line width for NH3 line
linewidth = 0.5
chanwidth = (pskobj.xarr[1]-pskobj.xarr[0])/1e3
ftdata = fft.fft(pskobj.data.filled(0))
tvals = fft.fftfreq(len(pskobj.data))/chanwidth
deltafcns = np.zeros(pskobj.data.shape,dtype=np.complex)
for idx, dv in enumerate(voff_lines):
deltafcns += tau_wts[idx]*(np.cos(2*np.pi*dv*tvals)+
1j*np.sin(2*np.pi*dv*tvals))*\
np.exp(-tvals**2*(linewidth/chanwidth)**2/(2))
ccor = np.real((fft.ifft(np.conj(ftdata)*deltafcns))[::-1])
vaxis = np.array(pskobj.xarr.as_unit('km/s'))
subsetidx = (vaxis>vmin)*(vaxis<vmax)*np.isfinite(np.array(pskobj.data))
peakIndex = np.argmax(ccor[subsetidx])
#pull out a 6 km/s slice around the peak
deltachan = np.abs(3.0 / chanwidth)
t = ((pskobj.data.filled(0))[subsetidx])[(peakIndex-deltachan):(peakIndex+deltachan)]
v = (vaxis[subsetidx])[(peakIndex-deltachan):(peakIndex+deltachan)]
# Calculate line width.
sigv = np.sqrt(abs(np.sum(t*v**2)/np.sum(t)-(np.sum(t*v)/np.sum(t))**2))
if (np.isnan(sigv)):
sigv = 0.85840189 # mean of sigv from first set of data from ./nh3_all/
# Peak of cross correlation is the brightness.
v0 = np.float((vaxis[subsetidx])[peakIndex])
# Set the excitation temperature to be between CMB and 20 K
# and equal to the peak brightness + 2.73 if valid.
tex = np.min([np.max([pskobj.data[peakIndex],0])+2.73,20])
guess = [20, # 20 K kinetic temperature
tex, #
15, # Log NH3
sigv, # velocity dispersion
v0,
0.5]
return(guess)