Example #1
0
def test_durationAttenuation():
    attenuation = .9
    timespan_days = 90
    period = 5
    size = timespan_days*50
    sigma = 1
    depth = 20

    rSun = 6.96e8
    mSun = 2e30

    x = np.linspace(0, timespan_days, size)
    y = sigma * np.random.randn(size)

    #Compute a plausible duration for transit
    durObj = fbls.AstrophysicalDurationsSearch(.333, 5, rSun, mSun, attenuation)
    duration_days = np.mean(durObj(period))
    duration_cadences = int(duration_days/float(timespan_days) * size)

    #Add in some transits
    phase = 25
    for i in np.arange(0, size, size*period/float(timespan_days)):
        y[i+phase:i+phase+duration_cadences] -= depth

    periodList = [5]
    blsArray = fbls.computefBls(x, y,sigma, periodList, 10,
                   durObj)

    n0 = duration_cadences * timespan_days/period
    expectedMax = (depth*n0) / (sigma*np.sqrt(n0))
    assert( blsArray[0,2] > attenuation*expectedMax)
Example #2
0
def test_strengthVScatter():
    """False alarm prob should be independent of the amount of scatter,
    all else being equal"""
    period = [200]
    size = 1000
    sigma = 1
    overres = 10
    width = [6]

    x = np.arange(size)
    noise = np.random.randn(size)

    mp.clf()
    sigmaList = [1,2,4,8]
    signal = np.zeros_like(sigmaList)

    for i,sigma in enumerate(sigmaList):
        y = sigma * noise
        blsArray = fbls.computefBls(x, y,sigma, [period], overres,
                                    width)
        signal[i] = np.min(blsArray[:,1])


    signal /= np.mean(signal) - 1
    assert np.all( np.fabs(signal) < .01)
Example #3
0
def test_strengthVDuration():
    """Test that measured signal strength is strongest at the
    true duration of the transit
    """

    period = 200
    size = 1000
    sigma = 1
    overres = 10
    injectedWidth = 10

    for kk in range(30):
        x = np.arange(size)
        y = sigma * np.random.randn(size)

        #Add a small signal
        y[400:400+injectedWidth] -= 20
        trialWidths = np.arange(2, 100, 4)
        signal = np.zeros_like(trialWidths)

        for i, tw in enumerate(trialWidths):
            durFunc = lambda x: [tw]
            blsArray = fbls.computefBls(x, y,sigma, [period], overres,
                       durFunc)
            signal[i] = np.min(blsArray[:,1])

        wh = np.argmin( np.fabs(trialWidths - injectedWidth) )
        assert(signal[wh] <  .95*np.min(signal))
Example #4
0
def test_strengthVTimespan():
    """Test that signal strength is independent of timespan"""

    size = 10000
    sigma = 1
    overres = 10
    width = 10
    #BLS strength should be constant with timespan, but FAP should
    #decrease for a signal of a given strength when timespan increases
    #because the number of draws increases

    x = np.arange(size)
    y = sigma * np.random.randn(size)

    #Add a small signal
    y[10:10+width] -= 2

    for iter in range(100):
        nList = [30, 100, 300, 1000, 3000, 10000]
        signal = np.zeros_like(nList)
        for i,n in enumerate(nList):
            durFunc = lambda x: [width]
            blsArray = fbls.computefBls(x[:n], y[:n], sigma, [n], overres,
                       durFunc)

            signal[i] = np.max(blsArray[:,2])
        assert np.all( np.fabs(signal - np.mean(signal) ) < .001)
Example #5
0
def test_periodAttenuation():

    attenuation = .9
    timespan_days = 90
    period = 5
    size = timespan_days*50
    sigma = 1
    depth = 20

    rSun = 6.96e8
    mSun = 2e30

    x = np.linspace(0, timespan_days, size)
    y = sigma * np.random.randn(size)
    durObj = fbls.AstrophysicalDurationsSearch(.99, 1.01, rSun, mSun, attenuation)
    duration_days = durObj(period)[0]
    duration_cadences = int(duration_days/float(timespan_days) * size)
