def DoubleTransitModel(theta, x, y, yerr):
    p1, t01, rp1, w1, u1, p2, t02, rp2, w2, u2, V, C = theta
    params1 = batman.TransitParams()
    #params1.t0=t01
    params1.t0 = 57512.3834
    params1.per = 1.6377
    params1.rp = rp1
    params1.a = 19.5
    params1.inc = 90
    params1.ecc = 0
    params1.w = w1
    params1.u = [u1]
    params1.limb_dark = "linear"
    m1 = batman.TransitModel(params1, x)
    model1 = m1.light_curve(params1)
    params2 = batman.TransitParams()
    params2.t0 = 57512.3897
    params2.per = 2.0198
    params2.rp = rp2
    params2.a = 26.7
    params2.inc = 90
    params2.ecc = 0
    params2.w = w2
    params2.u = [u2]
    params2.limb_dark = "linear"
    m2 = batman.TransitModel(params2, x)
    model2 = m2.light_curve(params2)
    model3 = V * (x - x[0]) + C
    #model3=-1167273.5778*(x-x[0])+59856592.8761
    #model=(model1+model2-1)*model3
    model = model1 + model2 - 1
    #model=model1
    return model
示例#2
0
def fit_db(X0, p1, f1, e1, p2, f2, e2):

    pm1 = bm.TransitParams()
    pm2 = bm.TransitParams()

    t01, t02 = X0[0], X0[1]
    rp1 = X0[2]
    rp2 = 1 / rp1
    fp1 = X0[3]
    fp2 = 1 / fp1
    a1, a2 = X0[4], X0[5]
    inc = X0[6]
    ecc = X0[7]
    w1 = X0[8]
    w2 = w1 + 180
    u1, u2 = X0[9], X0[10]
    u3, u4 = X0[11], X0[12]

    pm1.t0 = t01
    pm1.per = 1.
    pm1.rp = rp1
    pm1.a = a1
    pm1.inc = inc
    pm1.ecc = ecc
    pm1.w = w1
    pm1.u = [u1, u2]
    pm1.limb_dark = "quadratic"

    pm2.t0 = t02
    pm2.per = 1.
    pm2.rp = rp2
    pm2.a = a2
    pm2.inc = inc
    pm2.ecc = ecc
    pm2.w = w2
    pm2.u = [u3, u4]
    pm2.limb_dark = "quadratic"

    m1 = bm.TransitModel(pm1, p1)
    m2 = bm.TransitModel(pm2, p2)

    F1 = (m1.light_curve(pm1) + fp1) / (1 + fp1)
    F2 = (m2.light_curve(pm2) + fp2) / (1 + fp2)

    fit_vals1 = np.sqrt((f1 - F1)**2 / e1**2)
    fit_vals2 = np.sqrt((f2 - F2)**2 / e2**2)

    fit_val = (np.sum(fit_vals1) + np.sum(fit_vals2)) / (len(fit_vals1) +
                                                         len(fit_vals2) - 1)
    return fit_val
示例#3
0
def lnlike(theta,
           t_kep,
           f_kep,
           t_spit,
           f_spit,
           u1_kep=u1_KEP,
           u2_kep=u2_KEP,
           u1_spit=u1_SPIT,
           u2_spit=u2_SPIT):
    t0, per, a, b, rpKEP, rpSPIT, sigmaKEP, sigmaSPIT, offsetKEP, offsetSPIT = theta

    # Set up K2 transit parameters.
    kep_params = batman.TransitParams()
    kep_params.t0 = t0
    kep_params.per = per
    kep_params.rp = rpKEP
    kep_params.a = a
    kep_params.inc = np.arccos(b / a) * (180. / np.pi)
    kep_params.ecc = 0.
    kep_params.w = 0.
    kep_params.u = [u1_kep, u2_kep]
    kep_params.limb_dark = 'quadratic'
    # Initialize the K2 transit model.
    kep_init = batman.TransitModel(kep_params, t_kep)
    kep_model = kep_init.light_curve(kep_params) + offsetKEP
    # Calculate likelihood of K2 model
    like_kep = -0.5 * (np.sum((f_kep - kep_model)**2 *
                              (1 / sigmaKEP**2) - np.log(2 * np.pi *
                                                         (1 / sigmaKEP**2))))

    # Set up Spitzer transit parameters.
    spit_params = batman.TransitParams()
    spit_params.t0 = t0
    spit_params.per = per
    spit_params.rp = rpSPIT
    spit_params.a = a
    spit_params.inc = np.arccos(b / a) * (180. / np.pi)
    spit_params.ecc = 0.
    spit_params.w = 0.
    spit_params.u = [u1_spit, u2_spit]
    spit_params.limb_dark = 'quadratic'
    # Initialize the Spitzer transit model.
    spit_init = batman.TransitModel(spit_params, t_spit)
    spit_model = spit_init.light_curve(spit_params) + offsetSPIT
    # Calculate likelihood of Spitzer model
    like_spit = -0.5 * (np.sum((f_spit - spit_model)**2 * (1 / sigmaSPIT**2) -
                               np.log(2 * np.pi * (1 / sigmaSPIT**2))))

    return like_kep + like_spit
