Exemplo n.º 1
0
                    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))]

                    #pl.subplot(212)
                    #pl.title(results)
            # 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()
            width = max(b_eep[0] * 3., 1.)
            half_width = int((width / 2.) / 0.05)
Exemplo n.º 3
0
                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):
                         min(center_index + half_width + 1,
                             len(results['time_%d' % tel]))]
Exemplo n.º 4
0
    flux /= np.median(flux)
    flux = add_noise(flux, np.inf)
    # flux = add_noise(flux, 3)

    # Time offset from 0 to 5.
    colors = "rgbmck"
    base_sampling = 120
    sampling = 40
    b_bin_steps = base_sampling / sampling
    for i in range(b_bin_steps):
        down_time = binning(time, i, b_bin_steps)
        down_flux = binning(flux, i, b_bin_steps)

        eep = EEP(down_time, down_flux)
        eep.estimate()
        print "binned N: ", len(eep.flux), eep.get_params()
        results = eep.get_params()

        width = max(results[0] * 3.0, 0.4)
        # 3 times of the width. The data point at zero time
        # must be centered.
        half_width = int((width / 2.0) * base_sampling)
        center_index = np.searchsorted(time, results[3])
        flux_cut = flux[max(center_index - half_width, 0) : min(center_index + half_width + 1, len(flux))]

        pl.subplot(122)
        pl.step(eep.time, eep.flux, color=colors[i % len(colors)], marker="x", where="mid")

        v = pl.axis()
        x = np.linspace(v[0], v[1], 1000)
        y = eep.gaussian_step(eep.p1, x)
Exemplo n.º 5
0
    time, flux = np.loadtxt(lc_name, dtype=(np.float, np.float),
        usecols=(1, 2), unpack=True)
    print len(time)
    # Scale the light curve so that the mean level is one.
    flux /= np.median(flux)
    flux = add_noise(flux, np.inf)

    width = 6
    down_time = time[:(time.size // width) * width]. \
        reshape(-1, width).mean(axis=1)
    down_flux = flux[:(flux.size // width) * width]. \
        reshape(-1, width).mean(axis=1)

    eep = EEP(down_time, down_flux)
    eep.estimate()
    print eep.p1, len(eep.flux), eep.get_params()
    results = eep.get_params()

    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
    flux_cut = flux[max(center_index - half_width, 0):
                    min(center_index + half_width + 1, len(flux))]
    #flux_cut = flux[center_index - half_width:
    #                center_index + half_width + 1]
    #print flux_cut, len(flux_cut)

    pl.subplot(122)