Esempio n. 1
0
def candsearch(spectrum, specstart, specend, candthresh, drift_rate, header,
               fftlen, tdwidth, max_val, reverse):
    ''' Searches for candidates: each channel if > candthresh.
    '''

    logger.debug('Start searching for drift rate: %f' % drift_rate)
    j = 0
    for i in (spectrum[specstart:specend] >
              candthresh).nonzero()[0] + specstart:
        k = (tdwidth - 1 - i) if reverse else i
        info_str = 'Candidate found at SNR %f! %s\t' % (
            spectrum[i], '(reverse)' if reverse else '')
        info_str += 'Spectrum index: %d, Drift rate: %f\t' % (i, drift_rate)
        info_str += 'Uncorrected frequency: %f\t' % chan_freq(
            header, k, tdwidth, 0)
        info_str += 'Corrected frequency: %f' % chan_freq(
            header, k, tdwidth, 1)
        logger.debug(info_str)
        j += 1
        used_id = j
        if spectrum[i] > max_val.maxsnr[k]:
            max_val.maxsnr[k] = spectrum[i]
            max_val.maxdrift[k] = drift_rate
            max_val.maxid[k] = used_id

    return j, max_val
Esempio n. 2
0
    def report_tophit(self,
                      max_val,
                      ind,
                      ind_tuple,
                      tdwidth,
                      fftlen,
                      header,
                      total_n_candi,
                      spec_slice=None,
                      obs_info=None):
        '''This function looks into the top hit in a region, basically find the local maximum and saves that.
        '''

        offset = int((tdwidth - fftlen) / 2)
        tdwidth = len(max_val.maxsnr)

        self.tophit_count += 1
        freq_start = chan_freq(header, ind_tuple[0] - offset, tdwidth, 0)
        freq_end = chan_freq(header, ind_tuple[1] - 1 - offset, tdwidth, 0)

        uncorr_freq = chan_freq(header, ind - offset, tdwidth, 0)
        corr_freq = chan_freq(header, ind - offset, tdwidth, 1)

        #Choosing the index of given SEFD and freq.
        if obs_info['SEFDs_freq'][0] > 0.:
            this_one = np.arange(len(obs_info['SEFDs_freq']))[(
                obs_info['SEFDs_freq_up'] > uncorr_freq)][0]
        else:
            this_one = 0

        info_str = '%03d\t' % (self.tophit_count)  #Top Hit number
        info_str += '%10.6f\t' % max_val.maxdrift[ind]  #Drift Rate
        info_str += '%10.6f\t' % max_val.maxsnr[ind]  #SNR
        info_str += '%14.6f\t' % uncorr_freq  #Uncorrected Frequency:
        info_str += '%14.6f\t' % corr_freq  #Corrected Frequency:
        info_str += '%d\t' % (ind - offset)  #Index:
        info_str += '%14.6f\t' % freq_start  #freq_start:
        info_str += '%14.6f\t' % freq_end  #freq_end:
        info_str += '%s\t' % obs_info['SEFDs_val'][this_one]  #SEFD:
        info_str += '%14.6f\t' % obs_info['SEFDs_freq'][
            this_one]  #SEFD_mid_freq:
        try:
            info_str += '%i\t' % header[u'coarse_chan']  #
        except:
            info_str += '%i\t' % header[b'coarse_chan']
        info_str += '%i\t' % total_n_candi  #
        info_str += '\n'
        self.write(info_str)

        return self