示例#4
0
    def __init__(self, lightcurves, priors):
        lightcurves = deepcopy(lightcurves)
        self.lightcurves = np.array(lightcurves, dtype=object)

        self.n_telescopes = self.lightcurves.shape[0]
        self.n_filters = self.lightcurves.shape[1]
        self.n_epochs = self.lightcurves.shape[2]

        self.num_light_curves = len(np.where(self.lightcurves.flatten() != None)[0])

        self.priors = priors

        # We need to make a separate TransitParams and TransitModels for each
        # light curve.

        # Initialise them:
        self.batman_params = ParamArray('batman_params', (self.n_telescopes, self.n_filters, self.n_epochs), True, True, True, lightcurves=self.lightcurves)
        self.batman_models = ParamArray('batman_models', (self.n_telescopes, self.n_filters, self.n_epochs), True, True, True, lightcurves=self.lightcurves)


        for i in np.ndindex(self.lightcurves.shape):
            tidx, fidx, eidx = i

            if self.lightcurves[i] is not None:
                # Set up the params
                self.batman_params.set_value(batman.TransitParams(), tidx, fidx, eidx)

                # Set up the TransitModels
                # Make some realistic parameters to setup the models with
                default_params = batman.TransitParams()
                if self.priors.fit_ttv:
                    default_params.t0 = priors.priors['t0'].default_value
                else:
                    default_params.t0 = priors.priors['t0'].default_value
                default_params.per = priors.priors['P'].default_value
                default_params.rp = priors.priors['rp'].default_value
                default_params.a = priors.priors['a'].default_value
                default_params.inc = priors.priors['inc'].default_value
                default_params.ecc = priors.priors['ecc'].default_value
                default_params.w = priors.priors['w'].default_value
                default_params.limb_dark = priors.limb_dark
                # Note that technically this is q, not u, but it doesn't matter
                # as we are only initialising here
                default_params.u = [priors.priors[qX].default_value for qX in priors.limb_dark_coeffs]

                # Now make the models
                model = batman.TransitModel(default_params, self.lightcurves[i].times)
                self.batman_models.set_value(model, tidx, fidx, eidx)
示例#5
0
def mini_transit(lc_params, time, fsigns, free_params, ld, *theta_j):
    #P, t0, radius, dist, inc = theta
    nfp = len(free_params)
    params = batman.TransitParams()
    if theta_j:
        params.per = theta_j[0]  #orbital period in days
        params.w = theta_j[1]  #longitude of periastron (in degrees)
        params.ecc = theta_j[2]  #eccentricity
    else:
        params.per = nfplc_params[nfp + ld]  #orbital period in days
        params.w = nfplc_params[nfp + ld +
                                1]  #longitude of periastron (in degrees)
        params.ecc = nfplc_params[nfp + ld + 2]  #eccentricity
    params.t0 = nfplc_params[0]  #time of inferior conjunction
    params.rp = nfplc_params[1]  #planet radius (in units of stellar radii)
    params.a = nfplc_params[2]  #semi-major axis (in units of stellar radii)
    params.inc = nfplc_params[3]  #orbital inclination (in degrees)
    u = []
    for i in range(ld):
        u.append(nfplc_params[nfp + i])
    params.u = u  #limb darkening coefficients [u1, u2]
    params.limb_dark = "quadratic"  #limb darkening model

    m = batman.TransitModel(params, time)  #initializes model
    flux = m.light_curve(params)  #calculates light curve

    return (flux)
示例#6
0
def init_catwoman(t, ld_law, nresampling=None, etresampling=None):
    """  
     This function initializes the catwoman code.
     """
    params = batman.TransitParams()
    params.t0 = 0.
    params.per = 1.
    params.rp = 0.1
    params.rp2 = 0.1
    params.a = 15.
    params.inc = 87.
    params.ecc = 0.
    params.w = 90.
    params.phi = 90.
    if ld_law == 'linear':
        params.u = [0.5]
    else:
        params.u = [0.1, 0.3]
    params.limb_dark = ld_law
    if nresampling is None or etresampling is None:
        m = catwoman.TransitModel(params, t)
    else:
        m = catwoman.TransitModel(params,
                                  t,
                                  supersample_factor=nresampling,
                                  exp_time=etresampling)
    return params, m
