Basic FULMAR usage. Using K2-109 as an example

This system contains two known exoplanets. For more information, have a look at Barros et al. 2017

Let’s start by importing common modules

[1]:
import fulmar
import numpy as np
import matplotlib.pyplot as plt
import astropy.units as u
from transitleastsquares import transit_mask
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

Define target

[2]:
lc_targ = fulmar.target('K2-109') # aka. HD 106315
WARNING: UnitsWarning: Unit 'Rsun' not supported by the VOUnit standard.  [astropy.units.format.vounit]
WARNING: UnitsWarning: Unit 'Msun' not supported by the VOUnit standard.  [astropy.units.format.vounit]

Update stellar parameters if necessary

[3]:
# K2-109 parameters from Barros et al. 2017 (https://www.aanda.org/articles/aa/pdf/2017/12/aa31276-17.pdf)
lc_targ.R_star = 1.296
lc_targ.R_star_max = 0.058
lc_targ.R_star_min = 0.058

lc_targ.M_star = 1.091
lc_targ.M_star_max = 0.036
lc_targ.M_star_min = 0.036

Build the lightcurve

[4]:
lc_targ.build_lightcurve(author='EVEREST')
Searching for lightcurves
Warning: 25% (851/3384) of the cadences will be ignored due to the quality mask (quality_bitmask=1130799).
Warning: 25% (851/3384) of the cadences will be ignored due to the quality mask (quality_bitmask=1130799).
['K2 Campaign 102']
1 Lightcurves found
Downloading Lightcurves
[4]:
TimeSeries length=2533
timefluxflux_errcadnfrawcadencenofraw_errqualityfcorcbv01cbv02cbv03cbv04cbv05cbv06exptime
electron / selectron / selectron / ss
Timefloat64float64float64float64float64float64int32float64float64float64float64float64float64float64float64
2749.58995339413380.9919362273818925nan129231.03616934.469760895129231.047.4133457561224255242883618895.82392130141.04.0326018130621833.721325487340294-0.62729987225031352.75803522396945060.94496936077676821800.0
2749.61038542845930.9919057528017547nan129232.03616898.694656372129232.047.420606055378303618797.795774931.04.0364453031006023.709970058424757-0.6394826529697442.73377450187055170.94137117690342841800.0
2749.63081736232560.9920318018415252nan129233.03617448.0032958984129233.047.4348262763665503619268.6471231061.04.0402638719398553.698637940508874-0.65160199992492212.70959095565915350.93778230161215271800.0
2749.65124919595840.9919802015869569nan129234.03617286.1815719604129234.047.4462583529729703619093.662134571.04.0440575557652723.687329095681801-0.66365802077563572.6854844858070060.93420271828859641800.0
2749.67168122935250.992301349055998nan129235.03618496.683452606129235.047.46915206559436503620273.52982039841.04.0478263907621823.676043486032692-0.67565082318167312.66145499278585970.9306324103184151800.0
2749.69211316228760.9923487483914822nan129236.03618750.0302505493129236.047.4821109386744503620458.24287436441.04.0515704131159173.664781073650703-0.68758051480282252.63750237706746570.92707136108726421800.0
2749.7125449947560.9923954335698577nan129237.03618955.9937667847129237.047.4944854038991703620640.2778030661.04.0552896590118053.6535418206249886-0.69944720329887172.6136265391235740.92351955398079921800.0
2749.7329770272190.9925266324082855nan129238.03619466.253112793129238.047.50783439566773603621129.437180821.04.0589841646351783.642325689044705-0.71125099632960892.5898273794259350.91997697238467571800.0
2749.753408958990.9925245517214502nan129239.03619449.8608169556129239.047.5205186273302103621134.04458832831.04.0626539661713633.6311326409990063-0.72299200155482232.56610479844630040.9164435996845491800.0
2749.773840790760.992604148341398nan129240.03619830.804801941129240.047.5414812860888803621435.46656276841.04.06629909980569253.6199626385770487-0.73467032663429992.54245869665641950.91291941926607461800.0
2749.79427282205870.9925338870317024nan129241.03619638.970149994129241.047.5615780681344403621192.0744356451.04.06991960172349553.6088156438679864-0.74628607922782992.51888897452804360.9094044145149081800.0
2749.81470475289830.9926073018860605nan129242.03620092.708744049129242.047.590407035130403621470.86248074841.04.0735155081101023.5976916189609756-0.75783936699520042.49539553253292250.90589856881670471800.0
2749.8351365837370.9926726508159865nan129243.03620588.7246055603129243.047.6126159253186742024963621720.2495034331.04.0770868551508423.5865905259451702-0.76933029759619932.47197827114280780.90240186555712021800.0
2749.85556861387160.9928366016424158nan129244.03621590.49723053129244.047.6344691369141403622327.97232542931.04.0806336790310453.5755123269097266-0.7807589786906152.4486370908294490.898914288121811800.0
................................................
2818.4041014524411.0005970765947736nan132599.03633293.7000579834132599.047.8218626189940103629823.6011308871.0-2.1651051353042270.34304411454921263.43830542441204920.188773666996963853.53611330389744531800.0
2818.424533507031.0005313477783007nan132600.03633612.672267914132600.047.8243237141838103629576.24797599581.0-2.16764683934144160.357427419150561533.4760593688461860.18782928161142233.5647698820239161800.0
2818.4449653620831.0004984893450761nan132601.03633727.3173980713132601.047.8298927457173303629448.3073313491.0-2.1702099753471640.37190285657780233.51397135827394360.186878248436600283.5935658109232141800.0
2818.46539731736271.0005727916549771nan132602.03634014.084197998132602.047.840208745080803629709.82391449341.0-2.17279459288323460.38647061422773893.55204166744435220.185920553244338983.6225013891208911800.0
2818.4858293731161.000549754409066nan132603.03633582.8075580597132603.047.84956118074125403629617.4405606361.0-2.17540074151148670.40113087949717513.59027057110644330.184956181806479853.65157691514251771800.0
2818.50626122910031.0006123790751411nan132604.03633667.8337860107132604.047.86266905355072503629836.36602139751.0-2.1780284707937570.41588383978291513.62865834400926260.183985119894862743.68079268751367561800.0
2818.52669328554481.000732636547247nan132605.03633621.2506580353132605.047.8820638129415703630264.7145496711.0-2.1806778302918810.43072968248176293.66720526090183170.183007353281328923.71014900475992261800.0
2818.56755709914431.0006485538181358nan132607.03633000.380264282132607.047.9286904325582903629941.28571782261.0-2.18604163818303080.4607007647059893.74477762565239840.181031649035873433.76928446797999061800.0
2818.5879891567531.0005698599427024nan132608.03632872.1142292023132608.047.8991585387295503629646.23144860751.0-2.18875618569973170.47582637902498373.78380362300845170.180033682947633943.7990642110049421800.0
2818.6084211143681.0006106855242058nan132609.03632842.7295036316132609.047.8558543694713903629785.5570854461.0-2.19149256167963060.49104562534430053.82298986335040960.17902895524484023.82898569300727141800.0
2818.62885307244871.0006010795024947nan132610.03632803.993894577132610.047.837685487587703629741.4916785471.0-2.19425081568456240.50635869106074673.86233662142730160.17801745169933333.85904921251254951800.0
2818.6492850309881.0007452818397116nan132611.03633366.8895816803132611.047.83333782418690603630256.4457417381.0-2.19703099727636350.52176576357112283.9018441719881550.176999158082954723.88925506804633431800.0
2818.6697169897671.0006993653052811nan132612.03633311.242116928132612.047.8295129405504803630080.24629519131.0-2.19983315601687130.53726703027223623.94151278978201970.175974060167544353.91960355813421041800.0
2818.6901489487791.0005968151050437nan132613.03633454.115245819132613.047.82795698316855503629698.11086238461.0-2.20265734146791830.55286267856088743.98134274955792120.17494214372494363.95009498130173231800.0
2818.71058090824951.0005499870390169nan132614.03633572.709289551132614.047.828783985360175242883629518.4517405211.0-2.20550360319134460.56855289583388414.0213343260648930.17390339452699263.9807296360744921800.0

