Exemple #1
0
def test_searchresult():
    sr = search_lightcurve("Kepler-10", mission="Kepler")
    assert len(sr) == len(sr.table)  # Tests SearchResult.__len__
    assert len(sr[2:7]) == 5  # Tests SearchResult.__get__
    assert len(sr[2]) == 1
    assert "kplr" in sr.__repr__()
    assert "kplr" in sr._repr_html_()
Exemple #2
0
def test_collections():
    # TargetPixelFileCollection class
    assert (len(
        search_targetpixelfile("EPIC 205998445", mission="K2",
                               radius=900).table) == 4)
    # LightCurveFileCollection class with set targetlimit
    assert (len(
        search_lightcurve("EPIC 205998445",
                          mission="K2",
                          radius=900,
                          limit=3,
                          author="K2").download_all()) == 3)
    # if fewer targets are found than targetlimit, should still download all available
    assert (len(
        search_targetpixelfile("EPIC 205998445",
                               mission="K2",
                               radius=900,
                               limit=6).table) == 4)
    # if download() is used when multiple files are available, should only download 1
    with pytest.warns(LightkurveWarning,
                      match="4 files available to download"):
        assert isinstance(
            search_targetpixelfile("EPIC 205998445",
                                   mission="K2",
                                   radius=900,
                                   author="K2").download(),
            KeplerTargetPixelFile,
        )
Exemple #3
0
def test_stitch_repr():
    """Regression test for #884."""
    lc = search_lightcurve("Pi Men", mission="TESS", author="SPOC",
                           sector=1).download()
    # The line below used to raise `ValueError: Unable to parse format string
    # "{:10d}" for entry "70445.0" in column "cadenceno"`
    LightCurveCollection((lc, lc)).stitch().__repr__()
Exemple #4
0
def test_spoc_ffi_lightcurve():
    """Can we search and download a SPOC FFI light curve?"""
    search = search_lightcurve("TrES-2b", sector=26, author="tess-spoc")
    assert len(search) == 1
    assert search.author[0] == "TESS-SPOC"
    assert search.exptime[0] == 30 * u.minute  # Sector 26 had 30-minute FFIs
    lc = search.download()
    all(lc.flux == lc.pdcsap_flux)
Exemple #5
0
def test_qlp_ffi_lightcurve():
    """Can we search and download an MIT QLP FFI light curve?"""
    search = search_lightcurve("TrES-2b", sector=26, author="qlp")
    assert len(search) == 1
    assert search.author[0] == "QLP"
    assert search.exptime[0] == 30 * u.minute  # Sector 26 had 30-minute FFIs
    lc = search.download()
    all(lc.flux == lc.kspsap_flux)
Exemple #6
0
def test_indexerror_631():
    """Regression test for #631; avoid IndexError."""
    # This previously triggered an exception:
    result = search_lightcurve("KIC 8462852",
                               sector=15,
                               radius=1,
                               author="spoc")
    assert len(result) == 1
Exemple #7
0
def test_asteroseismology():
    datalist = search_lightcurve("KIC11615890")
    data = datalist.download_all()
    lc = data[0].normalize().flatten()
    for nlc in data[0:5]:
        lc = lc.append(nlc.normalize().flatten())
    lc = lc.remove_nans()
    pg = lc.to_periodogram(normalization="psd")
    snr = pg.flatten()
    snr.to_seismology().estimate_numax()
Exemple #8
0
def test_overlapping_targets_718():
    """Regression test for #718."""
    # Searching for the following targets without radius should only return
    # the requested targets, not their overlapping neighbors.
    targets = ["KIC 5112705", "KIC 10058374", "KIC 5385723"]
    for target in targets:
        search = search_lightcurve(target, quarter=11)
        assert len(search) == 1
        assert search.target_name[0] == f"kplr{target[4:].zfill(9)}"

    # When using `radius=1` we should also retrieve the overlapping targets
    search = search_lightcurve("KIC 5112705", quarter=11, radius=1 * u.arcsec)
    assert len(search) > 1

    # Searching by `target_name` should not preven a KIC identifier to work
    # in a TESS data search
    search = search_targetpixelfile(
        "KIC 8462852", mission="TESS", sector=15, author="spoc"
    )
    assert len(search) == 1