def lc_min(params, phase, flux, err):
    '''
	Function which calculates Chi2 value for a given set of input parameters.
	Function to be minimized to find best fit parameters
	'''

    #Define the system parameters for the batman LC model
    pm = bm.TransitParams()

    pm.t0 = 0.  #Time of transit centre
    pm.per = 1.  #Orbital period = 1 as phase folded
    pm.rp = params[0]  #Ratio of planet to stellar radius
    pm.a = params[1]  #Semi-major axis (units of stellar radius)
    pm.inc = params[2]  #Orbital Inclination [deg]
    pm.ecc = 0.  #Orbital eccentricity (fix circular orbits)
    pm.w = 90.  #Longitude of periastron [deg] (unimportant as circular orbits)
    pm.u = [0.1, 0.3]  #Stellar LD coefficients
    pm.limb_dark = "quadratic"  #LD model

    #Initialize the batman LC model and compute model LC
    m = bm.TransitModel(pm, phase)
    f_model = m.light_curve(pm)
    fit_vals = np.sqrt((flux - f_model)**2 / err**2)
    fit_val = np.sum(fit_vals) / (len(fit_vals) - 4)
    return fit_val
示例#8
0
def transit_model_1_plot(period):
    """
    Function for interactive transit modeling
    """
    # Parameters of planet model
    params = batman.TransitParams()
    params.t0 = 0.  # time of inferior conjunction
    params.per = period  # orbital period (days)
    params.rp = (
        (1.0 * u.Rjup) /
        (1.203 * u.Rsun)).si.value  # planet radius (in units of stellar radii)
    params.a = 15.  # semi-major axis (in units of stellar radii)
    params.inc = 87.  # orbital inclination (in degrees)
    params.ecc = 0.  # eccentricity
    params.w = 90.  # longitude of periastron (in degrees)
    params.u = [0.1, 0.1]  # limb darkening coefficients [u1, u2]
    params.limb_dark = "quadratic"  # limb darkening model

    # Defining the timeframe and calculating flux
    time = np.linspace(-1, 1, 10000) * 6  # Creates an array of 10000 points
    # over a roughly 12-day period
    model = batman.TransitModel(params, time)
    flux_model = model.light_curve(params)

    # Plotting results
    plt.figure(figsize=(14, 5))
    plt.plot(time - time[0], flux_model, 'r-')
    plt.title(
        "Figure 3: Multiple Transits of a Hot Jupiter with a {:0.1f}-day Period"
        .format(params.per))
    plt.xlabel("Time (days)")
    plt.ylabel("Star brightness")

    return
示例#9
0
    def __init__(self, planet_row):

        self.planet_row = planet_row

        # Initialize transit model
        self.params = batman.TransitParams()
        self.params.t0 = planet_row['TT'][0]
        self.params.inc = planet_row['I'][0].value
        self.params.a = planet_row['AR'][0].value
        self.params.rp = planet_row['DEPTH'][
            0].value**0.5  #planet_row['RR'][0].value
        self.params.ecc = planet_row['ECC'][0].value
        self.params.w = planet_row['OM'][0].value
        self.params.u = [0.0]
        self.params.limb_dark = 'linear'
        self.params.per = planet_row['PER'][0].value

        self.b = planet_row['B'][0]

        self.transit_duration = duration_14(self.params.per, self.params.rp,
                                            self.params.a, self.b,
                                            np.radians(self.params.inc),
                                            self.params.ecc,
                                            np.radians(self.params.w))

        # Initialize some attributes to fill later
        self.transit_model = None
        self.phase = None
示例#10
0
def init_batman(t, ld_law, nresampling=None, etresampling=None):
    """
     This function initializes the batman code.
     """
    
     params = batman.TransitParams()
     params.t0 = 0. 
     params.per = 1. 
     params.rp = 0.1
     params.a = 15.
     params.inc = 87.
     params.ecc = 0. 
     params.w = 90.
     if ld_law == 'linear':
         params.u = [0.5]
     else:
         params.u = [0.1,0.3]
     if ld_law == 'none':
         params.limb_dark = 'quadratic'
     else:
         params.limb_dark = ld_law
     params.ac = 0.001
     params.fp = 0.001
     params.t_secondary = params.t0 + (params.per/2) + params.ac
     if nresampling is None or etresampling is None:
         m = [batman.TransitModel(params, t), batman.TransitModel(params, t, transittype='secondary')]
     else:
         m = [batman.TransitModel(params, t, supersample_factor=nresampling, exp_time=etresampling),\
             batman.TransitModel(params, t, transittype='secondary', supersample_factor=nresampling, exp_time=etresampling)]
     return params,m
