Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Everest pipeline for K2 data #15

Open
mirsakhawathossain opened this issue Oct 18, 2018 · 11 comments
Open

Everest pipeline for K2 data #15

mirsakhawathossain opened this issue Oct 18, 2018 · 11 comments

Comments

@mirsakhawathossain
Copy link

mirsakhawathossain commented Oct 18, 2018

How can I use this package to compute new k2 planet candidate? @rodluger

@ericagol
Copy link
Collaborator

I would recommend starting with the documentation. There is an example given on how to mask the transits, which is necessary for detrending (since you don't want the transits to affect the pixel-level decorelation). An alternative to masking is to do an initial fit to the transits, and then subtract the fit, and carry out the PLD on the residuals.

https://rodluger.github.io/everest/using_everest.html

@mirsakhawathossain
Copy link
Author

Everest pipeline runs good in Linux but when I try it to my Windows laptop it shows this problem. Could you please help me @rodluger and @ericagol?

Everest.zip

@ericagol
Copy link
Collaborator

I haven't used EVEREST on Windows, so I can't help. @rodluger ?

@mirsakhawathossain
Copy link
Author

It shows when run in Windows Machine. Can anyone please help me? @ericagol @rodluger
import everest
`=================

RESTART: C:/Users/User/Desktop/everesr.py =================
Traceback (most recent call last):
File "C:/Users/User/Desktop/everesr.py", line 1, in
import everest
File "C:/Users/User/Desktop\everest_init_.py", line 23, in
from . import transit
File "C:/Users/User/Desktop\everest\transit.py", line 19, in
import pysyzygy as ps
File "E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\pysyzygy_init_.py", line 16, in
subprocess.call(["make"], cwd = cwd)
File "E:\WPy-3662\python-3.6.6.amd64\lib\subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "E:\WPy-3662\python-3.6.6.amd64\lib\subprocess.py", line 709, in init
restore_signals, start_new_session)
File "E:\WPy-3662\python-3.6.6.amd64\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified`

@rodluger
Copy link
Owner

Hi @sakhawat18 the problem is in installing the pysyzygy package, which I coded up years ago before I knew what I was doing! Looks like the install script fails on Windows. But you shouldn't need pysyzygy to run most of the stuff in everest, so I pushed a quick workaround to master. Can you try to re-install everest from the master branch and let me know if that fixes the issue?

@mirsakhawathossain
Copy link
Author

Hello @rodluger I followed your way but when I tried your mcmc code following
`"""MCMC example for transit fitting."""

import matplotlib.pyplot as pl
from everest import Everest, TransitModel
import numpy as np
import emcee
from tqdm import tqdm
from corner import corner

def lnprior(x):
"""Return the log prior given parameter vector x."""
per, t0, b = x
if b < -1 or b > 1:
return -np.inf
elif per < 7 or per > 10:
return -np.inf
elif t0 < 1978 or t0 > 1979:
return -np.inf
else:
return 0.

def lnlike(x, star):
"""Return the log likelihood given parameter vector x."""
ll = lnprior(x)
if np.isinf(ll):
return ll, (np.nan, np.nan)
per, t0, b = x
model = TransitModel('b', per=per, t0=t0, b=b, rhos=10.)(star.time)
like, d, vard = star.lnlike(model, full_output=True)
ll += like
return ll, (d,)

Initialize the everest model

star = Everest(201635569)

Set up the MCMC sampler

params = ['Period (days)', r't$_0$ (BJD - 2456811)', 'Impact parameter']
blobs = ['Depth (%)']
nsteps = 1000
nburn = 300
nwalk = 10
ndim = len(params)
nblobs = len(blobs)
sampler = emcee.EnsembleSampler(nwalk, ndim, lnlike, args=[star])
x0 = [[8.368 + 0.01 * np.random.randn(),
1978.4513 + 0.01 * np.random.randn(),
0. + 0.1 * np.random.randn()] for k in range(nwalk)]
blobs0 = [[0.] for k in range(nwalk)]

Run!

for i in tqdm(sampler.sample(x0, iterations=nsteps, blobs0=blobs0),
total=nsteps):
pass

Add the blobs to the chain for plotting

chain = np.concatenate((sampler.chain,
np.array(sampler.blobs).swapaxes(0, 1)), axis=2)

Re-scale the transit time for prettier axes labels

chain[:, :, 1] -= 1978.

Take the absolute value of the impact parameter for plotting

chain[:, :, 2] = np.abs(chain[:, :, 2])

Re-scale the transit depth as a percentage

chain[:, :, 3] *= 100.

Plot the chains

fig1, ax = pl.subplots(ndim + nblobs, figsize=(6, 7))
fig1.suptitle("K2-14b", fontsize=16, fontweight='bold')
ax[-1].set_xlabel("Iteration", fontsize=14)
for n in range(ndim + nblobs):
for k in range(nwalk):
ax[n].plot(chain[k, :, n], alpha=0.3, lw=1)
ax[n].set_ylabel((params + blobs)[n], fontsize=9)
ax[n].margins(0, None)
ax[n].axvline(nburn, color='b', alpha=0.5, lw=1, ls='--')
fig1.savefig("k2-14b_chains.png", bbox_inches='tight')

Plot the posterior distributions

samples = chain[:, nburn:, :].reshape(-1, ndim + nblobs)
fig2 = corner(samples, labels=params + blobs)
fig2.suptitle("K2-14b", fontsize=16, fontweight='bold')
fig2.set_size_inches(6, 6)
for ax in fig2.axes:
for tick in ax.get_xticklabels() + ax.get_yticklabels():
tick.set_fontsize(7)
fig2.savefig("k2-14b_corner.png", bbox_inches='tight')
`
It raised exception following
=================== RESTART: C:\Users\User\Desktop\mcmc.py ===================
INFO [everest.user.DownloadFile()]: Found cached file.
INFO [everest.user.load_fits()]: Loading FITS file for 201635569.

0%| | 0/1000 [00:00<?, ?it/s]emcee: Exception while calling your likelihood function:
params: [ 8.37136581e+00 1.97846054e+03 -2.77124129e-02]
args: [<everest.Everest(201635569)>]
kwargs: {}
exception:
Traceback (most recent call last):
File "E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\emcee\ensemble.py", line 519, in call
return self.f(x, *self.args, **self.kwargs)
File "C:\Users\User\Desktop\mcmc.py", line 30, in lnlike
model = TransitModel('b', per=per, t0=t0, b=b, rhos=10.)(star.time)
File "E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\everest\transit.py", line 107, in call
raise Exception("Unable to import pysyzygy.")
Exception: Unable to import pysyzygy.
Traceback (most recent call last):
File "C:\Users\User\Desktop\mcmc.py", line 55, in
total=nsteps):
File "E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\tqdm_tqdm.py", line 933, in iter
for obj in iterable:
File "E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\emcee\ensemble.py", line 198, in sample
lnprob, blobs = self._get_lnprob(p)
File "E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\emcee\ensemble.py", line 382, in _get_lnprob
results = list(M(self.lnprobfn, [p[i] for i in range(len(p))]))
File "E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\emcee\ensemble.py", line 519, in call
return self.f(x, *self.args, **self.kwargs)
File "C:\Users\User\Desktop\mcmc.py", line 30, in lnlike
model = TransitModel('b', per=per, t0=t0, b=b, rhos=10.)(star.time)
File "E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\everest\transit.py", line 107, in call
raise Exception("Unable to import pysyzygy.")
Exception: Unable to import pysyzygy.

@mirsakhawathossain
Copy link
Author

In mcmc.py code how can I set up following line
x0 = [[8.368 + 0.01 * np.random.randn(), 1978.4513 + 0.01 * np.random.randn(), 0. + 0.1 * np.random.randn()] for k in range(nwalk)]
How can I find out transit time and period? Please help me. @rodluger @ericagol

@ericagol
Copy link
Collaborator

That depends on which system you are studying - this is only useful if you have a known transiting exoplanet; if the planet is not known, then the transits cannot be masked.

@mirsakhawathossain
Copy link
Author

I am studying exoplanet candidates to confirm them. Now please help me @rodluger @ericagol

@ericagol
Copy link
Collaborator

Well, for each candidate you will have to look up the period and time of first transit.

@mirsakhawathossain
Copy link
Author

It is easy to find out time of transit using Lightkurve Python package but the period search it is not easy because using different algorithm it varies. Could you please help me? @rodluger @ericagol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants