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()
def test_collection_append(): """Does Collection.append() work?""" lc = LightCurve( time=np.arange(1, 5), flux=np.arange(1, 5), flux_err=np.arange(1, 5), targetid=500, ) lc2 = LightCurve( time=np.arange(10, 15), flux=np.arange(10, 15), flux_err=np.arange(10, 15), targetid=100, ) lcc = LightCurveCollection([lc]) lcc.append(lc2) assert len(lcc) == 2
def test_collection_getitem(): """Tests Collection.__getitem__""" lc = LightCurve( time=np.arange(1, 5), flux=np.arange(1, 5), flux_err=np.arange(1, 5), targetid=50000, ) lc2 = LightCurve( time=np.arange(10, 15), flux=np.arange(10, 15), flux_err=np.arange(10, 15), targetid=120334, ) lcc = LightCurveCollection([lc]) lcc.append(lc2) assert (lcc[0] == lc).all() assert (lcc[1] == lc2).all() with pytest.raises(IndexError): lcc[50]
def test_collection_setitem(): """Tests Collection. __setitem__""" lc = LightCurve( time=np.arange(1, 5), flux=np.arange(1, 5), flux_err=np.arange(1, 5), targetid=50000, ) lc2 = LightCurve( time=np.arange(10, 15), flux=np.arange(10, 15), flux_err=np.arange(10, 15), targetid=120334, ) lcc = LightCurveCollection([lc]) lcc.append(lc2) lc3 = LightCurve(time=[1], targetid=55) lcc[1] = lc3 assert lcc[1].time == lc3.time lcc.append(lc2) assert (lcc[2].time == lc2.time).all() with pytest.raises(IndexError): lcc[51] = 10