Alternatively, build the lightcurve from files, for example data reduced with POLAR

[ ]:
filelist = [your_files_here]
[ ]:
lc_targ.build_lightcurve(filelist=filelist, author='AUTHOR')

Plot the light curve for a quick visualisation

[5]:
plt.plot(lc_targ.ts_stitch.time.value, lc_targ.ts_stitch['flux'],'k.', markersize=1.8, alpha = 0.25)

plt.xlabel('Time [{}]'.format(str(lc_targ.ts_stitch.time.format).upper()))
plt.ylabel('Flux')
plt.title(lc_targ.K2 + ' Lightcurve')
# plt.xlim(2350,2356)
# plt.ylim(0.9985,1.0015)
plt.show()
_images/example_K2-109_12_0.png

Mask Outliers

[6]:
m1 = lc_targ.mask_outliers(sigma=4)

Plot the light curve with outliers highlighted

[7]:
plt.plot(lc_targ.ts_stitch.time.value, lc_targ.ts_stitch['flux'],'k.', markersize=1.8, alpha = 0.25)
plt.plot(lc_targ.ts_stitch.time.value[~m1], lc_targ.ts_stitch['flux'][~m1],'o', color='xkcd:orange', markersize=8, alpha = 0.5)

plt.xlabel('Time [{}]'.format(str(lc_targ.ts_stitch.time.format).upper()))
plt.ylabel('Flux')
# plt.xlim(2350,2356)
# plt.ylim(0.985,1.015)
plt.show()
_images/example_K2-109_16_0.png