示例#11
0
def BatmanModel(t0=0.0,
                P=1.0,
                rad_pl=0.01602,
                a=15.0,
                i=87.0,
                e=0.0,
                w=90.0,
                coeff=[0.5, 0.1],
                plot=False):

    # Initialize the model
    params = batman.TransitParams()  #object to store transit parameters
    params.t0 = t0  #76.6764                    #time of inferior conjunction
    params.per = P  #13.17562                       #orbital period
    params.rp = rad_pl  #0.01602                       #planet radius (in units of stellar radii)
    params.a = a  #13.8                        #semi-major axis (in units of stellar radii)
    params.inc = i  #88.19                      #orbital inclination (in degrees)
    params.ecc = e  #0.0                       #eccentricity
    params.w = w  #90.                        #longitude of periastron (in degrees)
    params.limb_dark = "quadratic"  #limb darkening model
    params.u = coeff  #[0.4899, 0.1809]     #limb darkening coefficients [u1, u2]

    t = np.linspace(-.25, .25, 1000)  #times at which to calculate light curve
    t_new = np.interp(t, (t.min(), t.max()), (0, 0.2))
    m = batman.TransitModel(params, t)  #initializes model

    flux = m.light_curve(params)  #calculates light curve

    if plot == True:
        fig, ax = plt.subplots()
        ax.get_yaxis().get_major_formatter().set_useOffset(False)
        ax.plot(t_new, flux)

    return (t_new, flux, rad_pl)
示例#12
0
    def test_run_with_planet(self):
        """A test of simulate() with a planet"""
        # Make the TSO object
        tso = TSO(ngrps=2, nints=2, star=self.star)

        # Make orbital params
        params = batman.TransitParams()
        params.t0 = 0.
        params.per = 5.7214742
        params.a = 0.0558*q.AU.to(ac.R_sun)*0.66
        params.inc = 89.8
        params.ecc = 0.
        params.w = 90.
        params.limb_dark = 'quadratic'
        params.u = [0.1, 0.1]
        params.rp = 0.
        tmodel = batman.TransitModel(params, tso.time)
        tmodel.teff = 3500
        tmodel.logg = 5
        tmodel.feh = 0

        # Run the simulation
        tso.simulate(planet=self.planet, tmodel=tmodel)
        tso.subarray = 'SUBSTRIP96'
        tso.simulate(planet=self.planet, tmodel=tmodel)
        tso.subarray = 'FULL'
        tso.simulate(planet=self.planet, tmodel=tmodel)
示例#13
0
 def reference_transit(self, period_grid, duration_grid, samples, per, rp, a, inc, ecc, w, u, limb_dark):
     f = numpy.ones(tls_constants.SUPERSAMPLE_SIZE)
     duration = 1  # transit duration in days. Increase for exotic cases
     t = numpy.linspace(-duration * 0.5, duration * 0.5, tls_constants.SUPERSAMPLE_SIZE)
     ma = batman.TransitParams()
     ma.t0 = 0  # time of inferior conjunction
     ma.per = per  # orbital period, use Earth as a reference
     ma.rp = rp  # planet radius (in units of stellar radii)
     ma.a = a  # semi-major axis (in units of stellar radii)
     ma.inc = inc  # orbital inclination (in degrees)
     ma.ecc = ecc  # eccentricity
     ma.w = w  # longitude of periastron (in degrees)
     ma.u = u  # limb darkening coefficients
     ma.limb_dark = limb_dark  # limb darkening model
     m = batman.TransitModel(ma, t)  # initializes model
     flux = m.light_curve(ma)  # calculates light curve
     # Determine start of transit (first value < 1)
     idx_first = numpy.argmax(flux < 1)
     intransit_time = t[idx_first: -idx_first + 1]
     intransit_flux = flux[idx_first: -idx_first + 1]
     # Downsample (bin) to target sample size
     x_new = numpy.linspace(t[idx_first], t[-idx_first - 1], samples, per)
     f = interp1d(x_new, intransit_time)
     downsampled_intransit_flux = f(intransit_flux)
     # Rescale to height [0..1]
     rescaled = (numpy.min(downsampled_intransit_flux) - downsampled_intransit_flux) / (
             numpy.min(downsampled_intransit_flux) - 1
     )
     return rescaled