Exemple #9
0
def test_ffi_hlsp():
    """Can SPOC, QLP (FFI), and TESS-SPOC (FFI) light curves be accessed?"""
    search = search_lightcurve(
        "TrES-2b", mission="tess", author="any", sector=26
    )  # aka TOI 2140.01
    assert "QLP" in search.table["author"]
    assert "TESS-SPOC" in search.table["author"]
    assert "SPOC" in search.table["author"]
    # tess-spoc also products tpfs
    search = search_targetpixelfile("TrES-2b", mission="tess", author="any", sector=26)
    assert "TESS-SPOC" in search.table["author"]
    assert "SPOC" in search.table["author"]
Exemple #10
0
def test_exptime_filtering():
    """Can we pass "fast", "short", exposure time to the cadence argument?"""
    # Try `cadence="fast"`
    res = search_lightcurve("AU Mic", sector=27, cadence="fast")
    assert len(res) == 1
    assert res.exptime[0].value == 20
    # Try `cadence="short"`
    res = search_lightcurve("AU Mic", sector=27, cadence="short")
    assert len(res) == 1
    assert res.table["t_exptime"][0] == 120
    # Try `cadence=20`
    res = search_lightcurve("AU Mic", sector=27, cadence=20)
    assert len(res) == 1
    assert res.table["t_exptime"][0] == 20
    assert "fast" in res.table["productFilename"][0]

    # Now do the same with the new exptime argument,
    # because `cadence` may be deprecated.
    # Try `exptime="fast"`
    res = search_lightcurve("AU Mic", sector=27, exptime="fast")
    assert len(res) == 1
    assert res.exptime[0].value == 20
    # Try `exptime="SHoRt"` -- mixed lower/uppercase is on purpose
    res = search_lightcurve("AU Mic", sector=27, exptime="SHoRt")
    assert len(res) == 1
    assert res.table["t_exptime"][0] == 120
    # Try `exptime=20`
    res = search_lightcurve("AU Mic", sector=27, exptime=20)
    assert len(res) == 1
    assert res.table["t_exptime"][0] == 20
    assert "fast" in res.table["productFilename"][0]
    def download_lightcurves(self, remove_fits=True):
        """
        Downloads light curves for the training, validation, and
        test sets. 

        Parameters
        ----------
        remove_fits : bool, optional
             Allows the user to remove the TESS light curveFITS 
             files when done. This will save space. Default is True.
        """
        if self.flare_table is None:
            self.flare_table = Table.read(os.path.join(
                self.fn_dir, self.flare_catalog_name),
                                          format='ascii')

        tics = np.unique(self.flare_table['TIC'])
        npy_name = '{0:09d}_sector{1:02d}.npy'

        for i in tqdm(range(len(tics))):
            slc = search_lightcurve('TIC' + str(tics[i]),
                                    mission='TESS',
                                    exptime=120,
                                    sector=[1, 2],
                                    author='SPOC')

            if len(slc) > 0:
                lcs = slc.download_all(download_dir=self.fn_dir)

                for j in range(len(lcs)):
                    # Default lightkurve flux = pdcsap_flux
                    lc = lcs[j].normalize()

                    np.save(
                        os.path.join(self.fn_dir,
                                     npy_name.format(tics[i], lc.sector)),
                        np.array(
                            [lc.time.value, lc.flux.value, lc.flux_err.value]))

                    # Removes FITS files when done
                    if remove_fits == True:
                        for dp, dn, fn in os.walk(
                                os.path.join(self.fn_dir, 'mastDownload')):
                            for file in [f for f in fn if f.endswith('.fits')]:
                                os.remove(os.path.join(dp, file))
                                os.rmdir(dp)

        if remove_fits == True:
            os.rmdir(os.path.join(self.fn_dir, 'mastDownload/TESS'))
            os.rmdir(os.path.join(self.fn_dir, 'mastDownload'))