Remove the outliers if necessary.

[11]:
lc_targ.ts_stitch = lc_targ.ts_stitch[m1]

Clean the light curve / correct activity

Using a Savistzky-Golay filter:

[9]:
lc_targ.clean_subt_activity_flatten(sigma=3,
        wl=37,
        time_window=18*u.h,
        polyorder=2,
        return_trend=False,
        remove_outliers=True,
        break_tolerance=5,
        niters=3,
        mask=None)

# You might face issues with Astropy >= 5.0 where flatten gives TypeError: "cannot write to unmasked output"
# The issue comes from Lightkurve and a pull request has been made: https://github.com/lightkurve/lightkurve/pull/1162/commits/05034f4bbd8e6a40f8efd9cfa1f108a36ddc0872
[9]:
TimeSeries length=2476
timefluxflux_errcadnfrawcadencenofraw_errqualityfcorcbv01cbv02cbv03cbv04cbv05cbv06exptime
electron / selectron / selectron / ss
Timefloat64float64float64float64float64float64int32float64float64float64float64float64float64float64float64
2749.58995339413380.9974494072046971nan129231.03616934.469760895129231.047.4133457561224255242883618895.82392130141.04.0326018130621833.721325487340294-0.62729987225031352.75803522396945060.94496936077676821800.0
2749.61038542845930.9974552745389408nan129232.03616898.694656372129232.047.420606055378303618797.795774931.04.0364453031006023.709970058424757-0.6394826529697442.73377450187055170.94137117690342841800.0
2749.63081736232560.9976185472245636nan129233.03617448.0032958984129233.047.4348262763665503619268.6471231061.04.0402638719398553.698637940508874-0.65160199992492212.70959095565915350.93778230161215271800.0
2749.65124919595840.997603175397708nan129234.03617286.1815719604129234.047.4462583529729703619093.662134571.04.0440575557652723.687329095681801-0.66365802077563572.6854844858070060.93420271828859641800.0
2749.67168122935250.9979626771452772nan129235.03618496.683452606129235.047.46915206559436503620273.52982039841.04.0478263907621823.676043486032692-0.67565082318167312.66145499278585970.9306324103184151800.0
2749.69211316228760.9980468850219955nan129236.03618750.0302505493129236.047.4821109386744503620458.24287436441.04.0515704131159173.664781073650703-0.68758051480282252.63750237706746570.92707136108726421800.0
2749.7125449947560.9981303806009645nan129237.03618955.9937667847129237.047.4944854038991703620640.2778030661.04.0552896590118053.6535418206249886-0.69944720329887172.6136265391235740.92351955398079921800.0
2749.7329770272190.9982988878195049nan129238.03619466.253112793129238.047.50783439566773603621129.437180821.04.0589841646351783.642325689044705-0.71125099632960892.5898273794259350.91997697238467571800.0
2749.753408958990.9983333476478541nan129239.03619449.8608169556129239.047.5205186273302103621134.04458832831.04.0626539661713633.6311326409990063-0.72299200155482232.56610479844630040.9164435996845491800.0
2749.773840790760.9984499681560839nan129240.03619830.804801941129240.047.5414812860888803621435.46656276841.04.06629909980569253.6199626385770487-0.73467032663429992.54245869665641950.91291941926607461800.0
2749.79427282205870.9984158515428457nan129241.03619638.970149994129241.047.5615780681344403621192.0744356451.04.06991960172349553.6088156438679864-0.74628607922782992.51888897452804360.9094044145149081800.0
2749.81470475289830.9985262651628759nan129242.03620092.708744049129242.047.590407035130403621470.86248074841.04.0735155081101023.5976916189609756-0.75783936699520042.49539553253292250.90589856881670471800.0
2749.8351365837370.9986285723716373nan129243.03620588.7246055603129243.047.6126159253186742024963621720.2495034331.04.0770868551508423.5865905259451702-0.76933029759619932.47197827114280780.90240186555712021800.0
2749.85556861387160.9988300845596197nan129244.03621590.49723053129244.047.6344691369141403622327.97232542931.04.0806336790310453.5755123269097266-0.7807589786906152.4486370908294490.898914288121811800.0
................................................
2818.4041014524410.9999724442966103nan132599.03633293.7000579834132599.047.8218626189940103629823.6011308871.0-2.1651051353042270.34304411454921263.43830542441204920.188773666996963853.53611330389744531800.0
2818.424533507030.9999040570091818nan132600.03633612.672267914132600.047.8243237141838103629576.24797599581.0-2.16764683934144160.357427419150561533.4760593688461860.18782928161142233.5647698820239161800.0
2818.4449653620830.9998691434778788nan132601.03633727.3173980713132601.047.8298927457173303629448.3073313491.0-2.1702099753471640.37190285657780233.51397135827394360.186878248436600283.5935658109232141800.0
2818.46539731736270.999941946949921nan132602.03634014.084197998132602.047.840208745080803629709.82391449341.0-2.17279459288323460.38647061422773893.55204166744435220.185920553244338983.6225013891208911800.0
2818.4858293731160.9999180958967169nan132603.03633582.8075580597132603.047.84956118074125403629617.4405606361.0-2.17540074151148670.40113087949717513.59027057110644330.184956181806479853.65157691514251771800.0
2818.50626122910030.9999804764132937nan132604.03633667.8337860107132604.047.86266905355072503629836.36602139751.0-2.1780284707937570.41588383978291513.62865834400926260.183985119894862743.68079268751367561800.0
2818.52669328554481.0001010771465841nan132605.03633621.2506580353132605.047.8820638129415703630264.7145496711.0-2.1806778302918810.43072968248176293.66720526090183170.183007353281328923.71014900475992261800.0
2818.56755709914431.0000180904455735nan132607.03633000.380264282132607.047.9286904325582903629941.28571782261.0-2.18604163818303080.4607007647059893.74477762565239840.181031649035873433.76928446797999061800.0
2818.5879891567530.9999411127814223nan132608.03632872.1142292023132608.047.8991585387295503629646.23144860751.0-2.18875618569973170.47582637902498373.78380362300845170.180033682947633943.7990642110049421800.0
2818.6084211143680.9999842031862137nan132609.03632842.7295036316132609.047.8558543694713903629785.5570854461.0-2.19149256167963060.49104562534430053.82298986335040960.17902895524484023.82898569300727141800.0
2818.62885307244870.9999775174168674nan132610.03632803.993894577132610.047.837685487587703629741.4916785471.0-2.19425081568456240.50635869106074673.86233662142730160.17801745169933333.85904921251254951800.0
2818.6492850309881.0001251684302048nan132611.03633366.8895816803132611.047.83333782418690603630256.4457417381.0-2.19703099727636350.52176576357112283.9018441719881550.176999158082954723.88925506804633431800.0
2818.6697169897671.0000834425946967nan132612.03633311.242116928132612.047.8295129405504803630080.24629519131.0-2.19983315601687130.53726703027223623.94151278978201970.175974060167544353.91960355813421041800.0
2818.6901489487790.999985741152896nan132613.03633454.115245819132613.047.82795698316855503629698.11086238461.0-2.20265734146791830.55286267856088743.98134274955792120.17494214372494363.95009498130173231800.0
2818.71058090824950.9999443509089974nan132614.03633572.709289551132614.047.828783985360175242883629518.4517405211.0-2.20550360319134460.56855289583388414.0213343260648930.17390339452699263.9807296360744921800.0

