Exemplo n.º 1
0
def hTestTrial(iTrial, nPhotons, photonPulseFraction, pulseModel, pulseModelQueryPoints):
    np.random.seed(int((time.time() + iTrial) * 1e6))
    modelSampler = inverseTransformSampler(pdf=pulseModel, queryPoints=pulseModelQueryPoints)

    nPulsePhotons = int(np.floor(photonPulseFraction * nPhotons))
    nBackgroundPhotons = int(np.ceil((1.0 - photonPulseFraction) * nPhotons))

    simPulsePhotons = modelSampler(nPulsePhotons)
    # background photons come from a uniform distribution
    simBackgroundPhotons = np.random.random(nBackgroundPhotons)
    simPhases = np.append(simPulsePhotons, simBackgroundPhotons)

    simHDict = h_test2(simPhases)
    simH, simM, simPval, simFourierCoeffs = simHDict["H"], simHDict["M"], simHDict["fpp"], simHDict["cs"]

    print "{} - H,M,fpp,sig:".format(iTrial), simH, simM, simPval
    return {"H": simH, "M": simM, "fpp": simPval}
Exemplo n.º 2
0
    if bLoadFromPl:
        photFile = tables.openFile(path, "r")
        photTable = photFile.root.photons.photTable
        phases = photTable.readWhere("(wvlStart < wavelength) & (wavelength < wvlEnd)")["phase"]
        photFile.close()
        print "cut wavelengths to range ({},{})".format(wvlStart, wvlEnd)

        nPhotons = len(phases)
        print nPhotons, "real photons read"

        observedProfile, _ = np.histogram(phases, bins=phaseBinEdges)
        observedProfile = 1.0 * observedProfile
        observedProfileErrors = np.sqrt(observedProfile)

        # Do H-test
        hDict = h_test2(phases)
        H, M, pval, fourierCoeffs = hDict["H"], hDict["M"], hDict["fpp"], hDict["cs"]

        print "h-test on real data"
        print "H,M,fpp:", H, M, pval
        print nSigma(1 - pval), "sigmas"

        # h_test2 calculates all fourierCoeffs out to 20, but for the fourier model, we only want the ones out to order M, which optimizes the Zm^2 metric
        truncatedFourierCoeffs = fourierCoeffs[0:M]
        print "fourier coeffs:", truncatedFourierCoeffs

        # for the model, we want the negative modes as well as positve, so add them
        modelFourierCoeffs = np.concatenate([truncatedFourierCoeffs[::-1], [1.0], np.conj(truncatedFourierCoeffs)])
        # make array of mode numbers
        modes = np.arange(-len(truncatedFourierCoeffs), len(truncatedFourierCoeffs) + 1)