Exemple #12
0
def test_predict():
    from lightkurve.search import search_lightcurve

    lk = search_lightcurve(target='tic62124646',
                           mission='TESS',
                           sector=13,
                           exptime=120,
                           author='SPOC')
    lk = lk.download(download_dir='.')  #.PDCSAP_FLUX
    lk = lk.remove_nans()

    cnn.predict(modelname='ensemble_s0002_i0010_b0.73.h5',
                times=lk.time.value,
                fluxes=lk.flux.value,
                errs=lk.flux_err.value)
    assert (cnn.predictions.shape == (1, 17939))
    assert_almost_equal(cnn.predictions[0][1000], 0.3, decimal=1)
Exemple #13
0
def test_search_lightcurve(caplog):
    # We should also be able to resolve it by its name instead of KIC ID
    assert (len(
        search_lightcurve("Kepler-10", mission="Kepler",
                          cadence="long").table) == 15)
    # An invalid KIC/EPIC ID or target name should be dealt with gracefully
    search_lightcurve(-999)
    assert "Could not resolve" in caplog.text
    search_lightcurve("DOES_NOT_EXIST (UNIT TEST)")
    assert "Could not resolve" in caplog.text
    # If we ask for all cadence types, there should be four Kepler files given
    assert len(
        search_lightcurve("KIC 4914423", quarter=6, cadence="any").table) == 4
    # ...and only one should have long cadence
    assert len(
        search_lightcurve("KIC 4914423", quarter=6, cadence="long").table) == 1
    # Should be able to resolve an ra/dec
    assert len(search_lightcurve("297.5835, 40.98339", quarter=6).table) == 1
    # Should be able to resolve a SkyCoord
    c = SkyCoord("297.5835 40.98339", unit=(u.deg, u.deg))
    search = search_lightcurve(c, quarter=6)
    assert len(search.table) == 1
    assert len(search) == 1
    # We should be able to download a light curve
    search.download()
    # The second call to download should use the local cache
    caplog.clear()
    caplog.set_level("DEBUG")
    search.download()
    assert "found in local cache" in caplog.text
    # with mission='TESS', it should return TESS observations
    tic = "TIC 273985862"
    assert len(search_lightcurve(tic, mission="TESS").table) > 1
    assert (len(
        search_lightcurve(tic,
                          mission="TESS",
                          author="spoc",
                          sector=1,
                          radius=100).table) == 2)
    search_lightcurve(tic, mission="TESS", author="SPOC", sector=1).download()
    assert len(search_lightcurve("pi Mensae", author="SPOC",
                                 sector=1).table) == 1
Exemple #14
0
def test_search_slicing_regression():
    # Regression test: slicing after calling __repr__ failed.
    res = search_lightcurve("AU Mic", exptime=20)
    res.__repr__()
    res[res.exptime.value < 100]
Exemple #15
0
def test_download_flux_column():
    """Can we pass reader keyword arguments to the download method?"""
    lc = search_lightcurve("Pi Men", author="SPOC",
                           sector=12).download(flux_column="sap_flux")
    assert_array_equal(lc.flux, lc.sap_flux)
Exemple #16
0
from stella.rotations import MeasureProt
from lightkurve.search import search_lightcurve
from numpy.testing import assert_almost_equal

lk = search_lightcurve(target='tic62124646',
                       mission='TESS',
                       exptime=120,
                       sector=13,
                       author='SPOC')
lk = lk.download(download_dir='.')
lk = lk.remove_nans().normalize()

mProt = MeasureProt([lk.targetid], [lk.time.value], [lk.flux.value],
                    [lk.flux_err.value])
mProt.run_LS()


def test_measurement():
    assert_almost_equal(mProt.LS_results['period_days'], 3.2, decimal=1)
    assert (mProt.LS_results['Flags'] == 0)