def flag(self, vis, vis_mask, li, gi, tf, ts, **kwargs): """Function that does the actual flag.""" # if all have been masked, no need to flag again if vis_mask.all(): return first_threshold = self.params['first_threshold'] exp_factor = self.params['exp_factor'] distribution = self.params['distribution'] max_threshold_len = self.params['max_threshold_len'] sensitivity = self.params['sensitivity'] min_connected = self.params['min_connected'] flag_direction = self.params['flag_direction'] tk_size = self.params['tk_size'] fk_size = self.params['fk_size'] threshold_num = max(0, int(self.params['threshold_num'])) vis_abs = np.abs(vis) # operate only on the amplitude # first round # first complete masked vals due to ns by interpolate itp = interpolate.Interpolate(vis_abs, vis_mask) background = itp.fit() # Gaussian fileter gf = gaussian_filter.GaussianFilter(background, time_kernal_size=tk_size, freq_kernal_size=fk_size) background = gf.fit() # sum-threshold vis_diff = vis_abs - background # an initial run of N = 1 only to remove extremely high amplitude RFI st = sum_threshold.SumThreshold(vis_diff, vis_mask, first_threshold, exp_factor, distribution, 1, min_connected) st.execute(sensitivity, flag_direction) # if all have been masked, no need to flag again if st.vis_mask.all(): vis_mask[:] = st.vis_mask return # next rounds for i in xrange(threshold_num): # Gaussian fileter gf = gaussian_filter.GaussianFilter(vis_diff, st.vis_mask, time_kernal_size=tk_size, freq_kernal_size=fk_size) background = gf.fit() # sum-threshold vis_diff = vis_diff - background st = sum_threshold.SumThreshold(vis_diff, st.vis_mask, first_threshold, exp_factor, distribution, max_threshold_len, min_connected) st.execute(sensitivity, flag_direction) # if all have been masked, no need to flag again if st.vis_mask.all(): break # replace vis_mask with the flagged mask vis_mask[:] = st.vis_mask
def flag(self, vis, vis_mask, li, gi, fb, ts, **kwargs): """Function that does the actual flag.""" # if all have been masked, no need to flag again if vis_mask.all(): return first_threshold = self.params['first_threshold'] exp_factor = self.params['exp_factor'] distribution = self.params['distribution'] max_threshold_len = self.params['max_threshold_len'] sensitivity = self.params['sensitivity'] min_connected = self.params['min_connected'] flag_direction = self.params['flag_direction'] vis_abs = np.abs(vis) # operate only on the amplitude # first complete masked vals due to ns by interpolate itp = interpolate.Interpolate(vis_abs, vis_mask) background = itp.fit() background1 = background.copy() # nt, nf = background.shape # for fi in range(nf): # background[:, fi] = multiscale.median_wavelet_smooth(background[:, fi], level=4) # for ti in range(nt): # if fb[0] == fb[1]: # background[ti, :] = multiscale.median_wavelet_smooth(background[ti, :], level=2) # else: # background[ti, :] = multiscale.median_wavelet_smooth(background[ti, :], level=3) background[:] = multiscale.median_wavelet_smooth(background, level=2) # sum-threshold # vis_diff = vis_abs - background vis_diff = background1 - background # an initial run of N = 1 only to remove extremely high amplitude RFI st = sum_threshold.SumThreshold(vis_diff, vis_mask, first_threshold, exp_factor, distribution, 1, min_connected) st.execute(sensitivity, flag_direction) # if all have been masked, no need to flag again if st.vis_mask.all(): vis_mask[:] = st.vis_mask return vis_diff = np.where(st.vis_mask, 0, vis_diff) st = sum_threshold.SumThreshold(vis_diff, st.vis_mask, first_threshold, exp_factor, distribution, max_threshold_len, min_connected) st.execute(sensitivity, flag_direction) vis_mask[:] = st.vis_mask