示例#14
0
def gentransit(t,
               t0=0.0,
               Porb=14.0,
               Rp=1.0,
               Mp=1.0,
               Rs=0.2,
               Ms=0.15,
               ideg=90.0,
               w=90.0,
               e=0.0,
               u1=0.1,
               u2=0.3):
    #Rp Earth radius
    params = batman.TransitParams()
    params.t0 = t0  # time of inferior conjunction
    params.rp = Rp * R_earth / (Rs * R_sun
                                )  # planet radius (in units of stellar radii)

    # calculate semi-major axis from orbital period value
    params.inc = ideg  # orbital inclination (in degrees)
    params.ecc = e  # eccentricity
    params.w = w  # longitude of periastron (in degrees), 90 for circular
    params.u = [u1, u2]  # limb darkening coefficients
    params.limb_dark = "quadratic"  # limb darkening model

    #period update
    params.per = Porb  # orbital period (days)
    a = (((params.per * u.day)**2 * G * (Ms * M_sun + Mp * M_earth) /
          (4 * np.pi**2))**(1. / 3)).to(R_sun).value / Rs
    params.a = a  # semi-major axis (in units of stellar radii)
    b = a * np.cos(ideg / 180.0 * np.pi)
    m = batman.TransitModel(params, t)  # initializes the model
    injlc = np.array(m.light_curve(params))

    return injlc, b
def transit_model_func(model_params, times, ldtype='quadratic', transitType='primary'):
    # Transit Parameters
    u1      = model_params['u1'].value
    u2      = model_params['u2'].value
    
    if 'edepth' in model_params.keys() and model_params['edepth'] > 0:
        if 'ecc' in model_params.keys() and 'omega' in model_params.keys() and model_params['ecc'] > 0:
            delta_phase = deltaphase_eclipse(model_params['ecc'], model_params['omega'])
        else:
            delta_phase = 0.5
        
        t_secondary = model_params['tCenter'] + model_params['period']*delta_phase
        
    else:
        model_params.add('edepth', 0.0, False)
    
    rprs  = np.sqrt(model_params['tdepth'].value)
    
    bm_params           = batman.TransitParams() # object to store transit parameters
    
    bm_params.per       = model_params['period'].value   # orbital period
    bm_params.t0        = model_params['tCenter'].value  # time of inferior conjunction
    bm_params.inc       = model_params['inc'].value      # inclunaition in degrees
    bm_params.a         = model_params['aprs'].value     # semi-major axis (in units of stellar radii)
    bm_params.rp        = rprs     # planet radius (in units of stellar radii)
    bm_params.fp        = model_params['edepth'].value   # planet radius (in units of stellar radii)
    bm_params.ecc       = model_params['ecc'].value      # eccentricity
    bm_params.w         = model_params['omega'].value    # longitude of periastron (in degrees)
    bm_params.limb_dark = ldtype   # limb darkening model # NEED TO FIX THIS
    bm_params.u         = [u1, u2] # limb darkening coefficients # NEED TO FIX THIS
    
    m_eclipse = batman.TransitModel(bm_params, times, transittype=transitType)# initializes model
    
    return m_eclipse.light_curve(bm_params)
def lc_min(params, time, flux, err):
    '''
	Function which calculates Chi2 value for a given set of input parameters.
	Function to be minimized to find best fit parameters
	'''

    phase = ((time - params['t0'].value) / params['per'].value) % 1

    #Define the system parameters for the batman LC model
    pm = bm.TransitParams()

    pm.t_secondary = 0  #Time of transit centre
    pm.per = 1.  #Orbital period = 1 as phase folded
    pm.rp = params['rp'].value  #Ratio of planet to stellar radius
    pm.a = params['a'].value  #Semi-major axis (units of stellar radius)
    pm.inc = 90  #Orbital Inclination [deg]
    pm.fp = params['fp'].value
    pm.ecc = args.ecc  #Orbital eccentricity (fix circular orbits)
    pm.w = args.w  #Longitude of periastron [deg] (unimportant as circular orbits)
    if not args.ld == "uniform":
        pm.u = [args.u1, args.u2]  #Stellar LD coefficients
    else:
        pm.u = []
    pm.limb_dark = args.ld  #LD model

    #Initialize the batman LC model and compute model LC
    m = bm.TransitModel(pm, phase, transittype="secondary")
    f_model = m.light_curve(pm) - params['base'].value
    residuals = (flux - f_model)**2 / err**2
    return residuals
示例#17
0
    def eval(self, **kwargs):
        """Evaluate the function with the given values"""
        # Get the time
        if self.time is None:
            self.time = kwargs.get('time')

        # Generate with batman
        bm_params = batman.TransitParams()

        # Set all parameters
        for p in self.parameters.list:
            setattr(bm_params, p[0], p[1])

        # Combine limb darkening coeffs
        bm_params.u = [getattr(self.parameters, u).value for u in self.coeffs]

        # Use batman ld_profile name
        if self.parameters.limb_dark.value == '4-parameter':
            bm_params.limb_dark = 'nonlinear'

        # Make the eclipse
        tt = self.parameters.transittype.value
        m_eclipse = batman.TransitModel(bm_params, self.time, transittype=tt)

        # Evaluate the light curve
        return m_eclipse.light_curve(bm_params)
