Ejemplo n.º 1
0
def createktransit(time, p, r):
    
    num_time = len(time)

    M = ktransit.LCModel()
    M.add_star(
    rho=1.5, # mean stellar density in cgs units
        ld1=0.2, # ld1--4 are limb darkening coefficients 
        ld2=0.4, # if only ld1 and ld2 are non-zero then a quadratic limb darkening law is used
        ld3=0.0, # if all four parameters are non-zero we use non-linear flavour limb darkening
        ld4=0.0, 
        dil=0.0, # a dilution factor: 0.0 -> transit not diluted, 0.5 -> transit 50% diluted
        zpt=0.0  # a photometric zeropoint, incase the normalisation was wonky
)
    M.add_planet(
    T0=1.0,     # a transit mid-time  
        period=p, # an orbital period in days
        impact=0.0, # an impact parameter
        rprs=r,   # planet stellar radius ratio  
        ecosw=0.0,  # eccentricity vector
        esinw=0.0,
        occ=0.0)    # a secondary eclipse depth in ppm
        
    M.add_data(time=numpy.array(time[:])),

    tmod = M.transitmodel# the out of transit data will be 0.0 unless you specify zpt
    
    return tmod
Ejemplo n.º 2
0
 def __init__(self):
     self.mod = ktransit.LCModel()
 #    self.nplanets = self.mod.nplanets
     self.free_parameters(fitparstar=[],
     fitparplanet=[])
     self.planetguess_d = {}
     self.uservdata = False
Ejemplo n.º 3
0
    def get_value(self, t):

        #make transit model
        M = ktransit.LCModel()
        M.add_star(
            rho=np.exp(self.log_rho),  # mean stellar density in cgs units
            ld1=0.6505,  # ld1--4 are limb darkening coefficients 
            ld2=
            0.1041,  # if only ld1 and ld2 are non-zero then a quadratic limb darkening law is used
            #ld1=theta[8],
            #ld2=theta[9],
            ld3=
            0.0,  # if all four parameters are non-zero we use non-linear flavour limb darkening
            ld4=0.0,
            dil=
            0.0,  # a dilution factor: 0.0 -> transit not diluted, 0.5 -> transit 50% diluted
            zpt=
            0.0  # a photometric zeropoint, incase the normalisation was wonky
        )
        M.add_planet(
            T0=np.exp(self.log_T0),  # a transit mid-time  
            period=np.exp(self.log_per),  # an orbital period in days
            impact=np.exp(self.log_imp),  # an impact parameter
            rprs=np.exp(self.log_ror),  # planet stellar radius ratio  
            #ecosw=self.ecosw,  # eccentricity vector
            #esinw=self.esinw,
            occ=0.0)  # a secondary eclipse depth in ppm

        M.add_data(time=t)

        return M.transitmodel
Ejemplo n.º 4
0
def createT(time, T0):#time array, transit mid-time, impact parameter

    #random period and radius: uniformly weighted
    #you can inject a specific period if you want
    period = np.random.uniform(low=1, high=26)
    print('inj period: ' + str(period))
    rprs = np.random.uniform(low=.01, high=.4)
    rprs = float(rprs)
    print('inj rprs: ' + str(rprs))

    #this is Tom Barclay's ktransit package I use for injection and fitting (https://github.com/mrtommyb/ktransit)
    M = ktransit.LCModel()
    M.add_star(
    rho=1.5, # mean stellar density in cgs units
    ld1=0.2, # ld1--4 are limb darkening coefficients
    ld2=0.4, # assuming quadratic limb darkening
    ld3=0.0,
    ld4=0.0,
    dil=0.0, # a dilution factor: 0.0 -> transit not diluted, 0.5 -> transit 50% diluted
    zpt=0.0  # photometric zeropoint
        )
    M.add_planet(
    T0=T0,     # a transit mid-time
    period=period, # an orbital period in days
    impact=0.0, # an impact parameter
    rprs=rprs,   # planet stellar radius ratio
    ecosw=0.0,  # eccentricity vector
    esinw=0.0,
    occ=0.0)    # a secondary eclipse depth in ppm

    M.add_data(time=np.array(time[:]))      # integration time of each timestamp

    tmod = M.transitmodel # the out of transit data will be 0.0 unless you specify zpt

    return tmod, period, rprs
Ejemplo n.º 5
0
def test_planets():
    import ktransit

    M = ktransit.LCModel()
    M.add_star()
    M.add_planet()
    M.add_data()

    tmod = M.transitmodel