#    duration_cadences = 4

    #Add in some transits
    phase = 25
    for i in np.arange(0, size, size*period/float(timespan_days)):
        y[i+phase:i+phase+duration_cadences] -= depth

    periodList = fbls.computePeriodListForAstrophysicalDurations(4,6, \
                    timespan_days, rSun, mSun, attenuation)

    blsArray = fbls.computefBls(x, y,sigma, periodList, 10,
                   [duration_days])

    n0 = duration_cadences * timespan_days/period
    expectedMax = (depth*n0) / (sigma*np.sqrt(n0))
    assert( np.max(blsArray[:,2]) > attenuation*expectedMax)
Example #6
0
def test_strengthVPhaseOverres():
    """Test that measured strength at a given period is not
    sensitive to the choice of phase over resolution

    """

    transitWidth = lambda x: [10]   #Function that always returns 10
    period = 200
    size = 1000
    sigma = 1

    x = np.arange(size)
    y = sigma * np.random.randn(size)

    #If the BLS is under resolved we get an underestimated signal strength.
    #So we start at a phase over resolution of 16 for the purpose of this
    #test. Your actual needs may tolerate a lower overresolution.
    overresList = 2** np.arange(4,10)
    signal = np.zeros_like(overresList)

    for i in range(len(overresList)):
        blsArray = fbls.computefBls(x, y,sigma, [period], overresList[i],
                       transitWidth)
        signal[i] = np.min(blsArray[:,1])

    signal -= np.mean(signal)

    assert np.max( np.fabs(signal) < 1e-3)
Example #7
0
def test_strengthVTimespan():
    """Test that signal strength is independent of timespan"""

    size = 10000
    sigma = 1
    overres = 10
    width = 10
    #BLS strength should be constant with timespan, but FAP should
    #decrease for a signal of a given strength when timespan increases
    #because the number of draws increases

    x = np.arange(size)
    y = sigma * np.random.randn(size)

    #Add a small signal
    y[10:10 + width] -= 2

    for iter in range(100):
        nList = [30, 100, 300, 1000, 3000, 10000]
        signal = np.zeros_like(nList)
        for i, n in enumerate(nList):
            durFunc = lambda x: [width]
            blsArray = fbls.computefBls(x[:n], y[:n], sigma, [n], overres,
                                        durFunc)

            signal[i] = np.max(blsArray[:, 2])
        assert np.all(np.fabs(signal - np.mean(signal)) < .001)
Example #8
0
def test_durationAttenuation():
    attenuation = .9
    timespan_days = 90
    period = 5
    size = timespan_days * 50
    sigma = 1
    depth = 20

    rSun = 6.96e8
    mSun = 2e30

    x = np.linspace(0, timespan_days, size)
    y = sigma * np.random.randn(size)

    #Compute a plausible duration for transit
    durObj = fbls.AstrophysicalDurationsSearch(.333, 5, rSun, mSun,
                                               attenuation)
    duration_days = np.mean(durObj(period))
    duration_cadences = int(duration_days / float(timespan_days) * size)

    #Add in some transits
    phase = 25
    for i in np.arange(0, size, size * period / float(timespan_days)):
        y[i + phase:i + phase + duration_cadences] -= depth

    periodList = [5]
    blsArray = fbls.computefBls(x, y, sigma, periodList, 10, durObj)

    n0 = duration_cadences * timespan_days / period
    expectedMax = (depth * n0) / (sigma * np.sqrt(n0))
    assert (blsArray[0, 2] > attenuation * expectedMax)
Example #9
0
def test_strengthVDuration():
    """Test that measured signal strength is strongest at the
    true duration of the transit
    """

    period = 200
    size = 1000
    sigma = 1
    overres = 10
    injectedWidth = 10

    for kk in range(30):
        x = np.arange(size)
        y = sigma * np.random.randn(size)

        #Add a small signal
        y[400:400 + injectedWidth] -= 20
        trialWidths = np.arange(2, 100, 4)
        signal = np.zeros_like(trialWidths)

        for i, tw in enumerate(trialWidths):
            durFunc = lambda x: [tw]
            blsArray = fbls.computefBls(x, y, sigma, [period], overres,
                                        durFunc)
            signal[i] = np.min(blsArray[:, 1])

        wh = np.argmin(np.fabs(trialWidths - injectedWidth))
        assert (signal[wh] < .95 * np.min(signal))
