コード例 #1
0
    def generate_threshold(self):
        """
        This function generates a histogram to calculate the lnB values at a given confidence level.
        The histogram is then stored in the ``threshold`` folder.
        """
        import pickle
        import glob
        import pylab as pl

        B = self.B

        files = glob.glob(self.folderpath+'/f*.pickle')
        filesp= glob.glob(self.folderpath+'/p*.pickle')
        data = np.array([]) 
        datap= np.array([])

        if len(files) < 1000 :
            print("[Note] The thresholding values must be calculated for this quarter, as they do not appear to exist. This can take several hours.")
            repeats = 1000 - len(files)
            dt = B.lightcurve.dt()
            length = (B.lightcurve.cts[-1] - B.lightcurve.cts[0] )
            cadence = B.lightcurve.cadence
            pf.mkdir(self.folderpath)
            hours  = 3600
            M = pf.Flare(B.lightcurve.cts, amp=10)
            M.set_taus_gauss(0, 2*hours, 3)
            M.set_taus_exp(.5*hours, 5*hours, 30)
            P = pf.Transit(B.lightcurve.cts, amp=10)
            P.set_tauf(0.5*hours, 6*hours, 11)
            for i in np.arange(repeats-len(files)):
                print("[Note] Iteration ",  1+i, " of ", repeats, "(", ((float(i))/float(repeats))*100,"% completed)")
                A = pf.SimLightcurve(dt=dt, length=length, cadence=cadence)
                # Run the detection statistic for the flare model
                B = pf.Bayes(A, M)
                B.bayes_factors()                
                C = B.marginalise_full()
                D = pf.Bayes(A, P)
                D.bayes_factors()
                E = D.marginalise_full()
                F = C + E
                pickle.dump(F.lnBmargAmp, open(self.folderpath+'/f'+str(i)+'.pickle', 'wb'))
        for file in files:
            data = np.append(data,pickle.load(open(file, 'rb')))

        counts, bin_edges = np.histogram(data[np.isfinite(data)], bins=10000, density=True)
        cdf = np.cumsum(counts)/np.sum(counts)

        mkdir(self.thrfolder)
        pickle.dump(cdf, open(self.thrfolder+'/cdf.pickle', 'wb'))
        pickle.dump(bin_edges, open(self.thrfolder+'/binedge.pickle', 'wb'))

        print("[Note] The thresholding files have been found, and the histogram has been constructed")
コード例 #2
0
ファイル: plot_spectrum.py プロジェクト: wafels/bayesflare
        if kfile == '':
            print >> sys.stderr, "Error... no light curve file found for KID%d" % kids
            sys.exit(0)

        try:
            flarelc = bf.Lightcurve(curve=kfile)
        except:
            print >> sys.stderr, "Error... could not open light curve file %s" % kfile
            sys.exit(0)

        ts = np.copy(flarelc.cts)

    # inject flare
    if opts.injflare:
        tmi = flarelc.cts - flarelc.cts[0]
        Mfi = bf.Flare(tmi, amp=1.)

        if opts.t0 == -1.:
            t0 = tmi[int(len(tmi) / 2)]
        else:
            t0 = opts.t0

        # create flare
        injdata = np.copy(Mfi.model(opts.injamp, opts.taug, opts.taue, t0,
                                    tmi))

        if opts.oinj:
            if oinj != None:
                oinj = oinj + injdata
            else:
                oinj = np.copy(injdata)
コード例 #3
0
            # output the transit parameters
            if outd:
                fparams.write("%f\t%f\t%f\n" % (snrs[i], sigmags[i], taufs[i]))

            del Mti
        elif opts.injimpulse:  # create a delta-function impulse
            Mii = bf.Impulse(flarelc.cts, amp=1)
            injdata = np.copy(Mii.model(impsign, t0, flarelc.cts))

            # output the impulse parameters
            if outd is not None:
                fparams.write("%f\t%d\n" % (snrs[i], impsign))

            del Mii
        else:
            Mfi = bf.Flare(flarelc.cts, amp=1)
            injdata = np.copy(
                Mfi.model(1., taugausss[i], tauexps[i], t0, flarelc.cts))

            # output the flare parameters
            if outd is not None:
                fparams.write("%d\t%d\t%f\t%f\t%f" %
                              (i, idxt0, snrs[i], taugausss[i], tauexps[i]))

                if dosinusoids:
                    fparams.write("\t%e\t%f" % (freqs[i], amps[i]))

                fparams.write("\n")

            del Mfi