Ejemplo n.º 6
0
def plot_rv_best(hf, ax, ylim=[-420, 420]):
    with h5py.File(hf) as f:
        g = f['mcmc']['chain'][:]
        lnprob = f['mcmc']['lnprob'][:]
        mle_idx = np.unravel_index(lnprob.argmax(), lnprob.shape)
        mle = g[mle_idx]
        M = ktransit.LCModel()
        M.add_star(rho=mle[0],
                   zpt=mle[1],
                   ld1=mle[2],
                   ld2=mle[3],
                   veloffset=mle[4])
        M.add_planet(T0=mle[7],
                     period=mle[8],
                     impact=mle[9],
                     rprs=mle[10],
                     ecosw=mle[11],
                     esinw=mle[12],
                     rvamp=mle[13],
                     occ=mle[14],
                     ell=mle[15],
                     alb=mle[16])
        M.add_data(time=f['time'][:])
        M.add_rv(rvtime=f['rvtime'][:])
        tmod = M.transitmodel
        phi, ffold, efold, fmod = get_qf_rv(M.rvtime,
                                            f['rvval'][:] - mle[4],
                                            np.sqrt(f['rverr'][:]**2 +
                                                    mle[-1]**2),
                                            M.T0,
                                            M.period,
                                            rvmodel=M.rvmodel - mle[4])

        M.add_rv(rvtime=np.arange(0, M.period, 0.002))
        tmod = M.transitmodel
        phi2, fmod2, efol2 = get_qf_rv(M.rvtime, M.rvmodel - mle[4], M.rvmodel,
                                       M.T0, M.period)

        lphi2 = int(len(phi2) / 2.)
        ax.plot(np.r_[phi2, phi2 + M.period], np.r_[fmod2, fmod2], color='r')

        ax.errorbar(np.r_[phi, phi + M.period],
                    np.r_[ffold, ffold],
                    yerr=np.r_[efold, efold],
                    color='k',
                    alpha=1,
                    ls='',
                    fmt='.')

        ax.set_xlim([-0.5 * M.period, 1.5 * M.period])
        ax.set_ylim(ylim)
        ax.set_xlabel('Time from mid-transit (days)')
        ax.set_ylabel('Radial Velocity (m/s)')
        ax.minorticks_on()
    return ax
Ejemplo n.º 7
0
def plot_transit_best(hf, ax, ylim=[9000, -1000], bins=900):
    with h5py.File(hf) as f:
        g = f['mcmc']['chain'][:]
        lnprob = f['mcmc']['lnprob'][:]
        mle_idx = np.unravel_index(lnprob.argmax(), lnprob.shape)
        mle = g[mle_idx]
        M = ktransit.LCModel()
        M.add_star(rho=mle[0],
                   zpt=mle[1],
                   ld1=mle[2],
                   ld2=mle[3],
                   veloffset=mle[4])
        M.add_planet(T0=mle[7],
                     period=mle[8],
                     impact=mle[9],
                     rprs=mle[10],
                     ecosw=mle[11],
                     esinw=mle[12],
                     rvamp=mle[13],
                     occ=mle[14],
                     ell=mle[15],
                     alb=mle[16])
        M.add_data(time=f['time'][:])
        M.add_rv(rvtime=f['rvtime'][:])

        #resid = f['flux'][:] - M.transitmodel
        #sample = get_sample(
        #    mle[5],mle[6],M.time,resid,f['err'][:])
        #len_samp = len(sample)
        phi, ffold, fmod = get_qf(M.time,
                                  f['flux'][:],
                                  M.T0,
                                  M.period,
                                  transitmodel=M.transitmodel)

        ax.scatter(np.r_[phi, phi + M.period],
                   np.r_[ffold, ffold],
                   color='k',
                   alpha=0.05,
                   s=0.5)
        ax.plot(np.r_[phi, phi + M.period], np.r_[fmod, fmod], color='r')
        bq1, bf1, be1 = bin_data(phi, ffold, bins)
        ax.errorbar(np.r_[bq1, bq1 + M.period],
                    np.r_[bf1, bf1],
                    yerr=np.r_[be1, be1],
                    ls='',
                    color='b')
        ax.set_xlim([-0.5 * M.period, 1.5 * M.period])
        ax.set_ylim(ylim)
        ax.set_xlabel('Time from mid-transit (days)')
        ax.set_ylabel('Transit depth (ppm)')
        ax.minorticks_on()
    return ax