Example #10
0
def test_strengthVPhaseOverres():
    """Test that measured strength at a given period is not
    sensitive to the choice of phase over resolution

    """

    transitWidth = lambda x: [10]  #Function that always returns 10
    period = 200
    size = 1000
    sigma = 1

    x = np.arange(size)
    y = sigma * np.random.randn(size)

    #If the BLS is under resolved we get an underestimated signal strength.
    #So we start at a phase over resolution of 16 for the purpose of this
    #test. Your actual needs may tolerate a lower overresolution.
    overresList = 2**np.arange(4, 10)
    signal = np.zeros_like(overresList)

    for i in range(len(overresList)):
        blsArray = fbls.computefBls(x, y, sigma, [period], overresList[i],
                                    transitWidth)
        signal[i] = np.min(blsArray[:, 1])

    signal -= np.mean(signal)

    assert np.max(np.fabs(signal) < 1e-3)
Example #11
0
def test_periodAttenuation():

    attenuation = .9
    timespan_days = 90
    period = 5
    size = timespan_days * 50
    sigma = 1
    depth = 20

    rSun = 6.96e8
    mSun = 2e30

    x = np.linspace(0, timespan_days, size)
    y = sigma * np.random.randn(size)
    durObj = fbls.AstrophysicalDurationsSearch(.99, 1.01, rSun, mSun,
                                               attenuation)
    duration_days = durObj(period)[0]
    duration_cadences = int(duration_days / float(timespan_days) * size)
    #    duration_cadences = 4

    #Add in some transits
    phase = 25
    for i in np.arange(0, size, size * period / float(timespan_days)):
        y[i + phase:i + phase + duration_cadences] -= depth

    periodList = fbls.computePeriodListForAstrophysicalDurations(4,6, \
                    timespan_days, rSun, mSun, attenuation)

    blsArray = fbls.computefBls(x, y, sigma, periodList, 10, [duration_days])

    n0 = duration_cadences * timespan_days / period
    expectedMax = (depth * n0) / (sigma * np.sqrt(n0))
    assert (np.max(blsArray[:, 2]) > attenuation * expectedMax)
Example #12
0
def computeBlsOfNoise(size, sigma, trialTransitWidth, periodList, phaseOverres):

    #Compute lnFAP
    x = np.arange(size)
    y = sigma * np.random.randn(size)
    lnFapArray = fbls.computefBls(x, y, sigma, periodList,
                       [trialTransitWidth], phaseOverres)

    idx= lnFapArray > 1e3
    lnFapArray[idx] = 0
    #Compute BLS spectrum
    nPeriod = len(periodList)
    blsArray = np.zeros( nPeriod )
    for j in range(nPeriod):
        blsArray[j] = np.min( lnFapArray[j,:,:])

    return blsArray
Example #13
0
def computeBlsOfNoise(size, sigma, trialTransitWidth, periodList,
                      phaseOverres):

    #Compute lnFAP
    x = np.arange(size)
    y = sigma * np.random.randn(size)
    lnFapArray = fbls.computefBls(x, y, sigma, periodList, [trialTransitWidth],
                                  phaseOverres)

    idx = lnFapArray > 1e3
    lnFapArray[idx] = 0
    #Compute BLS spectrum
    nPeriod = len(periodList)
    blsArray = np.zeros(nPeriod)
    for j in range(nPeriod):
        blsArray[j] = np.min(lnFapArray[j, :, :])

    return blsArray
Example #14
0
def test_strengthVScatter():
    """False alarm prob should be independent of the amount of scatter,
    all else being equal"""
    period = [200]
    size = 1000
    sigma = 1
    overres = 10
    width = [6]

    x = np.arange(size)
    noise = np.random.randn(size)

    mp.clf()
    sigmaList = [1, 2, 4, 8]
    signal = np.zeros_like(sigmaList)

    for i, sigma in enumerate(sigmaList):
        y = sigma * noise
        blsArray = fbls.computefBls(x, y, sigma, [period], overres, width)
        signal[i] = np.min(blsArray[:, 1])

    signal /= np.mean(signal) - 1
    assert np.all(np.fabs(signal) < .01)