Alternatively, using GP:

[10]:
lc_targ.clean_subt_activity_GP(
            timeseries=None,
            bin_duration=60 * u.min,
            period_min=0.2,
            period_max=100.0,
            tune=2500,
            draws=2500,
            chains=2,
            target_accept=0.95,
            ncores=None,
            return_trend=False,
            remove_outliers=True,
            sigma_out=3,
            mask=None)
 /home/jrodrigues/fulmar_venv/lib64/python3.9/site-packages/astropy/timeseries/downsample.py:28: RuntimeWarning: Mean of empty slice /home/jrodrigues/fulmar_venv/lib64/python3.9/site-packages/astropy/timeseries/downsample.py:26: RuntimeWarning: Mean of empty slice /home/jrodrigues/fulmar_venv/lib64/python3.9/site-packages/astropy/timeseries/downsample.py:29: RuntimeWarning: Mean of empty slice
guessed period is 24.03185320009876 days
optimizing logp for variables: [f, log_dQ, log_Q0, log_period, sigma_rot, rho, sigma, log_jitter, mean]
100.00% [36/36 00:00<00:00 logp = -2.258e+03]

message: Optimization terminated successfully.
logp: -2793.754777544708 -> -2258.111803771446
Multiprocess sampling (2 chains in 8 jobs)
NUTS: [f, log_dQ, log_Q0, log_period, sigma_rot, rho, sigma, log_jitter, mean]
100.00% [10000/10000 01:57<00:00 Sampling 2 chains, 0 divergences]
Sampling 2 chains for 2_500 tune and 2_500 draw iterations (5_000 + 5_000 draws total) took 118 seconds.
[10]:
TimeSeries length=2480
timefluxflux_errcadnfrawcadencenofraw_errqualityfcorcbv01cbv02cbv03cbv04cbv05cbv06exptime
electron / selectron / selectron / ss
objectfloat64float64float64float64float64float64int32float64float64float64float64float64float64float64float64
2749.58995339413380.998349433848371nan129231.03616934.469760895129231.047.4133457561224255242883618895.82392130141.04.0326018130621833.721325487340294-0.62729987225031352.75803522396945060.94496936077676821800.0
2749.61038542845930.9983187622396653nan129232.03616898.694656372129232.047.420606055378303618797.795774931.04.0364453031006023.709970058424757-0.6394826529697442.73377450187055170.94137117690342841800.0
2749.63081736232560.9984457325683745nan129233.03617448.0032958984129233.047.4348262763665503619268.6471231061.04.0402638719398553.698637940508874-0.65160199992492212.70959095565915350.93778230161215271800.0
2749.65124919595840.9983939071581265nan129234.03617286.1815719604129234.047.4462583529729703619093.662134571.04.0440575557652723.687329095681801-0.66365802077563572.6854844858070060.93420271828859641800.0
2749.67168122935250.9987166345406551nan129235.03618496.683452606129235.047.46915206559436503620273.52982039841.04.0478263907621823.676043486032692-0.67565082318167312.66145499278585970.9306324103184151800.0
2749.69211316228760.9987638059203047nan129236.03618750.0302505493129236.047.4821109386744503620458.24287436441.04.0515704131159173.664781073650703-0.68758051480282252.63750237706746570.92707136108726421800.0
2749.7125449947560.998809794888955nan129237.03618955.9937667847129237.047.4944854038991703620640.2778030661.04.0552896590118053.6535418206249886-0.69944720329887172.6136265391235740.92351955398079921800.0
2749.7329770272190.9989407930835639nan129238.03619466.253112793129238.047.50783439566773603621129.437180821.04.0589841646351783.642325689044705-0.71125099632960892.5898273794259350.91997697238467571800.0
2749.753408958990.9989372786791572nan129239.03619449.8608169556129239.047.5205186273302103621134.04458832831.04.0626539661713633.6311326409990063-0.72299200155482232.56610479844630040.9164435996845491800.0
2749.773840790760.9990159099433658nan129240.03619830.804801941129240.047.5414812860888803621435.46656276841.04.06629909980569253.6199626385770487-0.73467032663429992.54245869665641950.91291941926607461800.0
2749.79427282205870.998943158158829nan129241.03619638.970149994129241.047.5615780681344403621192.0744356451.04.06991960172349553.6088156438679864-0.74628607922782992.51888897452804360.9094044145149081800.0
2749.81470475289830.9990148906745702nan129242.03620092.708744049129242.047.590407035130403621470.86248074841.04.0735155081101023.5976916189609756-0.75783936699520042.49539553253292250.90589856881670471800.0
2749.8351365837370.9990779456926332nan129243.03620588.7246055603129243.047.6126159253186742024963621720.2495034331.04.0770868551508423.5865905259451702-0.76933029759619932.47197827114280780.90240186555712021800.0
2749.85556861387160.9992400840159591nan129244.03621590.49723053129244.047.6344691369141403622327.97232542931.04.0806336790310453.5755123269097266-0.7807589786906152.4486370908294490.898914288121811800.0
................................................
2818.4041014524410.9997083659963285nan132599.03633293.7000579834132599.047.8218626189940103629823.6011308871.0-2.1651051353042270.34304411454921263.43830542441204920.188773666996963853.53611330389744531800.0
2818.424533507030.9996423445755372nan132600.03633612.672267914132600.047.8243237141838103629576.24797599581.0-2.16764683934144160.357427419150561533.4760593688461860.18782928161142233.5647698820239161800.0
2818.4449653620830.9996091702784011nan132601.03633727.3173980713132601.047.8298927457173303629448.3073313491.0-2.1702099753471640.37190285657780233.51397135827394360.186878248436600283.5935658109232141800.0
2818.46539731736270.9996831983733262nan132602.03634014.084197998132602.047.840208745080803629709.82391449341.0-2.17279459288323460.38647061422773893.55204166744435220.185920553244338983.6225013891208911800.0
2818.4858293731160.9996599733968752nan132603.03633582.8075580597132603.047.84956118074125403629617.4405606361.0-2.17540074151148670.40113087949717513.59027057110644330.184956181806479853.65157691514251771800.0
2818.50626122910030.9997223116728409nan132604.03633667.8337860107132604.047.86266905355072503629836.36602139751.0-2.1780284707937570.41588383978291513.62865834400926260.183985119894862743.68079268751367561800.0
2818.52669328554480.9998422314448273nan132605.03633621.2506580353132605.047.8820638129415703630264.7145496711.0-2.1806778302918810.43072968248176293.66720526090183170.183007353281328923.71014900475992261800.0
2818.56755709914430.9997582398366757nan132607.03633000.380264282132607.047.9286904325582903629941.28571782261.0-2.18604163818303080.4607007647059893.74477762565239840.181031649035873433.76928446797999061800.0
2818.5879891567530.9996797398181987nan132608.03632872.1142292023132608.047.8991585387295503629646.23144860751.0-2.18875618569973170.47582637902498373.78380362300845170.180033682947633943.7990642110049421800.0
2818.6084211143680.9997206621332078nan132609.03632842.7295036316132609.047.8558543694713903629785.5570854461.0-2.19149256167963060.49104562534430053.82298986335040960.17902895524484023.82898569300727141800.0
2818.62885307244870.9997112588233211nan132610.03632803.993894577132610.047.837685487587703629741.4916785471.0-2.19425081568456240.50635869106074673.86233662142730160.17801745169933333.85904921251254951800.0
2818.6492850309880.9998555351226522nan132611.03633366.8895816803132611.047.83333782418690603630256.4457417381.0-2.19703099727636350.52176576357112283.9018441719881550.176999158082954723.88925506804633431800.0
2818.6697169897670.9998098925720524nan132612.03633311.242116928132612.047.8295129405504803630080.24629519131.0-2.19983315601687130.53726703027223623.94151278978201970.175974060167544353.91960355813421041800.0
2818.6901489487790.9997076723433814nan132613.03633454.115245819132613.047.82795698316855503629698.11086238461.0-2.20265734146791830.55286267856088743.98134274955792120.17494214372494363.95009498130173231800.0
2818.71058090824950.9996609323036864nan132614.03633572.709289551132614.047.828783985360175242883629518.4517405211.0-2.20550360319134460.56855289583388414.0213343260648930.17390339452699263.9807296360744921800.0

