-
Notifications
You must be signed in to change notification settings - Fork 0
/
qso_CRTS_stats_match_to_javelin.py
162 lines (114 loc) · 4.54 KB
/
qso_CRTS_stats_match_to_javelin.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
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 23 22:12:01 2014
@author: Chris
Matching the Javelin results and the good_err_LC.txt , which selected
those quasars that have good errors.
Plotting stats for CRTS, to see if there is anything weird in those
that have sigma < 0 ...
I leave it open to also plot these same stats for QSO,
because it's so much quicker, to test the program ...
"""
import numpy as np
#args = sys.argv
#err = int(args[1])
ch = 1
dir_in_out = ['QSO_CRTS_analysis/', 'stars_CRTS_analysis/']
files = ['javelin_CRTS_chain_results_err_w.txt', 'javelin_CRTS_stars_err_w_chain_results.txt']
chain_results = dir_in_out[ch]+ files[ch]
data = np.loadtxt(chain_results,dtype='str' )
############################
# READ IN THE CHAIN VALUES#
############################
fname = np.empty(0,dtype=float)
sigma_m = np.empty(0,dtype=float)
tau_m = np.empty(0,dtype=float)
print 'Reading in all the values ... '
for i in range(len(data[:,0])):
try:
fname = np.append(fname, data[i,0])
sigma_m = np.append(sigma_m, float(data[i,2]))
tau_m = np.append(tau_m, float(data[i,5]))
except ValueError:
pass
if len(sigma_m) != len(tau_m) :
m = min(len(tau_m), len(sigma_m))
sigma_m = sigma_m[0:m]
tau_m = tau_m[0:m]
fname = fname[0:m]
assert len(sigma_m) == len(tau_m)
print '\nOut of ', len(data[:,0]), ' rows we were able to read in ', len(tau_m)
############################
# SELECTING POINTS TO USE #
############################
def sel_points_stars(dir_in_out, fname):
good_LC = np.loadtxt(dir_in_out + 'good_err_LC.txt', dtype='str')
good_LC_cut = np.empty(0, dtype=str)
for i in range(len(good_LC)):
good_LC_cut = np.append(good_LC_cut, good_LC[i][4:-8])
good_LC_mask = np.zeros_like(fname, dtype='bool')
for i in range(len(fname)):
print '\nComparison in progress...', str((float(i) / float(len(fname)) )*100.0)[:5], '%'
good_LC_mask[i] = fname[i][4:] in good_LC_cut
print 'Out of ', len(fname), 'objects, we use ', good_LC_mask.sum()
return good_LC_mask
def sel_points_qso(dir_in_out, fname):
good_LC = np.loadtxt(dir_in_out + 'good_err_LC.txt', dtype='str')
good_LC_cut = np.empty(0, dtype=str)
for i in range(len(good_LC)):
good_LC_cut = np.append(good_LC_cut, good_LC[i][4:-4])
good_LC_mask = np.zeros_like(fname, dtype='bool')
for i in range(len(fname)):
print '\nComparison in progress...', str((float(i) / float(len(fname)) )*100.0)[:5], '%'
good_LC_mask[i] = fname[i][:-10] in good_LC_cut
print 'Out of ', len(fname), 'objects, we use ', good_LC_mask.sum()
return good_LC_mask
if ch == 0:
good_LC_mask = sel_points_qso(dir_in_out[ch], fname)
if ch == 1 :
good_LC_mask = sel_points_stars(dir_in_out[ch], fname)
fname = fname[good_LC_mask]
sigma_m = sigma_m[good_LC_mask]
tau_m = tau_m[good_LC_mask]
sigma_hat = sigma_m * np.sqrt(tau_m / (2.0 * 365.0))
############################
# READ IN STATS FOR LC'S #
############################
stats = np.loadtxt(dir_in_out[ch]+'LC_stats.txt', dtype='str')
lc_names = stats[:,0]
def check_stats_qso(fname,lc_names):
ind = np.zeros(len(fname), dtype=int)
for i in range(len(fname)):
print '\nChecking', i, ' of ', len(fname)
for j in range(len(lc_names)):
if lc_names[j][4:-4] == fname[i][:-10] :
ind[i] = j
return ind
def check_stats_stars(fname,lc_names):
ind = np.zeros(len(fname), dtype=int)
for i in range(len(fname)):
print '\nChecking', i, ' of ', len(fname)
for j in range(len(lc_names)):
if lc_names[j][4:-8] == fname[i][4:] :
ind[i] = j
return ind
if ch == 0 :
ind = check_stats_qso(fname,lc_names)
if ch == 1 :
ind = check_stats_stars(fname, lc_names)
mjd_span = stats[:,1]
mag_rms = stats[:,2]
mag_mean = stats[:,3]
err_mean = stats[:,4]
N_lines = stats[:,5]
# choose only those matching from stats - now their order matches the fname order
lc_names = lc_names[ind]
mjd_span = mjd_span[ind]
mag_rms = mag_rms[ind]
mag_mean = mag_mean[ind]
err_mean = err_mean[ind]
N_lines = N_lines[ind]
print 'These should match: ', fname[0], lc_names[0]
DAT = np.column_stack((fname,lc_names, sigma_m, tau_m, sigma_hat, mjd_span, mag_rms, mag_mean, err_mean, N_lines))
np.savetxt(dir_in_out[ch]+'javelin_sigma_tau_plus_stats_matched_good_err.txt',DAT,delimiter=" ", fmt="%s")
#newDAT=DAT[DAT[:,2].argsort()] # sort according to sigma_m