Пример #1
0
def test_accessor_k2_campaign():
    # scaled down version of tess sector test, as they share the same codepath
    lc0 = KeplerLightCurve(
        time=np.arange(1, 5),
        flux=np.arange(1, 5),
        flux_err=np.arange(1, 5),
        targetid=50000,
    )
    lc0.meta["CAMPAIGN"] = 2
    lc1 = KeplerLightCurve(
        time=np.arange(10, 15),
        flux=np.arange(10, 15),
        flux_err=np.arange(10, 15),
        targetid=120334,
    )
    lc1.meta["CAMPAIGN"] = 1
    lcc = LightCurveCollection([lc0, lc1])
    assert (lcc.campaign == [2, 1]).all()

    # ensure it works for TPFs too.
    tpf0 = KeplerTargetPixelFile(filename_tpf_all_zeros)
    tpf0.hdu[0].header["CAMPAIGN"] = 2
    tpf1 = KeplerTargetPixelFile(filename_tpf_one_center)
    tpf1.hdu[0].header["CAMPAIGN"] = 1
    tpfc = TargetPixelFileCollection([tpf0, tpf1])
    assert (tpfc.campaign == [2, 1]).all()
Пример #2
0
def test_tpfcollection_plot():
    tpf = KeplerTargetPixelFile(filename_tpf_all_zeros)
    tpf2 = KeplerTargetPixelFile(filename_tpf_one_center)
    # Does plotting work with 3 TPFs?
    coll = TargetPixelFileCollection([tpf, tpf2, tpf2])
    coll.plot()
    # Does plotting work with one TPF?
    coll = TargetPixelFileCollection([tpf])
    coll.plot()
    plt.close("all")
Пример #3
0
def test_accessor_tess_sector():
    lc0 = TessLightCurve(
        time=np.arange(1, 5),
        flux=np.arange(1, 5),
        flux_err=np.arange(1, 5),
        targetid=50000,
    )
    lc0.meta["SECTOR"] = 14
    lc1 = TessLightCurve(
        time=np.arange(10, 15),
        flux=np.arange(10, 15),
        flux_err=np.arange(10, 15),
        targetid=120334,
    )
    lc1.meta["SECTOR"] = 26
    lcc = LightCurveCollection([lc0, lc1])
    assert (lcc.sector == [14, 26]).all()
    # The sector accessor can be used to generate boolean array
    # to support filter collection by sector
    assert ((lcc.sector == 26) == [False, True]).all()
    assert ((lcc.sector < 20) == [True, False]).all()

    # boundary condition: some lightcurve objects do not have sector
    lc2 = LightCurve(
        time=np.arange(15, 20),
        flux=np.arange(15, 20),
        flux_err=np.arange(15, 20),
        targetid=23456,
    )
    lcc.append(lc2)
    # expecting [14, 26, np.nan], need 2 asserts to do it.
    assert (lcc.sector[:-1] == [14, 26]).all()
    assert np.isnan(lcc.sector[-1])
    # The sector accessor can be used to generate boolean array
    # to support filter collection by sector
    assert ((lcc.sector == 26) == [False, True, False]).all()
    assert ((lcc.sector < 20) == [True, False, False]).all()

    # ensure it works for TPFs too.
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", LightkurveWarning)
        # Ignore "A Kepler data product is being opened using the `TessTargetPixelFile` class"
        # the test only cares about the SECTOR header that it sets.
        tpf = TessTargetPixelFile(filename_tpf_all_zeros)
        tpf.hdu[0].header["SECTOR"] = 23
        tpf2 = TessTargetPixelFile(filename_tpf_one_center)
        # tpf2 has no sector defined
        tpf3 = TessTargetPixelFile(filename_tpf_one_center)
        tpf3.hdu[0].header["SECTOR"] = 1
    tpfc = TargetPixelFileCollection([tpf, tpf2, tpf3])
    assert (tpfc.sector == [23, None, 1]).all()
Пример #4
0
def test_tpfcollection():
    tpf = KeplerTargetPixelFile(filename_tpf_all_zeros)
    tpf2 = KeplerTargetPixelFile(filename_tpf_one_center)
    tpfc = TargetPixelFileCollection([tpf, tpf2])
    assert len(tpfc) == 2
    assert tpfc.data == [tpf, tpf2]
    tpfc.append(tpf2)
    assert len(tpfc) == 3
    assert tpfc[0] == tpf
    assert tpfc[1] == tpf2
    assert tpfc[2] == tpf2
    with pytest.raises(IndexError):
        tpfc[51]
    # ensure index by boolean array also works for TPFs
    tpfc_f = tpfc[[False, True, True]]
    assert tpfc_f.data == [tpf2, tpf2]
    assert type(tpfc_f) is TargetPixelFileCollection
    # Test __setitem__
    tpf3 = KeplerTargetPixelFile(filename_tpf_one_center, targetid=55)
    tpfc[1] = tpf3
    assert tpfc[1] == tpf3
    tpfc.append(tpf2)
    assert tpfc[2] == tpf2
    str(tpfc)  # Regression test for #564