Plot the corrected light curve

[10]:
plt.plot(lc_targ.ts_clean.time.value, lc_targ.ts_clean['flux'],'k.', markersize=1.8, alpha = 0.25)

plt.xlabel('Time [{}]'.format(str(lc_targ.ts_stitch.time.format).upper()))
plt.ylabel('Flux')
# plt.xlim(2350,2356)
# plt.ylim(0.985,1.015)
plt.show()
_images/example_K2-109_25_0.png

Looks like there’s something wrong at the begginning of our data. For now, lets mask it out.

[11]:
debut_mask = np.array(lc_targ.ts_clean.time.value < 2752.5)

Look for transits using TLS

Look for the first exoplanet

[12]:
perio_results1 = lc_targ.tls_periodogram(cleaned=True, n_transits_min=2, mask=debut_mask)
Transit Least Squares TLS 1.0.31 (22 Nov 2021)
Creating model cache for 44 durations
Searching 2342 data points, 6881 periods from 0.602 to 33.099 days
Using all 8 CPU threads
100%|██████████████████████████████████████████████████████████████████| 6881/6881 periods | 00:20<00:00
Searching for best T0 for period 21.06392 days
 /home/jrodrigues/testenv/lib64/python3.9/site-packages/transitleastsquares-1.0.31-py3.9.egg/transitleastsquares/main.py:411: UserWarning: 1 of 3 transits without data. The true period may be twice the given period.

