예제 #1
0
파일: event_fitter.py 프로젝트: adrn/PTF
def test_magnitude_model():
    mjd = np.arange(0., 100., 0.2)
    sigma = np.zeros_like(mjd) + 0.01

    u0 = 0.1
    t0 = 50.
    tE = 20
    mag = magnitude_model([15, u0, t0, tE], mjd)

    fig = plt.figure()
    ax = fig.add_subplot(111)

    ax.errorbar(mjd, mag, sigma)

    light_curve = SimulatedLightCurve(mjd=mjd, error=sigma, mag=15)
    light_curve.add_microlensing_event(t0=t0, u0=u0, tE=tE)
    light_curve.plot(ax)

    plt.show()
예제 #2
0
파일: event_fitter.py 프로젝트: adrn/PTF
def test_magnitude_model():
    mjd = np.arange(0., 100., 0.2)
    sigma = np.zeros_like(mjd) + 0.01

    u0 = 0.1
    t0 = 50.
    tE = 20
    mag = magnitude_model([15, u0, t0, tE], mjd)

    fig = plt.figure()
    ax = fig.add_subplot(111)

    ax.errorbar(mjd, mag, sigma)

    light_curve = SimulatedLightCurve(mjd=mjd, error=sigma, mag=15)
    light_curve.add_microlensing_event(t0=t0, u0=u0, tE=tE)
    light_curve.plot(ax)

    plt.show()
예제 #3
0
파일: test_pipeline.py 프로젝트: adrn/PTF
def test_iscandidate(plot=False):
    ''' Use test light curves to test selection:
        - Periodic
        - Bad data
        - Various simulated events
        - Flat light curve
        - Transients (SN, Nova, etc.)
    '''

    np.random.seed(10)

    logger.setLevel(logging.DEBUG)
    from ptf.lightcurve import SimulatedLightCurve
    import ptf.db.mongodb as mongo

    db = mongo.PTFConnection()

    logger.info("---------------------------------------------------")
    logger.info(greenText("Periodic light curves"))
    logger.info("---------------------------------------------------")

    # Periodic light curves
    periodics = [(4588, 7, 13227), (4588, 2, 15432), (4588, 9, 17195), (2562, 10, 28317), (4721, 8, 11979), (4162, 2, 14360)]

    for field_id, ccd_id, source_id in periodics:
        periodic_light_curve = pdb.get_light_curve(field_id, ccd_id, source_id, clean=True)
        periodic_light_curve.indices = pa.compute_variability_indices(periodic_light_curve, indices=["eta", "delta_chi_squared", "j", "k", "sigma_mu"])
        assert pa.iscandidate(periodic_light_curve, lower_eta_cut=10**db.fields.find_one({"_id" : field_id}, {"selection_criteria" : 1})["selection_criteria"]["eta"]) in ["subcandidate" , False]
        if plot: plot_lc(periodic_light_curve)

    logger.info("---------------------------------------------------")
    logger.info(greenText("Bad light curves"))
    logger.info("---------------------------------------------------")

    # Bad data
    bads = [(3756, 0, 14281), (1983, 10, 1580)]

    for field_id, ccd_id, source_id in bads:
        bad_light_curve = pdb.get_light_curve(field_id, ccd_id, source_id, clean=True)
        bad_light_curve.indices = pa.compute_variability_indices(bad_light_curve, indices=["eta", "delta_chi_squared", "j", "k", "sigma_mu"])
        assert not pa.iscandidate(bad_light_curve, lower_eta_cut=10**db.fields.find_one({"_id" : field_id}, {"selection_criteria" : 1})["selection_criteria"]["eta"])
        if plot: plot_lc(bad_light_curve)

    logger.info("---------------------------------------------------")
    logger.info(greenText("Simulated light curves"))
    logger.info("---------------------------------------------------")

    # Simulated light curves
    for field_id,mjd in [(4721,periodic_light_curve.mjd)]:
        for err in [0.01, 0.05, 0.1]:
            logger.debug("field: {0}, err: {1}".format(field_id,err))
            light_curve = SimulatedLightCurve(mjd=mjd, mag=15, error=[err])
            light_curve.indices = pa.compute_variability_indices(light_curve, indices=["eta", "delta_chi_squared", "j", "k", "sigma_mu"])
            assert not pa.iscandidate(light_curve, lower_eta_cut=10**db.fields.find_one({"_id" : field_id}, {"selection_criteria" : 1})["selection_criteria"]["eta"])

            light_curve.add_microlensing_event(u0=np.random.uniform(0.2, 0.8), t0=light_curve.mjd[int(len(light_curve)/2)], tE=light_curve.baseline/8.)
            light_curve.indices = pa.compute_variability_indices(light_curve, indices=["eta", "delta_chi_squared", "j", "k", "sigma_mu"])
            if plot:
                plt.clf()
                light_curve.plot()
                plt.savefig("plots/tests/{0}_{1}.png".format(field_id,err))
            assert pa.iscandidate(light_curve, lower_eta_cut=10**db.fields.find_one({"_id" : field_id}, {"selection_criteria" : 1})["selection_criteria"]["eta"])

    logger.info("---------------------------------------------------")
    logger.info(greenText("Transient light curves"))
    logger.info("---------------------------------------------------")

    # Transients (SN, Novae)
    transients = [(4564, 0, 4703), (4914, 6, 9673), (100041, 1, 4855), (100082, 5, 7447), (4721, 8, 3208), (4445, 7, 11458),\
                  (100003, 6, 10741), (100001, 10, 5466), (4789, 6, 11457), (2263, 0, 3214), (4077, 8, 15293), (4330, 10, 6648), \
                  (4913, 7, 13436), (100090, 7, 2070), (4338, 2, 10330), (5171, 0, 885)]

    for field_id, ccd_id, source_id in transients:
        transient_light_curve = pdb.get_light_curve(field_id, ccd_id, source_id, clean=True)
        logger.debug(transient_light_curve)
        transient_light_curve.indices = pa.compute_variability_indices(transient_light_curve, indices=["eta", "delta_chi_squared", "j", "k", "sigma_mu"])
        assert pa.iscandidate(transient_light_curve, lower_eta_cut=10**db.fields.find_one({"_id" : field_id}, {"selection_criteria" : 1})["selection_criteria"]["eta"])
        if plot: plot_lc(transient_light_curve)
