예제 #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}
예제 #2
0
    pulseModelQueryPoints = np.linspace(1.0 / nSmoothPlotPoints, 1, nSmoothPlotPoints)

    def modelProfile(thetas):
        return np.sum(modelFourierCoeffs * np.exp(2.0j * np.pi * modes * thetas[:, np.newaxis]), axis=1)

    lightCurveModel = np.abs(modelProfile(pulseModelQueryPoints))
    # for this test we only want the model to be the pulsed component.  We will add a DC offset later
    pulseModel = lightCurveModel - np.min(lightCurveModel)

    # initialPhotonPulseFraction = 1.*np.sum(pulseModel) / np.sum(lightCurveModel)
    photonPulseFraction = 15400.0 / nPhotons  # skip to previously determined answer
    print "photon fraction", photonPulseFraction

    # get samples with distribution of the modelProfile
    # modelSampler = inverseTransformSampler(pdf=lightCurveModel,queryPoints=pulseModelQueryPoints)
    modelSampler = inverseTransformSampler(pdf=pulseModel, queryPoints=pulseModelQueryPoints)

    nTrials = 1
    # for each trial run the h test on a set of photon phases with our model profile, and with the pulse fraction specified
    # we want to make a distribution of H values for this pulse fraction, model, and number of photons

    # make a function that only takes the trial number (as an identifier)
    mappableHTestTrial = functools.partial(
        hTestTrial,
        pulseModel=pulseModel,
        pulseModelQueryPoints=pulseModelQueryPoints,
        nPhotons=nPhotons,
        photonPulseFraction=photonPulseFraction,
    )
    pool = multiprocessing.Pool(processes=multiprocessing.cpu_count() - 3)  # leave a few processors for other people
    outDicts = pool.map(mappableHTestTrial, np.arange(nTrials))