Plot the TLS periodogram

[13]:
fulmar.perioplot(perio_results1, lc_targ.K2, folder="K2-109/", pl_n=1, maxper=None, savefig=False)
_images/example_K2-109_32_0.png

Plot the resulting model to have a quick visual check

[14]:
fulmar.modelplot(lc_targ.tls_results)
_images/example_K2-109_34_0.png

Optimize the transit parameters. *Be careful it assumes circular orbit*

[15]:
p, t0, dur, depth, ab, flat_samps = fulmar.params_optimizer(lc_targ.ts_clean, lc_targ.tls_results.period, lc_targ.tls_results.T0, 1-lc_targ.tls_results.depth, lc_targ.ab, lc_targ.R_star, lc_targ.K2, tran_window=0.25, ncores=None, mask=None)
running on 8 cores
mean           -3.22
log_ror        -3.22
log_period     -0.92
t0             -0.92
log_dur        -3.22
b_impact__     -1.39
obs           215.17
Name: Log-probability of test_point, dtype: float64
optimizing logp for variables: [log_dur, b, log_ror]
100.00% [34/34 00:00<00:00 logp = 3.298e+02]

message: Optimization terminated successfully.
logp: 202.27788474824652 -> 329.8381013996262
optimizing logp for variables: [mean]
100.00% [4/4 00:00<00:00 logp = 3.299e+02]