示例#18
0
def fit_secondary(X0, p, f, e):

    pm = bm.TransitParams()
    pm.t0 = t0
    pm.per = 1.
    pm.rp = rp
    pm.a = X0[0]
    pm.inc = X0[1]
    pm.ecc = X0[2]
    pm.w = w
    pm.u = [0.3, 0.2]
    pm.limb_dark = "quadratic"
    pm.fp = fp

    m = bm.TransitModel(pm, p)
    pm.t_secondary = m.get_t_secondary(pm)
    m2 = bm.TransitModel(pm, p, transittype="secondary")
    f1 = (m.light_curve(pm) + 1) / 2
    f2 = m2.light_curve(pm) / 2

    F = f1 * f2

    vals = np.sqrt((f - F)**2 / e**2)
    fit_val = np.sum(vals) / (len(vals) - 1)
    return fit_val
示例#19
0
def transit(idx, data, params):
    t = data.time[idx]

    p = batman.TransitParams()
    t0, per, rp, a, inc, ecc, w, u1, u2, limb_dark = params
    #FIXME
    if limb_dark == 2: p.limb_dark = "quadratic"
    else:
        print "unsupported limb darkening parameter"
        return 0

    p.t0 = t0
    p.per = per
    p.rp = rp
    p.a = a
    p.inc = inc
    p.ecc = ecc
    p.w = w
    p.u = [u1, u2]

    m = batman.TransitModel(p,
                            t,
                            supersample_factor=3,
                            exp_time=data.exp_time / 24. / 60. / 60.)
    return m.light_curve(p)
示例#20
0
def transitmodel(target, time=None):
    '''Some day soon this will be starry'''
    if time is None:
        time = target.time

    planets_dictionary = find_planet_parameters(target)
    mlc_flux = np.ones(len(time))
    for idx, planet in planets_dictionary.items():
        params = batman.TransitParams()
        params.limb_dark = "linear"  # limb darkening model
        params.u = [0.5]  # limb darkening coefficients [u1, u2]
        params.w = 90.  # longitude of periastron (in degrees)

        params.t0 = planet['tranmid']  # time of inferior conjunction
        params.per = planet['period']  # orbital period
        params.ecc = planet['ecc']  # eccentricity
        params.a = planet['orbsmax'] / planet[
            'st_rad']  # semi-major axis (in units of stellar radii)
        params.rp = planet['radj'] / planet[
            'st_rad']  # planet radius (in units of stellar radii)
        params.inc = planet['incl']  # orbital inclination (in degrees)

        m = batman.TransitModel(params, time)  # initializes model
        mlc_flux += (m.light_curve(params) - 1)
    return mlc_flux / np.median(mlc_flux)
示例#21
0
def light_curve_model(t, rp, a, t0 = 0., per = 1., inc = 90., ecc = 0., w = 90., limb_dark = "quadratic", u = [0.1, 0.3]):
	'''Python Function to use the batman package to produce a model lightcurve using the following input parameters:
			t: 						numpy array containing the time values at which to calculate the model LC
			rp: 					radius of the planet, in units of stellar radii
			a						semi-major axis of the planet's orbit, in units of stellar radii
			t0 = 0.					time of the transit centre
			per = 1.				orbital period
			inc = 90.				orbital inclination [degrees]
			ecc = 0.				orbital eccentricity
			w = 90. 				longitude of periastron [degrees]
			limb_dark = "uniform"	limb darkening mechanism 
			u = []					limb darkening coefficients
			
		NOTE: Units of t, t0, and per are not set to be a specific unit but must all be consistent
		
		OUTPUT:
			flux_model :  a numpy array of the same dimensions as t, containing the relative for the model LC at each 
							time point in t'''

	params = batman.TransitParams()
	params.t0 = t0
	params.per = per
	params.rp = rp
	params.a = a
	params.inc = inc
	params.ecc = ecc
	params.w = w
	params.u = u
	params.limb_dark = limb_dark
	
	m = batman.TransitModel(params, t)
	flux_model = m.light_curve(params)
	
	return flux_model
