def test_epoch(): tce = Tce(period=25 * u.day, epoch=1000 * u.day, epoch_offset=const.bkjd, duration=1 * u.hr, depth=1 * const.ppk) # BTJD is after BKJD epoch_btjd = tce.get_epoch(const.btjd) np.isclose( epoch_btjd, (2_454_833 - 2_457_000 + 1000) * u.day)
def test_required_quantity_missing(): with pytest.raises(KeyError, match='Missing required quantities'): Tce(period=25 * u.day) with pytest.raises(TypeError, match='Special param period must be an ' 'astropy Quantity'): Tce(period=25, epoch=0 * u.day, epoch_offset=0 * u.day, duration=1 * u.hr, depth=1 * const.ppk) tce = Tce(period=25 * u.day, epoch=0 * u.day, epoch_offset=0 * u.day, duration=1 * u.hr, depth=1 * const.ppk) with pytest.raises(TypeError, match='Special param depth must be an ' 'astropy Quantity'): tce["depth"] = 1000
def test_sweet_vetter(): """Tests the interface of the Sweet vetter class, without worrying about the correctness of the implementation """ period = 8. * u.day epoch_bkjd = 133. * u.day duration = 4.0 * u.hour target_name = "Dummy Data" event_name = "Data used to test the interface" tce = Tce(period=period, epoch=epoch_bkjd, epoch_offset=exo_const.bkjd, duration=duration, depth=0 * exo_const.frac_amp, target_name=target_name, event_name=event_name) # from lightkurve.lightcurve import LightCurve rng = np.random.default_rng(seed=1234) time = np.arange(1000) flux = 10 + rng.standard_normal(1000) lc = LightCurve(time, flux, time_format='bkjd') sweet_vetter = Sweet() res = sweet_vetter.run(tce, lc) sweet_vetter.plot() assert isinstance(res, dict) assert 'msg' in res.keys() assert 'amp' in res.keys() amp = res['amp'] assert amp.ndim == 2 assert amp.shape == (3, 3)
def test_kplr10417986(): """Integration test""" filename = download_file( 'https://archive.stsci.edu/missions/kepler/lightcurves/0104/010417986/kplr010417986-2010174085026_llc.fits', cache=True) # noqa period = .0737309 * u.day epoch_mbjd = 55000.027476 * u.day duration = 1 * u.hour target_name = "KPLR 010417986" event_name = "False Positive" epoch_bkjd = epoch_mbjd - exo_const.mbjd + exo_const.bkjd tce = Tce(period=period, epoch=epoch_bkjd, epoch_offset=exo_const.bkjd, duration=duration, depth=0 * exo_const.frac_amp, target_name=target_name, event_name=event_name) lcf = lc_read(filename) lc = lcf.PDCSAP_FLUX sweet_vetter = Sweet() res = sweet_vetter.run(tce, lc) amp = res['amp'] assert_allclose(amp[0, 0], 637, atol=30) # Amplitude assert_allclose(amp[0, 2], 106.94, atol=10) # SNR
def test_json_io(): input_file = get_pkg_data_filename("data/tce-test.json") atce = Tce.from_json(input_file) assert np.isclose(atce["period"].value, 0.830002, atol=1e-7) assert atce["period"].unit == "d" assert atce["sector"] == 14
def test_misc_quantity(): tce = Tce(kepid=1234, period=25 * u.day, epoch=0 * u.day, epoch_offset=0 * u.day, duration=1 * u.hr, depth=1 * const.ppk) tce["note"] = "This is a comment" assert np.isclose(tce["period"], 25 * u.day) assert tce["kepid"] == 1234 assert tce["note"] == "This is a comment"
def test_setting_values(): tce = Tce( period=1*u.day, epoch=1*u.day, duration=2*u.h, depth=1*const.ppm, epoch_offset=const.bkjd ) tce['duration'] = 5 * u.h assert tce['duration'] == 5 * u.h, tce
def get_wasp18_tce(): tce = Tce( period=0.94124 * u.day, epoch=58374.669883 * u.day, epoch_offset=-2400000.5 * u.day, depth=0.00990112 * exo_const.frac_amp, duration=0.08932 * u.day, event_name="WASP-18 b", target_name="WASP-18", snr=50, ) return tce
def test_get_model(epoch_val, ans_argmin): period = 100 * u.day epoch_bkjd = epoch_val * u.day tce = Tce(period=period, epoch=epoch_bkjd, epoch_offset=const.bkjd, depth=1 * const.ppk, duration=1 * u.hour) times = np.linspace(0 * u.day, period, 2400) model = create_box_model_for_tce(tce, times, const.bkjd) assert np.sum(model < 0) == 1 assert np.sum(model > 0) == 0 assert np.isclose(np.min(model), -1e-3) assert np.argmin(model) == ans_argmin
def test_one_lpp(): """"Use case is to get values for one TCE.""" period = 3.5224991 * u.day tzero = (54953.6193 + 2400000.5 - 2454833.0) * u.day duration = 3.1906 * u.hour depth = 0.009537 * const.frac_amp target_name = "Kepler-8" event_name = "Kepler-8 b" tce = Tce(period=period, epoch=tzero, duration=duration, target_name=target_name, depth=depth, event_name=event_name, epoch_offset=0 * u.day, snr=10) # Specify the lightcurve to vet mission = "Kepler" q = 4 # Generic function that runs lightkurve and returns a lightkurve object lcf = search_lightcurve(target_name, quarter=q, mission=mission, exptime=1800).download(flux_column="sap_flux") lc = lcf.remove_nans().remove_outliers() flat = lc.flatten(window_length=81) flat.flux = flat.flux.value - 1.0 # Use default .mat file from SourceForge lpp = vetters.Lpp(lc_name="flux", map_filename=None) _ = lpp.run(tce, flat) # Accepted value if data doesn't change assert_allclose(lpp.norm_lpp, 0.17, atol=0.09)
def get_mast_tce(name): """ Populate a TCE object using the mast database Parameters ---------- name : str Star name, TCE, or TOI Returns ------- tce : tce.Tce object populates the object with period, epoch, epoch_offset, depth, duration """ import requests from exovetter.tce import Tce import astropy.units as u from exovetter import const planeturl = "https://exo.mast.stsci.edu/api/v0.1/exoplanets/" header = {} url = planeturl + name + "/properties/" r = requests.get(url = url, headers = header) if len(r.json()) < 1: print("No TCE Information was returned from MAST.") return [] tces = [] for prop in r.json(): try: period = prop['orbital_period'] punit = prop['orbital_period_unit'] epoch = prop['transit_time'] epoch_offset_str = 'mjd' depth = prop['transit_depth'] duration = prop['transit_duration'] if duration is None: duration = 0 durunit = prop['transit_duration_unit'] if durunit is None: durunit = "d" atce = Tce(period = period * u.__dict__[punit], epoch = epoch * u.d, epoch_offset = const.__dict__['string_to_offset'][epoch_offset_str], depth = depth * const.frac_amp, duration = duration * u.__dict__[durunit], target = name ) tces.append(atce) except: print("An exception was thrown.") prop pass return tces