message: Optimization terminated successfully.
logp: 329.8381013996262 -> 329.9332573296841
optimizing logp for variables: [b, log_dur, t0, log_period, log_ror, mean]
100.00% [97/97 00:00<00:00 logp = 3.353e+02]

message: Desired error not necessarily achieved due to precision loss.
logp: 329.9332573296841 -> 335.29514335086077
optimizing logp for variables: [b, log_dur, t0, log_period, log_ror, mean]
100.00% [106/106 00:00<00:00 logp = 3.353e+02]

message: Desired error not necessarily achieved due to precision loss.
logp: 202.27788474824652 -> 335.2951433508669
Multiprocess sampling (2 chains in 8 jobs)
NUTS: [b, log_dur, t0, log_period, log_ror, mean]
100.00% [10000/10000 00:56<00:00 Sampling 2 chains, 0 divergences]
Sampling 2 chains for 2_500 tune and 2_500 draw iterations (5_000 + 5_000 draws total) took 58 seconds.
The number of effective samples is smaller than 25% for some parameters.
_images/example_K2-109_36_21.png

Mask intransit data

[18]:
intransit = transit_mask(lc_targ.ts_clean.time.value, p, 1.3*dur, t0) # True when datapoints are in transit

Combine intransit mask with the initial mask

[19]:
p1_mask = np.logical_or(debut_mask, intransit)

Plot the lightcurve with transits highlighted

[20]:
plt.plot(lc_targ.ts_clean.time.value, lc_targ.ts_clean['flux'],'k.', markersize=1.8, alpha = 0.25)
plt.plot(lc_targ.ts_clean.time.value[intransit], lc_targ.ts_clean['flux'][intransit],'o', color='xkcd:green', markersize=4.8, alpha = 0.5)

plt.xlabel('Time [{}]'.format(str(lc_targ.ts_stitch.time.format).upper()))
plt.ylabel('Flux')
#plt.xlim(2749,2752)
# plt.ylim(0.985,1.015)
plt.show()
_images/example_K2-109_42_0.png

Look for the second exoplanet

[21]:
perio_results2 = lc_targ.tls_periodogram(cleaned=True, n_transits_min=2, period_min=0.9, mask=p1_mask)
Transit Least Squares TLS 1.0.31 (22 Nov 2021)
Creating model cache for 44 durations
Searching 2318 data points, 5707 periods from 0.9 to 33.099 days
Using all 8 CPU threads
100%|██████████████████████████████████████████████████████████████████| 5707/5707 periods | 00:17<00:00
Searching for best T0 for period 9.55586 days

Plot the TLS periodogram

[22]:
fulmar.perioplot(perio_results2, lc_targ.K2, folder="K2-109/", pl_n=2, maxper=None, savefig=False)
# perioplot(results, lc_targ.K2, folder="K2-109/", num=1, maxper=50, savefig=False)
_images/example_K2-109_46_0.png
[23]:
fulmar.modelplot(lc_targ.tls_results)
_images/example_K2-109_47_0.png

Visualize where the transits lay in the lightcurve

[24]:
plt.plot(lc_targ.ts_clean.time.value[~debut_mask], lc_targ.ts_clean['flux'][~debut_mask],'ko', markersize=1.8, alpha = 0.2)

plt.xlabel('Time [{}]'.format(str(lc_targ.ts_stitch.time.format).upper()))
plt.ylabel('Flux')
#plt.xlim(2749,2752)
# plt.ylim(0.985,1.015)

for n in perio_results1.transit_times:
    plt.axvline(n, alpha=0.4, lw=2, ymax=0.15, color='xkcd:green')
for n in perio_results2.transit_times:
    plt.axvline(n, alpha=0.3, lw=2, ymax=0.45, color='xkcd:orange')

plt.title(lc_targ.K2)

plt.ylim(0.9985,1.00028)
plt.show()
_images/example_K2-109_49_0.png

Optimize the transit parameters. *Be careful it still assumes circular orbit*

[25]:
p_1, t0_1, dur_1, depth_1, ab_1, flat_samps_1 = fulmar.params_optimizer(lc_targ.ts_clean, lc_targ.tls_results.period, lc_targ.tls_results.T0, 1-lc_targ.tls_results.depth, lc_targ.ab, lc_targ.R_star, lc_targ.K2, tran_window=0.25, ncores=None, mask=~p1_mask)
running on 8 cores
mean           -3.22
log_ror        -3.22
log_period     -0.92
t0             -0.92
log_dur        -3.22
b_impact__     -1.39
obs           951.62
Name: Log-probability of test_point, dtype: float64
optimizing logp for variables: [log_dur, b, log_ror]
100.00% [34/34 00:00<00:00 logp = 9.923e+02]

