@@ -22,10 +22,10 @@ class NonIntegerClustersError(Exception):
22
22
23
23
def clean_signal (time , flux , dtime , dflux , dfluxerr , out ):
24
24
'''
25
- Remove possible eclipsing binary signals from a light curve. This works best
26
- on deep, strongly periodic signals, so it is unlikely to clean transit signals
27
- (though it sometimes will). This should help BLS pulse find less prominent
28
- signals in the same data.
25
+ Remove possible eclipsing binary signals from a light curve. This works
26
+ best on deep, strongly periodic signals, so it is unlikely to clean
27
+ transit signals (though it sometimes will). This should help BLS pulse
28
+ find less prominent signals in the same data.
29
29
30
30
:param time: Raw time vector (no detrending or binning)
31
31
:type time: np.ndarray
@@ -42,15 +42,17 @@ def clean_signal(time, flux, dtime, dflux, dfluxerr, out):
42
42
'''
43
43
# We restrict the "standard deviation" of the cluster to be 5% of the
44
44
# size of the space.
45
- size = max (np .nanmax (np .absolute (out ['depth_dip' ])), np .nanmax (out ['depth_blip' ]))
45
+ size = max (np .nanmax (np .absolute (out ['depth_dip' ])),
46
+ np .nanmax (out ['depth_blip' ]))
46
47
mean_flux_err = 0.05 * size
47
48
48
- # Construct an array of all the useful quantities. We will only be finding
49
- # clusters in the first two dimensions! The other dimensions are for bookkeeping.
49
+ # Construct an array of all the useful quantities. We will only be
50
+ # finding clusters in the first two dimensions! The other dimensions are
51
+ # for bookkeeping.
50
52
ndx = np .where ((out ['srsq_dip' ] > 0. ) & (out ['srsq_blip' ] > 0. ))
51
53
X = np .column_stack ((out ['depth_dip' ][ndx ], out ['depth_blip' ][ndx ],
52
- out ['duration_dip' ][ndx ], out ['duration_blip' ][ndx ], out [ 'midtime_dip' ][ ndx ],
53
- out ['midtime_blip' ][ndx ]))
54
+ out ['duration_dip' ][ndx ], out ['duration_blip' ][ndx ],
55
+ out ['midtime_dip' ][ ndx ], out [ ' midtime_blip' ][ndx ]))
54
56
55
57
metric = lambda x , y : np .sqrt ((x [0 ] - y [0 ])** 2. / mean_flux_err ** 2. +
56
58
(x [1 ] - y [1 ])** 2. / mean_flux_err ** 2. )
@@ -95,18 +97,19 @@ def clean_signal(time, flux, dtime, dflux, dfluxerr, out):
95
97
class_member_mask & core_samples_mask , err_flux = mean_flux_err )
96
98
except NoClustersError :
97
99
# We didn't find any clusters at all. This is a good place to stop.
98
- logger .info ('DBSCAN did not resolve any clusters in the depth_dip/period '
99
- 'space; stopping algorithm.' )
100
+ logger .info ('DBSCAN did not resolve any clusters in the '
101
+ 'depth_dip/period space; stopping algorithm.' )
100
102
raise RuntimeError
101
103
except NonIntegerClustersError :
102
104
# Something weird is going on. Try one more time with a step of 2,
103
105
# then quit, marking this system for further consideration.
104
106
try :
105
- best_period , best_duration , best_phase = __do_period_search (X , time ,
106
- class_member_mask & core_samples_mask , err_flux = mean_flux_err , step = 2 )
107
+ best_period , best_duration , best_phase = __do_period_search (X ,
108
+ time , class_member_mask & core_samples_mask ,
109
+ err_flux = mean_flux_err , step = 2 )
107
110
except (NoClustersError , NonIntegerClustersError ):
108
- logger .warning ('DBSCAN found multiple clusters that do not look like '
109
- 'integer multiples; investigate!' )
111
+ logger .warning ('DBSCAN found multiple clusters that do not look '
112
+ 'like integer multiples; investigate!' )
110
113
raise RuntimeError
111
114
112
115
def boxcar (time , duration , depth , P , phase ):
@@ -119,7 +122,8 @@ def boxcar(time, duration, depth, P, phase):
119
122
120
123
return flux
121
124
122
- p0 = np .array ([best_duration , depth , best_period , best_phase ], dtype = 'float64' )
125
+ p0 = np .array ([best_duration , depth , best_period , best_phase ],
126
+ dtype = 'float64' )
123
127
logger .info ('Best guess boxcar parameters:\n \t ' + str (p0 ))
124
128
125
129
ndx = np .where (np .isfinite (dflux ))
@@ -128,6 +132,7 @@ def boxcar(time, duration, depth, P, phase):
128
132
logger .info ('Best fit boxcar parameters:\n \t ' + str (pbest ))
129
133
130
134
best_duration = pbest [0 ]
135
+ best_depth = pbest [1 ]
131
136
best_period = pbest [2 ]
132
137
best_phase = pbest [3 ]
133
138
@@ -136,7 +141,8 @@ def boxcar(time, duration, depth, P, phase):
136
141
(pftime < best_phase + 2. * best_duration ))
137
142
flux [ndx ] = np .nan
138
143
139
- return dict (period = best_period , duration = best_duration , phase = best_phase )
144
+ return dict (period = best_period , duration = best_duration , depth = best_depth ,
145
+ phase = best_phase )
140
146
141
147
142
148
def __do_period_search (X , time , mask , step = 1 , err_midtime = 0.1 , err_flux = 0.01 ,
@@ -150,9 +156,9 @@ def __do_period_search(X, time, mask, step=1, err_midtime=0.1, err_flux=0.01,
150
156
metric = lambda x , y : np .sqrt ((x [0 ] - y [0 ])** 2. / err_flux ** 2. + \
151
157
(x [1 ] - y [1 ])** 2. / err_midtime ** 2. )
152
158
153
- # Search for clusters a second time, this time to identify the period. We expect
154
- # a cluster around the mean value and less significant ones around integer
155
- # multiples of that value.
159
+ # Search for clusters a second time, this time to identify the period.
160
+ # We expect a cluster around the mean value and less significant ones
161
+ # around integer multiples of that value.
156
162
try :
157
163
db = DBSCAN (eps = 1. , min_samples = 10 , metric = metric ).fit (Y [:,0 :2 ])
158
164
except ValueError :
@@ -167,9 +173,9 @@ def __do_period_search(X, time, mask, step=1, err_midtime=0.1, err_flux=0.01,
167
173
n_clusters_ = len (unique_labels ) - (1 if - 1 in labels else 0 )
168
174
169
175
if n_clusters_ == 1 :
170
- # This is the best-case scenario. The best choice for the period is just
171
- # the mean of the consecutive differences. The phase and duration follow
172
- # easily.
176
+ # This is the best-case scenario. The best choice for the period is
177
+ # just the mean of the consecutive differences. The phase and
178
+ # duration follow easily.
173
179
class_member_mask = (labels != - 1 )
174
180
175
181
best_period = np .mean (Y [class_member_mask & core_samples_mask ][:,1 ])
@@ -197,8 +203,8 @@ def __do_period_search(X, time, mask, step=1, err_midtime=0.1, err_flux=0.01,
197
203
candidate_periods .append ([np .mean (Y [class_member_mask &
198
204
core_samples_mask ][:,1 ]), kk ])
199
205
200
- # Check for integer multiples in the candidate periods list. The modulus
201
- # by the minimum one should be sufficient.
206
+ # Check for integer multiples in the candidate periods list. The
207
+ # modulus by the minimum one should be sufficient.
202
208
candidate_periods = np .array (candidate_periods )
203
209
min_period = np .amin (candidate_periods [:,0 ])
204
210
mods = np .mod (candidate_periods [:,0 ], min_period )
0 commit comments