Esempio n. 1
0
def test_slice_peak2():
    ''' Test the slicing around peak '''
    light_curve = pdb.get_light_curve(100024, 11, 2693, clean=True) # bad data

    ml_chisq = 1E6
    ml_params = None
    for ii in range(10):
        params = pa.fit_microlensing_event(light_curve)
        new_chisq = params["result"].chisqr

        if new_chisq < ml_chisq:
            ml_chisq = new_chisq
            ml_params = params

    import matplotlib.pyplot as plt

    ax = plt.subplot(211)
    sliced_lc = light_curve.slice_mjd(ml_params["t0"].value-ml_params["tE"].value, ml_params["t0"].value+ml_params["tE"].value)
    print len(sliced_lc)
    sliced_lc.plot(ax)

    ax2 = plt.subplot(212)
    sliced_ml_params = pa.fit_microlensing_event(sliced_lc)
    new_sliced_light_curve = pa.fit_subtract_microlensing(sliced_lc, fit_data=sliced_ml_params)
    new_sliced_light_curve.plot(ax2)
    ax2.set_title(r"Med. Err: {0}, $\sigma$: {1}".format(np.median(sliced_lc.error), np.std(new_sliced_light_curve.mag)))

    plt.savefig("plots/test_slice_peak2_bad_data.png")

    # Now do with a simulated event
    from ptf.lightcurve import SimulatedLightCurve
    light_curve = SimulatedLightCurve(mjd=light_curve.mjd, mag=15, error=0.1)
    light_curve.add_microlensing_event(u0=0.1, t0=55600, tE=40)

    ml_chisq = 1E6
    ml_params = None
    for ii in range(10):
        params = pa.fit_microlensing_event(light_curve)
        new_chisq = params["result"].chisqr

        if new_chisq < ml_chisq:
            ml_chisq = new_chisq
            ml_params = params

    plt.clf()
    ax = plt.subplot(211)
    sliced_lc = light_curve.slice_mjd(ml_params["t0"].value-ml_params["tE"].value, ml_params["t0"].value+ml_params["tE"].value)
    print len(sliced_lc)
    sliced_lc.plot(ax)

    ax2 = plt.subplot(212)
    sliced_ml_params = pa.fit_microlensing_event(sliced_lc)
    new_sliced_light_curve = pa.fit_subtract_microlensing(sliced_lc, fit_data=sliced_ml_params)
    new_sliced_light_curve.plot(ax2)
    ax2.set_title(r"Med. Err: {0}, $\sigma$: {1}".format(np.median(sliced_lc.error), np.std(new_sliced_light_curve.mag)))

    plt.savefig("plots/test_slice_peak2_sim.png")
Esempio n. 2
0
def test_slice_peak():
    ''' Test the slicing around peak '''
    light_curve = pdb.get_light_curve(100024, 11, 2693, clean=True) # bad data

    ml_chisq = 1E6
    ml_params = None
    for ii in range(10):
        params = pa.fit_microlensing_event(light_curve)
        new_chisq = params["result"].chisqr

        if new_chisq < ml_chisq:
            ml_chisq = new_chisq
            ml_params = params

    import matplotlib.pyplot as plt

    for ii in [1,2,3]:
        ax = plt.subplot(3,1,ii)
        sliced_lc = light_curve.slice_mjd(ml_params["t0"].value-ii*ml_params["tE"].value, ml_params["t0"].value+ii*ml_params["tE"].value)
        sliced_lc.plot(ax)
    plt.savefig("plots/test_slice_peak_bad_data.png")

    # Now do with a simulated event
    from ptf.lightcurve import SimulatedLightCurve
    light_curve = SimulatedLightCurve(mjd=light_curve.mjd, mag=15, error=0.1)
    light_curve.add_microlensing_event(u0=0.1)

    ml_chisq = 1E6
    ml_params = None
    for ii in range(10):
        params = pa.fit_microlensing_event(light_curve)
        new_chisq = params["result"].chisqr

        if new_chisq < ml_chisq:
            ml_chisq = new_chisq
            ml_params = params

    plt.clf()
    for ii in [1,2,3]:
        ax = plt.subplot(3,1,ii)
        sliced_lc = light_curve.slice_mjd(ml_params["t0"].value-ii*ml_params["tE"].value, ml_params["t0"].value+ii*ml_params["tE"].value)
        sliced_lc.plot(ax)
    plt.savefig("plots/test_slice_peak_sim.png")