message: Optimization terminated successfully.
logp: 938.7314070773815 -> 992.3434057514368
optimizing logp for variables: [mean]
100.00% [4/4 00:00<00:00 logp = 9.979e+02]

message: Optimization terminated successfully.
logp: 992.3434057514368 -> 997.8685515283529
optimizing logp for variables: [b, log_dur, t0, log_period, log_ror, mean]
100.00% [118/118 00:00<00:00 logp = 1.006e+03]

message: Desired error not necessarily achieved due to precision loss.
logp: 997.8685515283529 -> 1005.5500559403897
optimizing logp for variables: [b, log_dur, t0, log_period, log_ror, mean]
100.00% [119/119 00:00<00:00 logp = 1.005e+03]

message: Desired error not necessarily achieved due to precision loss.
logp: 938.7314070773815 -> 1005.3873774223697
Multiprocess sampling (2 chains in 8 jobs)
NUTS: [b, log_dur, t0, log_period, log_ror, mean]
100.00% [10000/10000 01:24<00:00 Sampling 2 chains, 0 divergences]
Sampling 2 chains for 2_500 tune and 2_500 draw iterations (5_000 + 5_000 draws total) took 86 seconds.
The number of effective samples is smaller than 10% for some parameters.
_images/example_K2-109_51_21.png

Mask intransit data

[26]:
intransit2 = transit_mask(lc_targ.ts_clean.time.value, p_1, 1.3*dur_1, t0_1) # True when datapoints are in transit

Combine intransit mask with the initial mask

[27]:
p2_mask = np.logical_or(p1_mask, intransit2)

Plot the lightcurve with transits highlighted

[28]:
plt.plot(lc_targ.ts_clean.time.value[~debut_mask], lc_targ.ts_clean['flux'][~debut_mask],'k.', markersize=1.8, alpha = 0.25)
plt.plot(lc_targ.ts_clean.time.value[intransit2], lc_targ.ts_clean['flux'][intransit2],'o', color='xkcd:orange', markersize=4.8, alpha = 0.25, label='K2-109b')
plt.plot(lc_targ.ts_clean.time.value[intransit], lc_targ.ts_clean['flux'][intransit],'o', color='xkcd:green', markersize=4.8, alpha = 0.25, label='K2-109c')


plt.xlabel('Time [{}]'.format(str(lc_targ.ts_stitch.time.format).upper()))
plt.ylabel('Flux')
#plt.xlim(2749,2752)
# plt.ylim(0.985,1.015)
plt.title(lc_targ.K2)
plt.legend()
plt.show()
_images/example_K2-109_57_0.png

Look for a possible third exoplanet ?

[29]:
perio_results3 = lc_targ.tls_periodogram(cleaned=True, n_transits_min=2, mask=p2_mask)
Transit Least Squares TLS 1.0.31 (22 Nov 2021)
Creating model cache for 44 durations
Searching 2266 data points, 6881 periods from 0.602 to 33.099 days
Using all 8 CPU threads
100%|██████████████████████████████████████████████████████████████████| 6881/6881 periods | 00:15<00:00
Searching for best T0 for period 12.50044 days
 /home/jrodrigues/testenv/lib64/python3.9/site-packages/transitleastsquares-1.0.31-py3.9.egg/transitleastsquares/stats.py:458: RuntimeWarning: divide by zero encountered in double_scalars

Plot the TLS periodogram

[30]:
fulmar.perioplot(perio_results3, lc_targ.K2, folder="K2-109/", pl_n=3, maxper=None, savefig=False)
# perioplot(results, lc_targ.K2, folder="K2-109/", num=1, maxper=50, savefig=False)
_images/example_K2-109_61_0.png
[31]:
fulmar.modelplot(lc_targ.tls_results)
_images/example_K2-109_62_0.png
[32]:
perio_results3.SDE, perio_results3.FAP
[32]:
(7.933769512184782, 0.00160064)

SDE < 9, which is the normally accepted threshold for a detection. We can end it there, as we can assume the system only contains two planets.

[33]:
print("In the paper, K2-109b period is announced to be 9.55237 days, in our quick look we found it at {0:.5f}.\nRegarding K2-109c, the paper announces 21.05704 days, we found {1:.5f}. \nNot bad !".format(p_1, p))
In the paper, K2-109b period is announced to be 9.55237 days, in our quick look we found it at 9.55405.
Regarding K2-109c, the paper announces 21.05704 days, we found 21.05469.
Not bad !