Ejemplo n.º 8
0
def createT(time, T0):  #time array, transit mid-time, impact parameter

    #random period and radius: uniformly weighted
    #you can inject a specific period if you want
    period = loguniform(low=float(1), high=float(26))
    print('inj period: ' + str(period))
    rprs = np.random.uniform(low=.01, high=.4)
    rprs = float(rprs)
    print('inj rprs: ' + str(rprs))

    Mc = 9e28  #kilograms - mass of L dwarf
    Rs = 7.1492e7  #meters - radius of L dwarf
    periodsec = 86400 * period
    a1 = sc.G * Mc * periodsec**2
    a2 = (4 * sc.pi)**2
    a = np.cbrt(a1 / a2)  #semimajor axis, meters

    i = randomInc(1)
    impact = (a * math.cos(i)) / Rs
    #impact = 0.0

    total_per.append(period)
    total_rprs.append(rprs)

    print('inj impact: ' + str(impact))

    #this is Tom Barclay's ktransit package I use for injection and fitting (https://github.com/mrtommyb/ktransit)
    M = ktransit.LCModel()
    M.add_star(
        rho=1.5,  # mean stellar density in cgs units
        ld1=0.2,  # ld1--4 are limb darkening coefficients
        ld2=0.4,  # assuming quadratic limb darkening
        ld3=0.0,
        ld4=0.0,
        dil=
        0.0,  # a dilution factor: 0.0 -> transit not diluted, 0.5 -> transit 50% diluted
        zpt=0.0  # photometric zeropoint
    )
    M.add_planet(
        T0=T0,  # a transit mid-time
        period=period,  # an orbital period in days
        impact=impact,  # an impact parameter
        rprs=rprs,  # planet stellar radius ratio
        ecosw=0.0,  # eccentricity vector
        esinw=0.0,
        occ=0.0)  # a secondary eclipse depth in ppm

    M.add_data(time=np.array(time[:]))  # integration time of each timestamp

    tmod = M.transitmodel  # the out of transit data will be 0.0 unless you specify zpt

    return tmod, period, rprs, impact
Ejemplo n.º 9
0
def makeFakeData():
    # simulate some data
    cadence = 1. / 48.
    time = np.arange(0, 80, cadence)
    rvtime = np.arange(0, 100, 50)

    M = ktransit.LCModel()
    M.add_star(
        rho=0.001,
        ld1=0.2,
        ld2=0.4,
        ld3=0.0,
        ld4=0.0,
        dil=0.0,
        zpt=0.0,
        veloffset=
        10  # new keyword, the radial velocity zero-point offset in m/s   
    )
    M.add_planet(T0=1.0,
                 period=10.0,
                 impact=0.1,
                 rprs=0.05,
                 ecosw=0.0,
                 esinw=0.0,
                 occ=0.0,
                 rvamp=100.)  # radial velocity semi-amplitude in m/s

    M.add_data(time=time, itime=np.zeros_like(time) + cadence)

    M.add_rv(
        time=rvtime,  # radial velocity observation timestamps
        itime=np.zeros_like(rvtime) +
        cadence  # integration time of each timestamp
    )

    tmod = M.transitmodel
    rvmodel = M.rvmodelv

    return time, tmod, rvmod
Ejemplo n.º 10
0
        sumflux = sum(flux)
        flux_avg = sumflux / flux_count

        flux = [i / flux_avg for i in flux]
        flux = [i - 1 for i in flux]

        #uncomment if extra time stamp
        time.pop()

        ##########################
        #Create ktransit Data: CODE FROM GITHUB
        ##########################

        num_time = len(time)

        M = ktransit.LCModel()
        M.add_star(
            rho=1.5,  # mean stellar density in cgs units
            ld1=0.2,  # ld1--4 are limb darkening coefficients 
            ld2=
            0.4,  # if only ld1 and ld2 are non-zero then a quadratic limb darkening law is used
            ld3=
            0.0,  # if all four parameters are non-zero we use non-linear flavour limb darkening
            ld4=0.0,
            dil=
            0.0,  # a dilution factor: 0.0 -> transit not diluted, 0.5 -> transit 50% diluted
            zpt=
            0.0  # a photometric zeropoint, incase the normalisation was wonky
        )
        M.add_planet(
            T0=1.0,  # a transit mid-time