def set_params_batman(params_lm, names, limb_type="quadratic"):

    params = batman.TransitParams()  #object to store transit parameters
    params.limb_dark = limb_type  #limb darkening model
    q_arr = np.zeros(2)
    for i in range(len(names)):
        value = params_lm[names[i]]
        name = names[i]
        if name == "t0":
            params.t0 = value
        if name == "per":
            params.per = value
        if name == "rp":
            params.rp = value
        if name == "a":
            params.a = value
        #if name=="inc":
        #params.inc = value
        if name == "b":
            params.inc = np.degrees(np.arccos(value / params.a))
        if name == "ecc":
            params.ecc = value
        if name == "w":
            params.w = value
        if name == "q1":
            q_arr[0] = value
        if name == "q2":
            q_arr[1] = value

    u_arr = q_to_u_limb(q_arr)
    params.u = u_arr
    return params
示例#23
0
def make_lightcurve(r, i, width, u_type, u_param, t):
    '''
    r: planet radius (in stellar radii)
    i: inclination (in degrees)
    width: "width parameter" a**3/p**2
    u_type: type of limb darkening
    u_param: list of parameters for limb darkening
    
    t: timesteps that you want the fluxes at
    
    assume circular orbit
    '''
    params = batman.TransitParams()
    params.rp = r  #planet radius (in units of stellar radii)
    params.inc = i  #orbital inclination (in degrees)
    params.w = 0  #longitude of periastron (in degrees)
    params.ecc = 0  #eccentricity
    params.per = 100  #orbital period
    params.t0 = 0  #time of inferior conjunction
    params.a = (width * 100**2)**(
        1 / 3)  #semi-major axis (in units of stellar radii)
    params.u = u_param  #limb darkening coefficients [u1, u2]
    params.limb_dark = u_type  #limb darkening model
    m = batman.TransitModel(params, t)  #initializes model
    flux = m.light_curve(params)  #calculates light curve
    return flux
示例#24
0
文件: models.py 项目: zkbt/tess-zap
 def __init__(self,
              epoch=0.0,
              period=1.0,
              rp_over_rs=0.1,
              a_over_rs=15.0,
              impact_parameter=0.5,
              eccentricity=0.0,
              omega=90.0,
              limb_coef=[0.1, 0.3],
              limb_type="quadratic"):
     '''
     Initialize a transit object and set its parameters.
     '''
     import batman
     self.batman = batman
     self.params = batman.TransitParams()
     self.params.t0 = epoch
     self.params.per = period
     self.params.rp = rp_over_rs
     self.params.a = a_over_rs
     inclination = np.arccos(impact_parameter / a_over_rs) * 180.0 / np.pi
     self.params.inc = inclination
     self.params.ecc = eccentricity
     self.params.w = omega
     self.params.u = limb_coef
     self.params.limb_dark = limb_type
示例#25
0
def lc_min(params, time, flux, err, spl):
    '''
	Function which calculates Chi2 value for a given set of input parameters.
	Function to be minimized to find best fit parameters

	Uses a spline to model any Out-of-Transit variability
	'''

    phase = ((time - (params['t0'].value)) / params['per'].value) % 1

    #Produce binned data set for caclulating the spline
    variability_model = spl(phase)

    #Define the system parameters for the batman LC model
    pm = bm.TransitParams()

    pm.t0 = 0  #Time of transit centre
    pm.per = 1.  #Orbital period = 1 as phase folded
    pm.rp = params['rp'].value  #Ratio of planet to stellar radius
    pm.a = params['a'].value  #Semi-major axis (units of stellar radius)
    pm.inc = params['inc'].value  #Orbital Inclination [deg]
    pm.ecc = args.ecc  #Orbital eccentricity (fix circular orbits)
    pm.w = args.w  #Longitude of periastron [deg] (unimportant as circular orbits)
    if not args.ld == "uniform":
        pm.u = [args.u1, args.u2]  #Stellar LD coefficients
    else:
        pm.u = []
    pm.limb_dark = args.ld  #LD model

    #Initialize the batman LC model and compute model LC
    m = bm.TransitModel(pm, phase)
    f_model = m.light_curve(pm)
    model_total = f_model * variability_model
    residuals = (flux - model_total)**2 / err**2
    return residuals
