# read and estimate observables #print folder + '/' + lc_name_template lc_name = glob.glob(folder + '/' + lc_name_template)[0] # get flux time, flux = np.loadtxt(lc_name, dtype=(np.float, np.float), usecols=(1, 2), unpack=True) # Scale the light curve so that the mean level is one. flux /= np.median(flux) #pl.subplot(211) #pl.title(lc_name_template) #pl.step(time, flux, where='mid') # estimate event properties eep = EEP(time, flux) eep.estimate() results = eep.get_params() # Cut flux with three times of the event width. # At least 1 seconds. width = max(results[0] * 3., 1.) # 3 times of the width. The data point at zero time # must be centered. half_width = int((width / 2.) / 0.05) center_index = np.searchsorted(time, results[3]) #print half_width, center_index # This make always the number of data points "odd". flux_cut = flux[max(center_index - half_width, 0): min(center_index + half_width + 1, len(flux))]
b = rows[0][4] t = 0.0 a = rows[0][5] d = rows[0][6] print rows[0][7], rows[0][8], rows[0][9] # gen_lc = generate_event_lc(rows[0][tel], np.inf) time = np.arange(len(rows[0][tel])) / 120.0 time -= np.median(time) pl.figure(figsize=(16, 6)) pl.subplot(121) pl.grid() pl.step(time, rows[0][tel], "bx", where="mid") eep = EEP(time, rows[0][tel]) # eep.estimate() v = pl.axis() x = np.linspace(v[0], v[1], 1000) # y = eep.gaussian_step(eep.p1, x) # pl.plot(x, y, 'r-') pl.xlabel("Time/seconds") pl.ylabel("Scaled flux") # print eep.p1, len(eep.flux), eep.get_params() # From file. folder = "/Users/kim/Server/taos2/taos_lc/a%06.1fau_d%04.1fkm" % (a, d) lc_name_template = "TEL%d_bzero%06.3fomega_tzero%06.3fms_*_a%06.1fau_d%04.1fkm_*.lcv" % (tel, b, t, a, d) # Read and estimate observables
for i in range(10): logger.info('\t%dth search..' % (i + 1)) # Select one random event (three light curves). results, c_id = select_random(conn) true_id.append(c_id) # Add noise to the selected event. #Also, make the light curves having 200 data points. # 20 Hz time sampling. Centered at zero. #print len(results['flux_a']), len(results['flux_b']), len(results['flux_c']) results['flux_a'] = add_noise(results['flux_a'], SNRs[m]) results['flux_b'] = add_noise(results['flux_b'], SNRs[m]) results['flux_c'] = add_noise(results['flux_c'], SNRs[m]) # Estimate observables for each light curve. eep = EEP(results['time_a'], results['flux_a']) eep.estimate() a_eep = eep.get_params() width = max(a_eep[0] * 3., 1.) half_width = int((width / 2.) / 0.05) center_index = np.searchsorted(results['time_a'], a_eep[3]) start_index = center_index - half_width end_index = center_index + half_width + 1 #start_index = max(center_index - half_width, 0) #end_index = min(center_index + half_width + 1, len(results['flux_a'])) results['flux_a'] = results['flux_a'][start_index:end_index] results['time_a'] = results['time_a'][start_index:end_index] eep = EEP(results['time_b'], results['flux_b']) eep.estimate() b_eep = eep.get_params()
# Binning and add noise to the selected event. for tel in tels: # Binning, with offset 0. results['flux_%d' % tel] = \ binning(results['flux_%d' % tel], 0, b_bin_steps) results['time_%d' % tel] = \ binning(results['time_%d' % tel], 0, b_bin_steps) # Add noise. results['flux_%d' % tel] = \ add_noise(results['flux_%d' % tel], SNRs[m]) # Estimate observables for each light curve. for tel in tels: eep = EEP(results['time_%d' % tel], results['flux_%d' % tel]) eep.estimate() results['eep_%d' % tel] = eep.get_params() width = max(results['eep_%d' % tel][0] * 3., 0.4) half_width = int((width / 2.) * base_sampling) center_index = np.searchsorted(results['time_%d' % tel], results['eep_%d' % tel][3]) results['flux_%d' % tel] = \ results['flux_%d' % tel] \ [max(center_index - half_width, 0): min(center_index + half_width + 1, len(results['flux_%d' % tel]))] results['time_%d' % tel] = \ results['time_%d' % tel] \ [max(center_index - half_width, 0):