-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
74 lines (51 loc) · 1.74 KB
/
test.py
File metadata and controls
74 lines (51 loc) · 1.74 KB
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
#!/usr/local/bin/python3
# Cross-correlate a spectrum with a reference
# Returns the relative spectral shift or radial velocity
# Uses the pyastronomy library function
import os
import sys
import numpy as np
from PyAstronomy import pyasl
import matplotlib.pylab as plt
if len(sys.argv) == 1:
sys.exit("Usage: spectrum_crosscorr.py spectrum template rvmin rvmax rvstep skip ")
elif len(sys.argv) == 7:
spfile = sys.argv[1]
tpfile = sys.argv[2]
rvmin = float(sys.argv[3])
rvmax = float(sys.argv[4])
rvstep = float(sys.argv[5])
skip = int(float(sys.argv[6]))
else:
sys.exit("Usage: spectrum_crosscorr.py spectrum template rvmin rvmax rvstep skip ")
spectrum = np.loadtxt(spfile)
spwl = spectrum[:,0]
spfl = spectrum[:,1]
# print spwl
# print spflux
template = np.loadtxt(tpfile)
tpwl = template[:,0]
tpfl = template[:,1]
# print spwl
# print spfl
# Plot a preview of the spectrum and the template
plt.title("Spectrum (red) and the template (blue)")
plt.plot(spwl, spfl, 'r.-')
plt.plot(tpwl, tpfl, 'b.-')
plt.show()
# Carry out the cross-correlation.
# The RV-range is -rvmin to rvmax km/s in steps of rvstep
# The first and last skipedge points of the data are skipped.
rv, cc = pyasl.crosscorrRV(spwl, spfl, tpwl, tpfl, rvmin, rvmax, rvstep, mode='doppler', skipedge=skip)
# Find the index of maximum cross-correlation function
maxind = np.argmax(cc)
print("Cross-correlation function is maximized at relative RV = ", rv[maxind], " (km/s)")
if rv[maxind] > 0.0:
print(" This is a red-shift with respect to the template.")
else:
print(" This is a blue-shift with respect to the template.")
plt.plot(rv, cc, 'bp-')
plt.plot(rv[maxind], cc[maxind], 'ro')
plt.show()
print("Relative RV [km/s]: ", rv[maxind])
exit()