예제 #4
0
파일: paper_figures.py 프로젝트: adrn/PTF
def microlensing_event_sim():
    """ Create the multi-panel figure with simulated microlensing events for a single
        'typical' PTF light curve.
    """

    #field = pdb.Field(100062, "R")
    #ccd = field.ccds[1]
    #chip = ccd.read()
    #sources = chip.sources.readWhere("(ngoodobs > 300) & (vonNeumannRatio > 1.235)")
    #light_curve = ccd.light_curve(sources["matchedSourceID"][np.random.randint(0, len(sources))], clean=True)
    #print sources["matchedSourceID"]
    light_curve = pdb.get_light_curve(100062, 1, 13268, clean=True)

    num = 4
    fig, axes = plt.subplots(num,1, sharex=True, figsize=(11,15))

    sim_light_curve = SimulatedLightCurve(mjd=light_curve.mjd, mag=light_curve.mag, error=light_curve.error)

    t0 = sim_light_curve.mjd[int(len(sim_light_curve.mjd)/2)]

    kwarg_list = [None, {"u0" : 1.0, "t0" : t0, "tE" : 20},
                        {"u0" : 0.5, "t0" : t0, "tE" : 20},
                        {"u0" : 0.01, "t0" : t0, "tE" : 20}]

    args_list = [(16.66, "a)"), (16.4, "b)"), (16.0, "c)"), (12, "d)")]
    args_list2 = [16.68, 16.5, 16.2, 13]

    for ii in range(num):
        axes[ii].xaxis.set_visible(False)

        if ii != 0:
            #sim_light_curve.reset()
            sim_light_curve = SimulatedLightCurve(mjd=light_curve.mjd, mag=light_curve.mag, error=light_curve.error)
            sim_light_curve.add_microlensing_event(**kwarg_list[ii])

        sim_light_curve.plot(axes[ii], marker="o", ms=3, alpha=0.75)

        axes[ii].axhline(14.3, color='r', linestyle="--")

        if kwarg_list[ii] == None:
            u0_str = ""
        else:
            u0 = kwarg_list[ii]["u0"]
            u0_str = r"$u_0={:.2f}$".format(u0)
        #axes[ii].set_ylabel(u0_str, rotation="horizontal")

        #for tick in axes[ii].yaxis.get_major_ticks():
        #    tick.label.set_fontsize(tick_font_size)

        if ii == 0:
            [tick.set_visible(False) for jj,tick in enumerate(axes[ii].get_yticklabels()) if jj % 2 != 0]

        if ii % 2 != 0:
            axes[ii].yaxis.tick_right()
        else:
            axes[ii].yaxis.set_label_position("right")

        if ii == 0:
            axes[ii].set_ylabel(r"$R$", rotation="horizontal", fontsize=26)
            axes[ii].yaxis.set_label_position("left")

        axes[ii].text(56100, *args_list[ii], fontsize=24)
        axes[ii].text(56100, args_list2[ii], u0_str, fontsize=24)

    #fig.suptitle("PTF light curve with simulated microlensing events", fontsize=24)

    for ax in fig.axes:
        for ticklabel in ax.get_yticklabels():
            ticklabel.set_fontsize(18)

    fig.subplots_adjust(hspace=0.0, left=0.1, right=0.9)
    fig.savefig(os.path.join(pg.plots_path, "paper_figures", "simulated_events.pdf"), bbox_inches="tight", facecolor="white")