示例#26
0
def make_lightcurve(T0, RP, INC, PER, width, u_type, u_param, t):
    '''
        r: planet radius
        i: inclination
        per = orbital period
        width: "width parameter" a ** 3/per ** 2
        u_type: type of limb darkening
        u_param: list of parameters for limb darkening
                                    
        assume circular orbit
        '''
    params = batman.TransitParams()
    params.w = 0  #longitude of periastron (in degrees)
    params.ecc = 0  #eccentricity
    params.t0 = T0  #time of inferior conjunction
    params.rp = RP  #planet radius (in units of stellar radii)
    params.inc = INC  #orbital inclination (in degrees)
    params.per = PER  #orbital period
    params.a = (width * PER**2)**(
        1 / 3)  #semi-major axis (in units of stellar radii)
    params.u = u_param  #limb darkening coefficients [u1, u2]
    params.limb_dark = u_type  #limb darkening model
    m = batman.TransitModel(params, t)  #initializes model
    flux = m.light_curve(params)  #calculates light curve
    return flux
    def transit_model(self, pv, time):
        """
        Define the transit model for a given pv vector

        INPUT:
            pv[0] - period
            pv[1] - epoch (0)
            pv[2] - Rp/Rs (sqrt(depth))
            pv[3] - a/Rs (estimate from stellar density)
            pv[4] - impact param
        """
        p,t0,RpRs,aRs,dur = pv
        ii = mt.acos(pv[4]/pv[3])*(180./np.pi) # inclination in degrees

        params = batman.TransitParams()
        params.t0 = t0
        params.per = p
        params.inc = ii
        params.rp = RpRs
        params.a = aRs
        params.ecc = 0.
        params.w = 0.
        params.u = self.limbdark
        params.limb_dark = "quadratic"
        params.fp = 0.001

        # supersample for K2 cadence
        transitmodel = batman.TransitModel(params, time, transittype='primary',supersample_factor=7,exp_time=0.020431801470066003)
        lc = transitmodel.light_curve(params)
        return lc
示例#28
0
def batman_model(time, p):
    """
    Creates a batman transit model to inject into the data
    as not-a-flare noise.

    Parameters
    ----------    
    time : np.ndarray
    params : parameters for the batman model. params is an 
         array of [t0, period, rp/r_star, a/r_star].

    Returns
    ----------    
    flux : batman modeled flux with transit injected.
    """
    params = batman.TransitParams()
    params.t0 = p[0]
    params.per = p[1]
    params.rp = p[2]
    params.a = p[3]
    params.inc = 90.
    params.ecc = 0.
    params.w = 90.
    params.u = [0.1, 0.3]
    params.limb_dark = "quadratic"

    m = batman.TransitModel(params, time)
    flux = m.light_curve(params)
    return flux
示例#29
0
def make_lightcurve(t0, r, i, p, width, u_type, u_param, t):
    """
    Generate a batman lightcurve with the given parameters.
    
    Parameters
    ----------
    t0 (num): time of inferior conjunction
    r (num): planet radius (in stellar radii)
    i (num): orbital inclination (in degrees)
    p (num): orbital period
    width (num): width parameter (defined as a**3/p**2)
    u_type (str): limb darkening model
    u_param (list): parameters for limb darkening
    
    t: timesteps that you want the fluxes at
    
    assume circular orbit
    """
    # Init batman model
    params = batman.TransitParams()
    params.rp = r
    params.inc = i
    params.w = 0  # longitude of periastron (degenerate with width)
    params.ecc = 0  # eccentricity (0 for circular orbits)
    params.per = p  # orbital period
    params.t0 = t0
    params.a = (width * p**2)**(1 / 3)  # semi-major axis (stellar radii)
    params.limb_dark = u_type
    params.u = u_param
    model = batman.TransitModel(params, t)

    # Generate curve
    flux = model.light_curve(params)  # compute light curve
    return flux
    def __init__(self, time, flux, uncertainty, parameter_dict):
        '''
        This is a TransitCurve - the flux, uncertainty and times, plus all the
        parameter information you might need. You can also use this object to
        add systematics.
        '''
        self.time = time
        self.flux = flux
        self.uncertainty = uncertainty

        self.parameters = {}

        self.parameters['Rp'] = parameter_dict['Rp']
        self.parameters['P'] = parameter_dict['P']
        self.parameters['t0'] = parameter_dict['t0']
        self.parameters['a'] = parameter_dict['a']
        self.parameters['inc'] = parameter_dict['inc']
        self.parameters['limb_darkening_model'] = parameter_dict[
            'limb_darkening_model']
        self.parameters['limb_darkening_params'] = parameter_dict[
            'limb_darkening_params']
        self.parameters['w'] = parameter_dict['w']
        self.parameters['ecc'] = parameter_dict['ecc']

        # batman.TransitParams which can be used to generate the curve again
        self.batman_params = batman.TransitParams()
        self.batman_params.t0 = self.parameters['t0']
        self.batman_params.rp = self.parameters['Rp']
        self.batman_params.per = self.parameters['P']
        self.batman_params.a = self.parameters['a']
        self.batman_params.limb_dark = self.parameters['limb_darkening_model']
        self.batman_params.u = self.parameters['limb_darkening_params']
        self.batman_params.inc = self.parameters['inc']
        self.batman_params.w = self.parameters['w']
        self.batman_params.ecc = self.parameters['ecc']