Ejemplo n.º 1
0
 def __make_model(self, time, flux, flux_err, rstar, mstar, epoch, period,
                  rplanet, exposure_time):
     P1 = period * u.day
     a = np.cbrt((ac.G * mstar * P1**2) / (4 * np.pi**2)).to(u.au)
     texpo = exposure_time / 60. / 60. / 24.
     model = ellc.lc(
         t_obs=time,
         radius_1=rstar.to(u.au) /
         a,  # star radius convert from AU to in units of a
         radius_2=rplanet.to(u.au) /
         a,  # convert from Rearth (equatorial) into AU and then into units of a
         sbratio=0,
         incl=90,
         light_3=0,
         t_zero=epoch,
         period=period,
         a=None,
         q=1e-6,
         f_c=None,
         f_s=None,
         ldc_1=self.ab,
         ldc_2=None,
         gdc_1=None,
         gdc_2=None,
         didt=None,
         domdt=None,
         rotfac_1=1,
         rotfac_2=1,
         hf_1=1.5,
         hf_2=1.5,
         bfac_1=None,
         bfac_2=None,
         heat_1=None,
         heat_2=None,
         lambda_1=None,
         lambda_2=None,
         vsini_1=None,
         vsini_2=None,
         t_exp=texpo,
         n_int=None,
         grid_1='default',
         grid_2='default',
         ld_1='quad',
         ld_2=None,
         shape_1='sphere',
         shape_2='sphere',
         spots_1=None,
         spots_2=None,
         exact_grav=False,
         verbose=1)
     if model[0] > 0:
         flux_t = flux + model - 1.
         result_flux = flux_t
         result_flux_err = flux_err
         result_time = time
     else:
         result_flux = []
         result_time = []
         result_flux_err = []
     return result_time, result_flux, result_flux_err
Ejemplo n.º 2
0
def basic_model(t, pars, grid='default'):

    try:
        m = ellc.lc(t_obs=t,
                    radius_1=pars[0],
                    radius_2=pars[1],
                    sbratio=pars[2],
                    incl=pars[3],
                    t_zero=58664.0,
                    q=pars[4],
                    period=pars[6] / 86400.0,
                    shape_1='roche',
                    shape_2='roche',
                    t_exp=30 / 86400.0,
                    grid_1=grid,
                    grid_2=grid,
                    heat_2=pars[5],
                    exact_grav=False)
        m *= 1.0

    except:
        print("Failed with parameters:", pars)
        return t * 10**99

    return m
Ejemplo n.º 3
0
def flux_fct(params, inst, planet, xx=None):
    '''
    ! params must be updated via update_params() before calling this function !
    '''
    if xx is None:
        xx = config.BASEMENT.data[inst]['time']

    model_flux = ellc.lc(
        t_obs=xx,
        radius_1=params[planet + '_radius_1'],
        radius_2=params[planet + '_radius_2'],
        sbratio=params[planet + '_sbratio_' + inst],
        incl=params[planet + '_incl'],
        light_3=params['light_3_' + inst],
        t_zero=params[planet + '_epoch'],
        period=params[planet + '_period'],
        f_c=params[planet + '_f_c'],
        f_s=params[planet + '_f_s'],
        ldc_1=params['ldc_1_' + inst],
        #                      ldc_2 = ldc_2,
        ld_1=config.BASEMENT.settings['ld_law_' + inst],
        #                      ld_2 = 'quad',
        heat_2=params[planet + '_heat_2_' + inst],
        t_exp=config.BASEMENT.settings['t_exp_' + inst],
        n_int=config.BASEMENT.settings['t_exp_n_int_' + inst])

    return model_flux
Ejemplo n.º 4
0
 def subtract_planet_transit(self,
                             ab,
                             star_radius,
                             star_mass,
                             time,
                             flux,
                             planet_radius,
                             planet_t0,
                             planet_period,
                             planet_inc=90):
     P1 = planet_period * u.day
     a = np.cbrt(
         (ac.G * star_mass * u.M_sun * P1**2) / (4 * np.pi**2)).to(u.au)
     model = ellc.lc(
         t_obs=time,
         radius_1=(star_radius * u.R_sun).to(u.au) /
         a,  # star radius convert from AU to in units of a
         radius_2=(planet_radius * u.R_earth).to(u.au) / a,
         # convert from Rearth (equatorial) into AU and then into units of a
         sbratio=0,
         incl=planet_inc,
         light_3=0,
         t_zero=planet_t0,
         period=planet_period,
         a=None,
         q=1e-6,
         f_c=None,
         f_s=None,
         ldc_1=ab,
         ldc_2=None,
         gdc_1=None,
         gdc_2=None,
         didt=None,
         domdt=None,
         rotfac_1=1,
         rotfac_2=1,
         hf_1=1.5,
         hf_2=1.5,
         bfac_1=None,
         bfac_2=None,
         heat_1=None,
         heat_2=None,
         lambda_1=None,
         lambda_2=None,
         vsini_1=None,
         vsini_2=None,
         t_exp=None,
         n_int=None,
         grid_1='default',
         grid_2='default',
         ld_1='quad',
         ld_2=None,
         shape_1='sphere',
         shape_2='sphere',
         spots_1=None,
         spots_2=None,
         exact_grav=False,
         verbose=1)
     return flux - model + 1
Ejemplo n.º 5
0
def test_EB(p=1.0, maxNterms=10):
    """ using ellc, make an eclipsing binary LC and fit using fourier components

    input:
    p: float the period
    Nterms number of fourier terms to be used for fitting

    output:
        0

    """

    import ellc

    # make testdata
    t = 100. * np.random.rand(1000)
    t.sort()
    y = ellc.lc(t,
                0.05,
                0.25,
                0.12,
                85.,
                t_zero=0.32321,
                period=p,
                q=0.23,
                shape_2='roche')
    y += 0.0000001 * (t - np.min(t))
    dy = 0.01 * np.ones_like(t)
    y += dy * np.random.randn(np.size(t))

    # fit data
    LC = np.c_[t, y, dy]
    output1 = fit_best(LC, p, maxNterms=maxNterms, output='full')
    output2 = fit(LC, p, Nterms=5, output='full')

    plt.plot(AB2AmpPhi(copy.deepcopy(output1[4:]).reshape(maxNterms, 2)), 'ro')
    plt.plot(AB2AmpPhi(copy.deepcopy(output2[4:]).reshape(Nterms, 2)), 'bo')
    plt.show()

    # show result
    f = make_f(p=p)
    model1 = f(t, *output1[2:])
    model2 = f(t, *output2[2:])

    #plt.errorbar(t,y,dy,fmt='k,')
    #plt.plot(t,model,'r.')
    #plt.show()

    # fold
    plt.errorbar(t / p % 1, y, dy, fmt='k,')
    plt.plot(t / p % 1, model1, 'r.')
    plt.plot(t / p % 1, model2, 'b.')
    plt.show()

    return 0
Ejemplo n.º 6
0
def ellc_WDWD(pars, x, logpars=False):

    # set values
    p, t0, r1, r2, incl, q, M1, scale, sbratio, heat = pars
    if logpars:
        sbratio = 10**sbratio

    # check parameter values
    if np.min(pars) < 0:
        return -np.inf
    #print(p,t0,r1,r2,incl,q,sbratio,heat)
    if (r2 > 0.99 * get_REg(q) or r1 > 0.99 * get_REg(q**-1) or incl >= 90
            or np.min([r1, r2, incl, q, scale, sbratio, heat]) <= 0):
        return -np.inf

    # calculate binary parameters
    K1, K2, a = kepler_calc_RV(M1, q * M1, p, incl)

    # lower limit to WD radius
    if M1 > 1.44 or r1 * a < WD_MR(M1):
        print('WD mass/radius out of range')
        return -np.inf
    if M2 > 1.44 or r2 * a < WD_MR(M2):
        print('WD mass/radius out of range')
        return -np.inf

    try:
        m = scale * ellc.lc(
            x,
            radius_1=r1,
            radius_2=r2,
            sbratio=sbratio,
            incl=incl,
            q=q,
            period=p,
            t_zero=t0,
            shape_2='roche',
            exact_grav=False,  #WARNING TURN THIS ON IN PRODUCTION!!!
            ldc_1=0.6,
            ldc_2=0.6,
            gdc_2=0.08,
            heat_2=heat,
            grid_1='default',
            grid_2='default',
            t_exp=30. / 3600 / 24,
            n_int=3)
        #print('succes')
        return m
    except Exception as e:
        print('ellc failed:')
        print(e)
        return -np.inf
Ejemplo n.º 7
0
def calcFLUX(curvas,pontos):
    startTime = datetime.now()
    
    time = linspace(0,curvas,pontos)
    
    flux = ellc.lc(time,t_zero=t_zero, period=period, 
        radius_1=r_1, radius_2=r_2,incl=90,sbratio=0, rotfac_1 = rotfac_1, 
        ld_1=ld_1, ldc_1=ldc_1,shape_1='sphere',shape_2='sphere',
        grid_1='sparse',grid_2='sparse',spots_1=spots_1)

    endTime = datetime.now()
    duracao = endTime - startTime
    
    registraExecucao(curvas, pontos, duracao, 1)
    return flux
Ejemplo n.º 8
0
Archivo: models.py Proyecto: vedad/ell
def get_light_curve(x,
                    period,
                    t0,
                    aor,
                    ror,
                    incl,
                    ustar=None,
                    ld=None,
                    ecc=0,
                    omega=90,
                    sbratio=0,
                    oversample=1,
                    texp=None,
                    **kwargs):
    try:
        from ellc import lc
    except ModuleNotFoundError:
        print("Please install `ellc` to use this function")
        sys.exit()

    if not isinstance(x, np.ndarray):
        x = np.array([x])

    r1oa = 1 / aor
    r2oa = r1oa * ror
    f_s = np.sqrt(ecc) * np.sin(np.deg2rad(omega))
    f_c = np.sqrt(ecc) * np.cos(np.deg2rad(omega))

    model = lc(x,
               radius_1=r1oa,
               radius_2=r2oa,
               incl=incl,
               sbratio=sbratio,
               period=period,
               t_zero=t0,
               f_s=f_s,
               f_c=f_c,
               light_3=0,
               ld_1=ld,
               ldc_1=ustar,
               t_exp=texp,
               n_int=oversample,
               **kwargs)
    #            grid_1='very_sparse',
    #            grid_2='v)

    return model
Ejemplo n.º 9
0
def func(c, t, r_1, k, incl, grid_size, lc_mugrid):
    h1, h2 = q1q2_to_h1h2(c[0], c[1])
    c2, a2 = h1h2_to_ca(h1, h2)
    ldc_1 = [c2, a2]
    try:
        lc_fit = lc(t,
                    radius_1=r_1,
                    radius_2=r_1 * k,
                    sbratio=0,
                    incl=incl,
                    ld_1='power-2',
                    ldc_1=ldc_1,
                    grid_1=grid_size,
                    grid_2=grid_size)
    except:
        lc_fit = zero_like(t)
    return (lc_fit - lc_mugrid).std()
Ejemplo n.º 10
0
def basic_model(t, pars, grid='default'):
    """ a function which returns model values at times t for parameters pars

    input:
        t    a 1D array with times
        pars a 1D array with parameter values; r1,r2,J,i,t0,p

    output:
        m    a 1D array with model values at times t

    """
    try:
        m = ellc.lc(t_obs=t,
                    radius_1=pars[0],
                    radius_2=pars[1],
                    sbratio=pars[2],
                    incl=pars[3],
                    t_zero=pars[4],
                    q=pars[6],
                    period=p,
                    shape_1='sphere',
                    shape_2='roche',
                    ld_1="claret",
                    ldc_1=[0.9361, -1.0310, 0.8933, -0.3117],
                    ld_2="claret",
                    ldc_2=[0.7593, -0.2638, 0.1634, -0.0651],
                    gdc_1=0.4712,
                    gdc_2=0.4102,
                    f_c=0,
                    f_s=0,
                    t_exp=t_exp,
                    grid_1=grid,
                    grid_2=grid,
                    heat_2=1.0,
                    exact_grav=True,
                    verbose=0)
        m *= pars[5]

    except:
        print("Failed with parameters:", pars)
        return t * 10**99

    return m
Ejemplo n.º 11
0
 def ellc_lc_short(time):
     return ellc.lc(t_obs=time,
                    radius_1=params['R_host/a'],
                    radius_2=params['R_companion/a'],
                    sbratio=sbratio,
                    incl=params['incl'],
                    light_3=dil,
                    t_zero=params['epoch'],
                    period=params['period'],
                    a=params['a'],
                    q=1,
                    f_c=params['f_c'],
                    f_s=params['f_s'],
                    ldc_1=ldc,
                    ldc_2=None,
                    gdc_1=None,
                    gdc_2=None,
                    didt=None,
                    domdt=None,
                    rotfac_1=1,
                    rotfac_2=1,
                    hf_1=1.5,
                    hf_2=1.5,
                    bfac_1=None,
                    bfac_2=None,
                    heat_1=None,
                    heat_2=None,
                    lambda_1=None,
                    lambda_2=None,
                    vsini_1=None,
                    vsini_2=None,
                    t_exp=None,
                    n_int=None,
                    grid_1='default',
                    grid_2='default',
                    ld_1=ld,
                    ld_2=None,
                    shape_1='sphere',
                    shape_2='sphere',
                    spots_1=None,
                    spots_2=None,
                    exact_grav=False,
                    verbose=1)
Ejemplo n.º 12
0
def basic_model(t, radius_1, radius_2, sbratio, incl, t_zero, q, period,
                heat_2, scale_factor):
    """ A function which returns model values at times t for parameters pars

    input:
        t    a 1D array with times
        pars a 1D array with parameter values; r1,r2,J,i,t0,p

    output:
        m    a 1D array with model values at times t

    """
    grid = "very_sparse"
    try:
        m = ellc.lc(t_obs=t,
                    radius_1=radius_1,
                    radius_2=radius_2,
                    sbratio=sbratio,
                    incl=incl,
                    t_zero=t_zero,
                    q=q,
                    period=period,
                    shape_1='sphere',
                    shape_2='roche',
                    ldc_1=0.2,
                    ldc_2=0.4548,
                    gdc_2=0.61,
                    f_c=0,
                    f_s=0,
                    t_exp=3.0 / 86400,
                    grid_1=grid,
                    grid_2=grid,
                    heat_2=heat_2,
                    exact_grav=False,
                    verbose=0)
        m *= scale_factor
    except:
        return t * 10**99

    return m
Ejemplo n.º 13
0
def basic_model(t, pars, grid='default'):
    """ a function which returns model values at times t for parameters pars

    input:
        t    a 1D array with times
        pars a 1D array with parameter values; r1,r2,J,i,t0,p

    output:
        m    a 1D array with model values at times t

    """
    try:
        m = ellc.lc(t_obs=t,
                    radius_1=pars[0],
                    radius_2=pars[1],
                    sbratio=pars[2],
                    incl=pars[3],
                    t_zero=pars[4],
                    q=pars[7],
                    period=pars[8],
                    shape_1='sphere',
                    shape_2='roche',
                    ldc_1=0.2,
                    ldc_2=0.4548,
                    gdc_2=0.61,
                    f_c=0,
                    f_s=0,
                    t_exp=3.0 / 86400,
                    grid_1=grid,
                    grid_2=grid,
                    heat_2=pars[6],
                    exact_grav=True,
                    verbose=0)
        m *= pars[5]

    except:
        print("Failed with parameters:", pars)
        return t * 10**99

    return m
Ejemplo n.º 14
0
    def _f(self, c, k, incl, law):
        if law in ("power-2"):
            h1, h2 = q1q2_to_h1h2(c[0], c[1])
            c2, a2 = h1h2_to_ca(h1, h2)
            ldc_1 = [c2, a2]
        else:
            ldc_1 = c

        try:
            lc_fit = lc(self._t,
                        radius_1=0.1,
                        radius_2=0.1 * k,
                        sbratio=0,
                        incl=incl,
                        ld_1=law,
                        ldc_1=ldc_1,
                        grid_1=self._gridsize,
                        grid_2=self._gridsize)
        except:
            lc_fit = zero_like(self._t)
        rms = np.sqrt(np.mean((lc_fit - self._lc_mugrid)**2))
        return rms
Ejemplo n.º 15
0
def light_curve_model(t_obs, t0, period, radius_1, radius_2, sbratio, incl,
                      f_c, f_s, ldc_1):

    lc_model = ellc.lc(t_obs=t_obs,
                       radius_1=radius_1,
                       radius_2=radius_2,
                       sbratio=sbratio,
                       incl=incl,
                       t_zero=t0,
                       period=period,
                       q=0.21864444,
                       a=14.6,
                       t_exp=0.02044,
                       n_int=5,
                       f_c=f_c,
                       f_s=f_s,
                       ldc_1=ldc_1,
                       ldc_2=0.6,
                       ld_1='lin',
                       ld_2='lin',
                       grid_1='very_sparse',
                       grid_2='very_sparse')
    return lc_model
Ejemplo n.º 16
0
def transit_model(time,
                  rr=0.1,
                  rsuma=0.1,
                  cosi=0,
                  epoch=0,
                  period=1,
                  ldc=[0.5, 0.5]):
    params = {
        'b_rr': rr,
        'b_rsuma': rsuma,
        'b_cosi': cosi,
        'b_epoch': epoch,
        'b_period': period,
    }

    companion = 'b'
    params[companion +
           '_radius_1'] = params[companion +
                                 '_rsuma'] / (1. + params[companion + '_rr'])
    params[companion +
           '_radius_2'] = params[companion + '_radius_1'] * params[companion +
                                                                   '_rr']
    params[companion +
           '_incl'] = np.arccos(params[companion + '_cosi']) / np.pi * 180.

    model_flux = ellc.lc(t_obs=time,
                         radius_1=params[companion + '_radius_1'],
                         radius_2=params[companion + '_radius_2'],
                         sbratio=0.,
                         incl=params[companion + '_incl'],
                         t_zero=params[companion + '_epoch'],
                         period=params[companion + '_period'],
                         ldc_1=ldc,
                         ld_1='quad',
                         verbose=False)

    return model_flux
Ejemplo n.º 17
0
                      ld_2=ld_2,
                      ldc_2=ldc_2,
                      a=0.737,
                      period=period,
                      shape_1=shape,
                      shape_2=shape,
                      flux_weighted=False)

lc_1 = ellc.lc(time,
               t_zero=0.0,
               q=1 / q,
               heat_1=heat,
               radius_1=r_2,
               radius_2=r_1,
               incl=incl,
               sbratio=1. / sbratio,
               a=0.737,
               period=period,
               ld_1=ld_2,
               ldc_1=ldc_2,
               ld_2=ld_1,
               ldc_2=ldc_1,
               shape_1=shape,
               shape_2=shape)
lc_1 = lc_1 / np.min(lc_1)
rv_1, dummy = ellc.rv(time,
                      t_zero=0.0,
                      q=1 / q,
                      heat_1=heat,
                      radius_1=r_2,
                      radius_2=r_1,
                      incl=incl,
Ejemplo n.º 18
0
ld_2 = 'claret'
ldc_2 = [a1, a2, a3, a4]
print('y_1 = ', y_1)
print('y_2 = ', y_2)

alpha = 0.5
lc_1 = lc(phase,
          t_zero=0.5,
          q=q,
          radius_1=r_1,
          radius_2=r_2,
          incl=incl,
          sbratio=sbratio,
          ld_1=ld_2,
          ldc_1=ldc_1,
          gdc_1=y_1,
          ld_2=ld_2,
          ldc_2=ldc_2,
          gdc_2=y_2,
          heat_1=alpha,
          heat_2=alpha,
          shape_1=shape_1,
          shape_2=shape_2,
          exact_grav=False,
          verbose=3)

heat_1 = [0.35, 1.0, np.sum(ldc_1)]
heat_2 = [0.35, 1.0, np.sum(ldc_2)]
lc_2 = lc(phase,
          t_zero=0.5,
          q=q,
Ejemplo n.º 19
0
def ellc(t_obs,
         radius_1=r1 / a,
         radius_2=r2 / a,
         sbratio=0.5,
         incl=80,
         light_3=0,
         t_zero=0,
         period=P0,
         a=a,
         q=m1 / m2,
         f_c=None,
         f_s=None,
         ldc_1=None,
         ldc_2=None,
         gdc_1=None,
         gdc_2=None,
         didt=None,
         domdt=None,
         rotfac_1=1,
         rotfac_2=1,
         hf_1=1.5,
         hf_2=1.5,
         bfac_1=None,
         bfac_2=None,
         heat_1=None,
         heat_2=None,
         lambda_1=None,
         lambda_2=None,
         vsini_1=None,
         vsini_2=None,
         t_exp=None,
         n_int=None,
         grid_1='default',
         grid_2='default',
         ld_1=None,
         ld_2=None,
         shape_1='sphere',
         shape_2='sphere',
         spots_1=None,
         spots_2=None,
         exact_grav=False,
         verbose=1):
    """
    Uses ellc binary star model [1] to create light curve of binary star system
    See lc.py for documentation of all params and defaults
    
    INPUT:
            t = time array from time() function
                Default: n=100, mean_dt=3, sig_t=2
                
            r1, r2 = radii of the objects
                Default: r1 = 1.5e-2 rsun, r2 = 3e-2 rsun
                
            a = semi-major axis of binary system
                Default: 10e-2 rsun
                
            sbratio = surface brightness ratio
                Default: 0.5
                
            incl = inclination of orbit
                Default: 80 deg
                
            period = period of orbit (assumes p dot = 0)
                Default: 0.005 days (432 s)
                
            m1, m2 = masses of objects
                Default: m1 = 0.5 msun, m2 = 0.25 msun
           
           (for other params, see ellc/lc.py documentation)
                
    OUTPUT:
            flux = flux array for binary system
       
    ------------
    References:
        [1] Maxted, P.F.L. 2016. A fast, flexible light curve model for detached
            eclipsing binary stars and transiting exoplanets. A&A 591, A111, 2016.
    """

    flux = lc(t_obs=t_obs,
              radius_1=radius_1,
              radius_2=radius_2,
              sbratio=sbratio,
              incl=incl,
              period=period,
              q=q,
              a=a,
              light_3=light_3,
              t_zero=t_zero,
              f_c=f_c,
              f_s=f_s,
              ldc_1=ldc_1,
              ldc_2=ldc_2,
              gdc_1=gdc_1,
              gdc_2=gdc_2,
              didt=didt,
              domdt=domdt,
              rotfac_1=rotfac_1,
              rotfac_2=rotfac_2,
              hf_1=hf_1,
              hf_2=hf_2,
              bfac_1=bfac_1,
              bfac_2=bfac_2,
              heat_1=heat_1,
              heat_2=heat_2,
              lambda_1=lambda_1,
              lambda_2=lambda_2,
              vsini_1=vsini_1,
              vsini_2=vsini_2,
              t_exp=t_exp,
              n_int=n_int,
              grid_1=grid_1,
              grid_2=grid_2,
              ld_1=ld_1,
              ld_2=ld_2,
              shape_1=shape_1,
              shape_2=shape_2,
              spots_1=spots_1,
              spots_2=spots_2,
              exact_grav=exact_grav,
              verbose=verbose)

    return np.array(flux)
Ejemplo n.º 20
0
def main():

    parser = argparse.ArgumentParser(
        description='Optimize limb-darkening coefficients',
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=textwrap.dedent('''\

        Optimize limb-darkening coefficients by fitting a transit light curve

        Input files containing centre-to-limb intensity profile must have three
        columns with mu in the _2nd_ column and intensity in the _3rd_column.

        N.B. input data must be in ascending order of mu.

        Currently only implements power-2 law - others to be added.
        
        The output is a single line with the parameters in the following order

            profile c alpha h_1 h_2 q_1 q_2 rms

        rms is the root-mean-square residual of the fit to the transit light
        curve in ppm.

        
        Notes
        ~~~~~
        - If repeated intensity values with mu=0 are present at the start of
           the data file then only the last one in the list is used.
        - If the data file does not contain data at mu=0, I(0)=0 will be used. 
        - If the data file does not contain data at mu=1, I(1)=1 will be used. 

        --
    '''))

    parser.add_argument(
        'profile',
        nargs='+',
        help='File with intensity profile, mu in col. 2, I(mu) in col. 3')

    parser.add_argument('-r',
                        '--resample',
                        default=101,
                        type=int,
                        help='''Re-sample input data  
         Input data are interpolated onto regular grid with specifed number of
        points. Set this value to 0 to avoid re-sampling if the input data are
        already on a regular grid of mu values. 
        (default: %(default)d)
        ''')

    parser.add_argument('-n',
                        '--n_lc',
                        default=64,
                        type=int,
                        help='''Number of points in the simulated light curve.
        (default: %(default)d)
        ''')

    parser.add_argument('-b',
                        '--impact',
                        default=0.0,
                        type=float,
                        help='''Impact parameter for simulated light curve
        (default: %(default)f)
        ''')

    parser.add_argument(
        '-k',
        '--ratio',
        default=0.1,
        type=float,
        help='''Planet-star radius ratio for simulated light curve
        (default: %(default)f)
        ''')

    parser.add_argument('-g',
                        '--grid',
                        default='sparse',
                        type=str,
                        help='''Density of numerical grid for simulation
        Options are 'very_sparse', 'sparse', 'default', 'fine' and 'very_fine'
        (default: %(default)s)
        ''')

    args = parser.parse_args()

    # Fixed parameters, might change these to input options later, idk
    r_1 = 0.1  # star radius/a

    w = 0.5 * transit_width(r_1, args.ratio, args.impact)
    t = np.linspace(0, w, args.n_lc, endpoint=False)
    for profile in args.profile:
        mu, I_mu = np.loadtxt(profile, unpack=True, usecols=[1, 2])
        # Deal with repeated data at mu=0
        if sum(mu == 0) > 1:
            j = np.arange(len(mu))[mu == 0].max()
            mu = mu[j:]
            I_mu = I_mu[j:]
        elif sum(mu == 0) == 0:
            mu = np.array([0, *mu])
            I_mu = np.array([0, *I_mu])
        if sum(mu == 1) == 0:
            mu = np.array([*mu, 1])
            I_mu = np.array([*I_mu, 1])
        if args.resample > 0:
            mu_1 = np.linspace(0, 1, args.resample)
            ldc_1 = pchip_interpolate(mu, I_mu, mu_1)
        else:
            ldc_1 = mu
        incl = 180 * np.arccos(r_1 * args.impact) / np.pi
        lc_mugrid = lc(t,
                       radius_1=r_1,
                       radius_2=r_1 * args.ratio,
                       sbratio=0,
                       incl=incl,
                       ld_1='mugrid',
                       ldc_1=ldc_1,
                       grid_1=args.grid,
                       grid_2=args.grid)

        c = np.array([0.3, 0.45])  # q1, q2
        smol = np.sqrt(np.finfo(float).eps)
        soln = minimize(func,
                        c,
                        args=(t, r_1, args.ratio, incl, args.grid, lc_mugrid),
                        method='L-BFGS-B',
                        bounds=((smol, 1 - smol), (smol, 1 - smol)))
        q1, q2 = soln.x
        h1, h2 = q1q2_to_h1h2(q1, q2)
        c2, a2 = h1h2_to_ca(h1, h2)
        print(
            f"{profile} {c2:0.5f} {a2:0.5f} {h1:0.5f} {h2:0.5f} {q1:0.5f} {q2:0.5f} {soln.fun*1e6:5.2f}"
        )
Ejemplo n.º 21
0
om = 90
f_c = np.sqrt(ecc) * np.cos(om * np.pi / 180.)
f_s = np.sqrt(ecc) * np.sin(om * np.pi / 180.)

t = phase * period
lc = ellc.lc(t,
             t_zero=t_zero,
             period=period,
             a=a,
             q=q,
             ld_1=ld_1,
             ldc_1=ldc_1,
             ld_2=ld_2,
             ldc_2=ldc_2,
             radius_1=r_1,
             radius_2=r_2,
             incl=incl,
             sbratio=sbratio,
             rotfac_1=rotfac_1,
             rotfac_2=rotfac_2,
             gdc_1=gdc_1,
             gdc_2=gdc_2,
             shape_1=shape_1,
             shape_2=shape_2,
             grid_1='default',
             grid_2='default')
rv_ellc_2, rv_ellc_1 = ellc.rv(t,
                               t_zero=t_zero,
                               period=period,
                               a=a,
                               q=q,
Ejemplo n.º 22
0
ldc_1 = [0.1, 0.3]
ld_1 = 'quad'
sbratio = 0
e = 0.1
om = 60
f_s = np.sqrt(e) * np.sin(om * np.pi / 180.)
f_c = np.sqrt(e) * np.cos(om * np.pi / 180.)
q = 0.001

flux_0 = ellc.lc(t,
                 radius_1=r_1,
                 radius_2=r_2,
                 incl=incl,
                 sbratio=sbratio,
                 ld_1=ld_1,
                 ldc_1=ldc_1,
                 shape_1='sphere',
                 shape_2='sphere',
                 grid_1='default',
                 grid_2='default',
                 f_s=f_s,
                 f_c=f_c)

flux_2 = ellc.lc(t,
                 radius_1=r_1,
                 radius_2=r_2,
                 incl=incl,
                 sbratio=sbratio,
                 ld_1=ld_1,
                 ldc_1=ldc_1,
                 shape_1='sphere',
Ejemplo n.º 23
0
def lnlike(par,
           lc_wasp,lc_nites,lc_oed,lc_byu,lc_kpno,radvel,
           period, t_zero, q, ldc_white, ldc_iband, ldc_jband, 
           n_int_nites, n_int_kpno):

  r_1, r_2, incl, f_s, f_c, sbratio_jband, K_1 = par

# For the WASP data, only need to calculate the light curve in the region of
# the transit. Phase here puts transit at phase 0.5 (for convenince).
  ph_wasp = (1.5 + (((lc_wasp['HJD']-t_zero)/period) % 1)) % 1
  m = np.zeros_like(lc_wasp['HJD'])
  try:
    m_tr = -2.5*np.log10(ellc.lc((lc_wasp['HJD'])[abs(ph_wasp-0.5) < 0.02], 
      radius_1=r_1, radius_2=r_2, incl=incl, sbratio=0,f_s=f_s, f_c=f_c,
      ld_1='quad', ldc_1 = ldc_white, period=period, t_zero=t_zero ,
      grid_1='sparse',grid_2='sparse'))
    m[abs(ph_wasp-0.5) < 0.02] = m_tr
    res = lc_wasp['dmag']-m
    wt = 1./lc_wasp['e_dmag']**2
    zp = np.sum(res*wt)/np.sum(wt)
    chisq_wasp = np.sum((res-zp)**2*wt)
  except:
    chisq_wasp = 1e20
  
  try:
    m = -2.5*np.log10(ellc.lc(lc_nites['HJD'], radius_1=r_1, radius_2=r_2,
      incl=incl, sbratio=0,f_s=f_s, f_c=f_c, ld_1='quad', ldc_1 = ldc_white,
      period=period, t_zero=t_zero, n_int=n_int_nites ,
      grid_1='sparse',grid_2='sparse') )
    res = lc_nites['dmag']-m
    wt = 1./lc_nites['e_dmag']**2
    zp = np.sum(res*wt)/np.sum(wt)
    chisq_nites = np.sum((res-zp)**2*wt)
  except:
    chisq_nites = 1e20
  
  try:
    m = -2.5*np.log10(ellc.lc(lc_oed['HJD'], radius_1=r_1, radius_2=r_2,
      incl=incl, sbratio=0,f_s=f_s, f_c=f_c, ld_1='quad', ldc_1 = ldc_iband,
      period=period, t_zero=t_zero , grid_1='sparse',grid_2='sparse'))
    res = lc_oed['dmag']-m
    wt = 1./lc_oed['e_dmag']**2
    zp = np.sum(res*wt)/np.sum(wt)
    chisq_oed = np.sum((res-zp)**2*wt)
  except:
    chisq_oed = 1e20
  
  try:
    m = -2.5*np.log10(ellc.lc(lc_byu['HJD'], radius_1=r_1, radius_2=r_2,
      incl=incl, sbratio=0,f_s=f_s, f_c=f_c, ld_1='quad', ldc_1 = ldc_iband,
      period=period, t_zero=t_zero, grid_1='sparse',grid_2='sparse' ))
    res = lc_byu['dmag']-m
    wt = 1./lc_byu['e_dmag']**2
    zp = np.sum(res*wt)/np.sum(wt)
    chisq_byu = np.sum((res-zp)**2*wt)
  except:
    chisq_byu = 1e20
    
  # Calculate semi-major axis
  ecc = f_s**2 + f_c**2
  a_1 = 0.019771142 * K_1 * period * np.sqrt(1 - ecc**2)/np.sin(incl*np.pi/180)
  a = (1+1/q)*a_1

  # kpno secondary eclipse - include semi-major axis for light time correction
  try:
    m = -2.5*np.log10(ellc.lc(lc_kpno['HJD'], radius_1=r_1, radius_2=r_2,
      incl=incl, sbratio=sbratio_jband,f_s=f_s, f_c=f_c, ld_2='quad', a=a, 
      ldc_2 = ldc_jband, period=period, t_zero=t_zero, n_int=n_int_kpno ,
      grid_1='sparse',grid_2='sparse'))
    res = lc_kpno['dmag']-m
    wt = 1./lc_kpno['e_dmag']**2
    zp = np.sum(res*wt)/np.sum(wt)
    chisq_kpno = np.sum((res-zp)**2*wt)
  except:
    chisq_kpno = 1e20

  # Radial velocity
  try:
    rv1,rv2 = ellc.rv(radvel['HJD'], radius_1=r_1, radius_2=r_2, incl=incl, 
                 q=q,sbratio=0,f_s=f_s, f_c=f_c, a=a, period=period, 
                 t_zero=t_zero, flux_weighted=False,
                 grid_1='very_sparse',grid_2='very_sparse')
    res = radvel['RV']-rv1
    wt = 1./radvel['e_RV']**2
    zp = np.sum(res*wt)/np.sum(wt)
    chisq_rv = np.sum((res-zp)**2*wt)
  except:
    chisq_rv = 1e20

  chisq = (chisq_wasp + chisq_nites + chisq_byu + chisq_oed + chisq_kpno + 
           chisq_rv)
  print(list(map(prettyfloat,[r_1, r_2, incl, f_s, f_c, sbratio_jband,
    K_1,chisq])))
  return -0.5*chisq
Ejemplo n.º 24
0
print('Median acceptance fraction =',np.median(af))
print('Range of  acceptance fraction =',np.min(af),' to ', np.max(af))
# Plot fit to lightcurves
fig=plt.figure(2,figsize=(5,7))

ph_mod = np.arange(-0.024,0.025,0.001)
offstep = 0.08
offset = 0 

ph_wasp = (1 + (((lc_wasp['HJD']-t_zero)/period) % 1)) % 1
plt.scatter(ph_wasp   ,lc_wasp['dmag'],s=1)
plt.scatter(ph_wasp-1,lc_wasp['dmag'],s=1)
plt.xlim([-0.024,0.024])
plt.ylim([0.35,-0.03])
m = -2.5*np.log10(ellc.lc(ph_mod*period+t_zero, radius_1=r_1, radius_2=r_2,
      incl=incl, sbratio=0,f_s=f_s, f_c=f_c, ld_1='quad', ldc_1 = ldc_white,
      period=period, t_zero=t_zero, grid_1='sparse',grid_2='sparse' ))
plt.plot(ph_mod,m)
plt.text(-0.023,-0.019,'WASP')

offset += offstep
ph_nites = (1 + (((lc_nites['HJD']-t_zero)/period) % 1)) % 1
plt.scatter(ph_nites   ,lc_nites['dmag']+offset,s=1)
plt.scatter(ph_nites-1,lc_nites['dmag']+offset,s=1)
m = -2.5*np.log10(ellc.lc(ph_mod*period+t_zero, radius_1=r_1, radius_2=r_2,
      incl=incl, sbratio=0,f_s=f_s, f_c=f_c, ld_1='quad', ldc_1 = ldc_white,
      period=period, t_zero=t_zero , grid_1='sparse',grid_2='sparse'))
plt.plot(ph_mod,m+offset)
plt.text(-0.023,offset-0.019,'NITES')

offset += offstep
Ejemplo n.º 25
0
    def __call__(self,
                 T_eff,
                 log_g,
                 Fe_H,
                 k=0.1,
                 b=0.0,
                 law='power-2',
                 precision='low'):
        """

        :parameter T_eff: effective temperature in Kelvin
        
        :parameter log_g: log of the surface gravity in cgs units
       
        :parameter Fe/H: [Fe/H] in dex

        :parameter k: Radius ratio R_pl/R_star 

        :parameter b: Impact parameter (R_star/a)cos(incl) 
       
        :parameter law: Limb darkening law
       
        :param precision: 'low', 'medium' or 'high'
       
        :returns: array of coefficients 
       
        """

        self._mu_default = np.array(
            [0, 0.01, 0.05, 0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 0.9, 1.0])
        precision_to_gridsize = {
            "low": "very_sparse",
            "medium": "sparse",
            "high": "default"
        }
        self._gridsize = precision_to_gridsize.get(precision, None)
        if self._gridsize is None:
            raise ValueError("Invalid precision value", precision)

    # Fixed parameters
        n_mu = 51
        n_grid = 32

        mu = np.linspace(0, 1, n_mu)
        I_mu = self._interpolator(T_eff, log_g, Fe_H)
        ldc_1 = pchip_interpolate(self._mu_default, I_mu, mu)
        w = 0.5 * transit_width(0.1, k, b)
        # Avoid last contact point - occasional numerical problems
        self._t = np.linspace(0, w, n_grid, endpoint=False)
        incl = 180 * np.arccos(0.1 * b) / np.pi
        self._lc_mugrid = lc(self._t,
                             radius_1=0.1,
                             radius_2=0.1 * k,
                             sbratio=0,
                             incl=incl,
                             ld_1='mugrid',
                             ldc_1=ldc_1,
                             grid_1=self._gridsize,
                             grid_2=self._gridsize)

        if law in ("lin"):
            c = np.full(1, 0.5)
        elif law in ("quad", "log", "sqrt", "exp"):
            c = np.full(2, 0.5)
        elif law in ("power-2"):
            c = np.array([0.3, 0.45])  # q1, q2
        elif law in ("sing"):
            c = np.full(3, 0.5)
        elif law in ("claret"):
            c = np.full(4, 0.5)
        else:
            raise Exception("Invalid limb darkening law")

        if law in ("power-2"):
            smol = np.sqrt(np.finfo(float).eps)
            soln = minimize(self._f,
                            c,
                            args=(k, incl, law),
                            method='L-BFGS-B',
                            bounds=((smol, 1 - smol), (smol, 1 - smol)))
            h1, h2 = q1q2_to_h1h2(soln.x[0], soln.x[1])
            c2, a2 = h1h2_to_ca(h1, h2)
            c = np.array([c2, a2])
        else:
            soln = minimize(self._f, c, args=(k, incl, law))
            c = soln.x

        self._rms = soln.fun
        self._lc_fit = lc(self._t,
                          radius_1=0.1,
                          radius_2=0.1 * k,
                          sbratio=0,
                          incl=incl,
                          ld_1=law,
                          ldc_1=c,
                          grid_1=self._gridsize,
                          grid_2=self._gridsize)

        return c
Ejemplo n.º 26
0
incl = 29.3
q = 0.234
ld_1 = 'quad'
ldc_1 = [0.028, 0.264]
ld_2 = 'quad'
ldc_2 = [0.272, 0.567]
shape_1 = 'roche'
shape_2 = 'roche'
heat_2 = [0.6, 3.5, 0.0]
lc_1 = ellc.lc(phase,
               t_zero=t_zero,
               q=q,
               heat_2=heat_2,
               radius_1=r_1,
               radius_2=r_2,
               incl=incl,
               sbratio=sbratio,
               ld_1=ld_1,
               ldc_1=ldc_1,
               ld_2=ld_2,
               ldc_2=ldc_2,
               shape_1=shape_1,
               shape_2=shape_2)
heat_2 = [1.0, 1.5, 0.0]
lc_2 = ellc.lc(phase,
               t_zero=t_zero,
               q=q,
               heat_2=heat_2,
               radius_1=r_1,
               radius_2=r_2,
               incl=incl,
               sbratio=sbratio,
Ejemplo n.º 27
0
def flux_fct(params, inst, companion, xx=None):
    '''
    ! params must be updated via update_params() before calling this function !
    
    if phased, pass e.g. xx=np.linspace(-0.25,0.75,1000) amd t_exp_scalefactor=1./params[companion+'_period']
    '''
    if xx is None:
        xx    = config.BASEMENT.data[inst]['time'] + params['ttv_'+inst]
        t_exp = config.BASEMENT.settings['t_exp_'+inst]
        n_int = config.BASEMENT.settings['t_exp_n_int_'+inst]
    else:
        t_exp = None
        n_int = None
        
#    try:
    #::: planet and EB transit lightcurve model
    if params[companion+'_rr'] > 0:
        model_flux = ellc.lc(
                          t_obs =       xx, 
                          radius_1 =    params[companion+'_radius_1'], 
                          radius_2 =    params[companion+'_radius_2'], 
                          sbratio =     params[companion+'_sbratio_'+inst], 
                          incl =        params[companion+'_incl'], 
                          light_3 =     params['dil_'+inst],
                          t_zero =      params[companion+'_epoch'],
                          period =      params[companion+'_period'],
                          a =           params[companion+'_a'],
                          q =           params[companion+'_q'],
                          f_c =         params[companion+'_f_c'],
                          f_s =         params[companion+'_f_s'],
                          ldc_1 =       params['host_ldc_'+inst],
                          ldc_2 =       params[companion+'_ldc_'+inst],
                          gdc_1 =       params['host_gdc_'+inst],
                          gdc_2 =       params[companion+'_gdc_'+inst],
                          didt =        params['didt_'+inst], 
                          domdt =       params['domdt_'+inst], 
                          rotfac_1 =    params['host_rotfac_'+inst], 
                          rotfac_2 =    params[companion+'_rotfac_'+inst], 
                          hf_1 =        params['host_hf_'+inst], #1.5, 
                          hf_2 =        params[companion+'_hf_'+inst], #1.5,
                          bfac_1 =      params['host_bfac_'+inst],
                          bfac_2 =      params[companion+'_bfac_'+inst], 
                          heat_1 =      params['host_geom_albedo_'+inst]/2.,
                          heat_2 =      params[companion+'_geom_albedo_'+inst]/2.,
                          lambda_1 =    params['host_lambda_'+inst], 
                          lambda_2 =    params[companion+'_lambda_'+inst], 
                          vsini_1 =     params['host_vsini_'+inst],
                          vsini_2 =     params[companion+'_vsini_'+inst], 
                          t_exp =       t_exp,
                          n_int =       n_int,
                          grid_1 =      config.BASEMENT.settings['host_grid_'+inst],
                          grid_2 =      config.BASEMENT.settings[companion+'_grid_'+inst],
                          ld_1 =        config.BASEMENT.settings['host_ld_law_'+inst],
                          ld_2 =        config.BASEMENT.settings[companion+'_ld_law_'+inst],
                          shape_1 =     config.BASEMENT.settings['host_shape_'+inst],
                          shape_2 =     config.BASEMENT.settings[companion+'_shape_'+inst],
                          spots_1 =     params['host_spots_'+inst], 
                          spots_2 =     params[companion+'_spots_'+inst], 
                          verbose =     False
                          )
    else:
        model_flux = np.ones_like(xx)
    
    
    #::: flare lightcurve model
    if config.BASEMENT.settings['N_flares'] > 0:
        for i in range(1,config.BASEMENT.settings['N_flares']+1):
#            print(params['flare_tpeak_'+str(i)])
            model_flux += aflare1(xx, params['flare_tpeak_'+str(i)], params['flare_fwhm_'+str(i)], params['flare_ampl_'+str(i)], upsample=True, uptime=10)
#
#    print(xx)
#    print(model_flux)
#    import matplotlib.pyplot as plt
#    plt.figure(xx, model_flux, 'r-')
#    err

#    except:
#        for key in params:
#            print(key, '\t', params[key])
#        raise ValueError('flux_fct crashed for the parameters given above.')
    
    return model_flux
Ejemplo n.º 28
0
params['flare_tpeak_2'] = 0.5
params['flare_fwhm_2'] = 0.05
params['flare_ampl_2'] = 0.004

params['flare_tpeak_3'] = 1.4
params['flare_fwhm_3'] = 0.2
params['flare_ampl_3'] = 0.007

###############################################################################
#::: "truth" signal
###############################################################################
time = np.linspace(0, 3, 1000)
flux_ellc = ellc.lc(t_obs=time,
                    radius_1=params[planet + '_radius_1'],
                    radius_2=params[planet + '_radius_2'],
                    sbratio=0,
                    incl=params[planet + '_incl'],
                    t_zero=params[planet + '_epoch'],
                    period=params[planet + '_period'])

flux_flares = np.zeros_like(time)
for i in range(1, N_flares + 1):
    flux_flares += aflare1(time,
                           params['flare_tpeak_' + str(i)],
                           params['flare_fwhm_' + str(i)],
                           params['flare_ampl_' + str(i)],
                           upsample=False,
                           uptime=10)

flux = flux_ellc + flux_flares
flux += 1e-3 * np.random.randn(len(time))
Ejemplo n.º 29
0
###############################################################################
#::: "truth" signals
###############################################################################

#==============================================================================
#::: Leonardo
#==============================================================================
planet = 'b'
inst = 'Leonardo'
time_Leonardo = np.arange(0, 16, 5. / 60. / 24.)[::5]
time_Leonardo = time_Leonardo[(time_Leonardo < 2) | (time_Leonardo > 4)]
flux_Leonardo = ellc.lc(t_obs=time_Leonardo,
                        radius_1=params[planet + '_radius_1'],
                        radius_2=params[planet + '_radius_2'],
                        sbratio=params[planet + '_sbratio'],
                        incl=params[planet + '_incl'],
                        t_zero=params[planet + '_epoch'],
                        period=params[planet + '_period'],
                        ld_1=params['ld_1_' + inst],
                        ldc_1=params['ldc_1_' + inst])
flux_Leonardo += np.random.normal(0, 2e-3, size=len(flux_Leonardo))
flux_Leonardo += 1e-3 * np.exp(time_Leonardo / 4.7) * np.sin(
    time_Leonardo / 2.7)

flux_err_Leonardo = 2e-3 * np.ones_like(flux_Leonardo)
header = 'time,flux,flux_err'
X = np.column_stack((time_Leonardo, flux_Leonardo, flux_err_Leonardo))
np.savetxt(os.path.join(workdir, 'Leonardo.csv'),
           X,
           delimiter=',',
           header=header)
Ejemplo n.º 30
0
def _lnlike(varpar_v,
            lcdata,
            varpar_l,
            fixpar_d,
            priors,
            ldy_,
            n_spot_1,
            n_spot_2,
            grid_size,
            return_fit=False):

    try:
        r_1 = varpar_v[(([i for i, s in enumerate(varpar_l)
                          if s == 'r_1'])[0])]
    except:
        r_1 = fixpar_d['r_1']
    if (r_1 <= 0) or (r_1 > 1): return -np.inf

    try:
        r_2 = varpar_v[(([i for i, s in enumerate(varpar_l)
                          if s == 'r_2'])[0])]
    except:
        r_2 = fixpar_d['r_2']
    if (r_2 <= 0) or (r_2 > 1): return -np.inf

    try:
        sb2 = varpar_v[(([i for i, s in enumerate(varpar_l)
                          if s == 'sb2'])[0])]
    except:
        sb2 = fixpar_d['sb2']
    if sb2 < 0: return -np.inf

    try:
        incl = varpar_v[(([i for i, s in enumerate(varpar_l)
                           if s == 'incl'])[0])]
    except:
        incl = fixpar_d['incl']
    if (incl <= 0) or (incl > 90): return -np.inf

    try:
        l_3 = varpar_v[(([i for i, s in enumerate(varpar_l)
                          if s == 'l_3'])[0])]
    except:
        l_3 = fixpar_d['l_3']

    try:
        t0 = varpar_v[(([i for i, s in enumerate(varpar_l) if s == 'T_0'])[0])]
    except:
        t0 = fixpar_d['T_0']

    try:
        period = varpar_v[(([i for i, s in enumerate(varpar_l)
                             if s == 'P'])[0])]
    except:
        period = fixpar_d['P']

    try:
        f_c = varpar_v[(([i for i, s in enumerate(varpar_l)
                          if s == 'f_c'])[0])]
    except:
        f_c = fixpar_d['f_c']
    if (f_c <= -1) or (f_c >= 1): return -np.inf

    try:
        f_s = varpar_v[(([i for i, s in enumerate(varpar_l)
                          if s == 'f_s'])[0])]
    except:
        f_s = fixpar_d['f_s']
    if (f_s <= -1) or (f_s >= 1): return -np.inf

    try:
        domdt = varpar_v[(([i for i, s in enumerate(varpar_l)
                            if s == 'domdt'])[0])]
    except:
        domdt = fixpar_d['domdt']
    if (domdt <= -1) or (domdt >= 1): return -np.inf

    try:
        frot1 = varpar_v[(([i for i, s in enumerate(varpar_l)
                            if s == 'F_1'])[0])]
    except:
        frot1 = fixpar_d['F_1']

    try:
        frot2 = varpar_v[(([i for i, s in enumerate(varpar_l)
                            if s == 'F_2'])[0])]
    except:
        frot2 = fixpar_d['F_2']

    try:
        t1 = varpar_v[(([i for i, s in enumerate(varpar_l)
                         if s == 'Teff1'])[0])]
    except:
        t1 = fixpar_d['Teff1']

    try:
        g1 = varpar_v[(([i for i, s in enumerate(varpar_l)
                         if s == 'logg1'])[0])]
    except:
        g1 = fixpar_d['logg1']

    try:
        t2 = varpar_v[(([i for i, s in enumerate(varpar_l)
                         if s == 'Teff2'])[0])]
    except:
        t2 = fixpar_d['Teff2']

    try:
        g2 = varpar_v[(([i for i, s in enumerate(varpar_l)
                         if s == 'logg2'])[0])]
    except:
        g2 = fixpar_d['logg2']

    try:
        m = varpar_v[(([i for i, s in enumerate(varpar_l)
                        if s == '[M/H]'])[0])]
    except:
        m = fixpar_d['[M/H]']

    try:
        A_1 = varpar_v[(([i for i, s in enumerate(varpar_l)
                          if s == 'A_1'])[0])]
    except:
        A_1 = fixpar_d['A_1']
    if A_1 < 0: return -np.inf

    try:
        A_2 = varpar_v[(([i for i, s in enumerate(varpar_l)
                          if s == 'A_2'])[0])]
    except:
        A_2 = fixpar_d['A_2']
    if A_2 < 0: return -np.inf

    try:
        tilt = varpar_v[(([i for i, s in enumerate(varpar_l)
                           if s == 'tilt'])[0])]
    except:
        tilt = fixpar_d['tilt']
    if tilt < 0: return -np.inf

    spots_1 = None
    if n_spot_1 > 0:
        try:
            s_1_1 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 's_1_1'
            ])[0])]
        except:
            s_1_1 = fixpar_d['s_1_1']
        if s_1_1 < 0: return -np.inf
        try:
            l_1_1 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'l_1_1'
            ])[0])]
        except:
            l_1_1 = fixpar_d['l_1_1']
        try:
            b_1_1 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'b_1_1'
            ])[0])]
        except:
            b_1_1 = fixpar_d['b_1_1']
        try:
            f_1_1 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'f_1_1'
            ])[0])]
        except:
            f_1_1 = fixpar_d['f_1_1']
        if f_1_1 < 0: return -np.inf
        spots_1 = [[l_1_1], [b_1_1], [s_1_1], [f_1_1]]

    if n_spot_1 > 1:
        try:
            s_2_1 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 's_2_1'
            ])[0])]
        except:
            s_2_1 = fixpar_d['s_2_1']
        if s_2_1 < 0: return -np.inf
        try:
            l_2_1 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'l_2_1'
            ])[0])]
        except:
            l_2_1 = fixpar_d['l_2_1']
        try:
            b_2_1 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'b_2_1'
            ])[0])]
        except:
            b_2_1 = fixpar_d['b_2_1']
        try:
            f_2_1 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'f_2_1'
            ])[0])]
        except:
            f_2_1 = fixpar_d['f_2_1']
        if f_2_1 < 0: return -np.inf
        spots_1 = [[l_1_1, l_2_1], [b_1_1, b_2_1], [s_1_1, s_2_1],
                   [f_1_1, f_2_1]]

    spots_2 = None
    if n_spot_2 > 0:
        try:
            s_1_2 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 's_1_2'
            ])[0])]
        except:
            s_1_2 = fixpar_d['s_1_2']
        if s_1_2 < 0: return -np.inf
        try:
            l_1_2 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'l_1_2'
            ])[0])]
        except:
            l_1_2 = fixpar_d['l_1_2']
        try:
            b_1_2 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'b_1_2'
            ])[0])]
        except:
            b_1_2 = fixpar_d['b_1_2']
        try:
            f_1_2 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'f_1_2'
            ])[0])]
        except:
            f_1_2 = fixpar_d['f_1_2']
        if f_1_2 < 0: return -np.inf
        spots_2 = [[l_1_2], [b_1_2], [s_1_2], [f_1_2]]

    if n_spot_2 > 1:
        try:
            s_2_2 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 's_2_2'
            ])[0])]
        except:
            s_2_2 = fixpar_d['s_2_2']
        if s_2_2 < 0: return -np.inf
        try:
            l_2_2 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'l_2_2'
            ])[0])]
        except:
            l_2_2 = fixpar_d['l_2_2']
        try:
            b_2_2 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'b_2_2'
            ])[0])]
        except:
            b_2_2 = fixpar_d['b_2_2']
        try:
            f_2_2 = varpar_v[(([
                i for i, s in enumerate(varpar_l) if s == 'f_2_2'
            ])[0])]
        except:
            f_2_2 = fixpar_d['f_2_2']
        if f_2_2 < 0: return -np.inf
        spots_2 = [[l_1_2, l_2_2], [b_1_2, b_2_2], [s_1_2, s_2_2],
                   [f_1_2, f_2_2]]

    a1, a2, a3, a4, y1 = ldy_(t1, g1, m)
    if np.isnan(y1):
        return -np.inf
    ldc_1 = [a1, a2, a3, a4]
    a1, a2, a3, a4, y2 = ldy_(t2, g2, m)
    if np.isnan(y2):
        return -np.inf
    ldc_2 = [a1, a2, a3, a4]

    heat_1 = A_1
    heat_2 = A_2

    q = fixpar_d['q']
    t_exp = fixpar_d['t_exp']
    if (t_exp <= 0) or (np.max(lcdata['flag']) < 2):
        t_exp = None

    if return_fit:
        n_int = np.array(lcdata['flag'])
        n_int[n_int < 0] = 1
        t = lcdata['time']
        f = lc(t,
               radius_1=r_1,
               radius_2=r_2,
               sbratio=sb2,
               incl=incl,
               light_3=l_3,
               t_zero=t0,
               period=period,
               q=q,
               f_c=f_c,
               f_s=f_s,
               domdt=domdt,
               rotfac_1=frot1,
               rotfac_2=frot2,
               heat_1=heat_1,
               heat_2=heat_2,
               n_int=n_int,
               ld_1='claret',
               ldc_1=ldc_1,
               ld_2='claret',
               ldc_2=ldc_2,
               gdc_1=y1,
               gdc_2=y2,
               t_exp=t_exp,
               grid_1=grid_size,
               grid_2=grid_size,
               shape_1='roche',
               shape_2='roche',
               spots_1=spots_1,
               spots_2=spots_2)

        m = tilt * (t - np.min(t)) - 2.5 * np.log10(f)
        m_mod = m[lcdata['flag'] >= 0]
        m_fit = (lcdata[lcdata['flag'] >= 0])['mag']
        e_fit = (lcdata[lcdata['flag'] >= 0])['e_mag']
        wt = 1.0 / e_fit**2
        zp = np.average((m_fit - m_mod), weights=wt)
        return m + zp

    # Check for input value outside range set by priors
    for p in priors:

        if p['p_type'] == 'U':
            if p['p_var'] in varpar_l:
                v = varpar_v[(([
                    i for i, s in enumerate(varpar_l) if s == p['p_var']
                ])[0])]
            elif p['p_var'] == 'e':
                v = f_c**2 + f_s**2
            elif p['p_var'] == 'om':
                v = np.arctan2(f_s, f_c)
            elif p['p_var'] == 'rsum':
                v = r_1 + r_2
            elif p['p_var'] == 'lrat':
                v = sb2 * (r_2 / r_1)**2
            elif p['p_var'] == 'k':
                v = r_2 / r_1
            else:
                raise Exception('No such prior variable')

            if (v < p['p_par1']) or (v > p['p_par2']):
                return -np.inf

    t_fit = (lcdata[lcdata['flag'] >= 0])['time']
    n_int = (lcdata[lcdata['flag'] >= 0])['flag']
    f = lc(t_fit,
           radius_1=r_1,
           radius_2=r_2,
           sbratio=sb2,
           incl=incl,
           light_3=l_3,
           t_zero=t0,
           period=period,
           q=q,
           f_c=f_c,
           f_s=f_s,
           domdt=domdt,
           rotfac_1=frot1,
           rotfac_2=frot2,
           heat_1=heat_1,
           heat_2=heat_2,
           n_int=n_int,
           ld_1='claret',
           ldc_1=ldc_1,
           ld_2='claret',
           ldc_2=ldc_2,
           gdc_1=y1,
           gdc_2=y2,
           t_exp=t_exp,
           grid_1=grid_size,
           grid_2=grid_size,
           shape_1='roche',
           shape_2='roche',
           spots_1=spots_1,
           spots_2=spots_2)

    if (True in np.isnan(f)) or np.min(f) <= 0: return -np.inf

    mod_fit = tilt * (t_fit - np.min(t_fit)) - 2.5 * np.log10(f)
    mag_fit = (lcdata[lcdata['flag'] >= 0])['mag']
    err_fit = (lcdata[lcdata['flag'] >= 0])['e_mag']
    wt = 1.0 / err_fit**2
    zp = np.average((mag_fit - mod_fit), weights=wt)
    mod_fit = mod_fit + zp
    lnlike = -0.5 * np.sum(wt * (mod_fit - mag_fit)**2)

    for p in priors:
        if p['p_type'] == 'G':
            if p['p_var'] in varpar_l:
                v = varpar_v[(([
                    i for i, s in enumerate(varpar_l) if s == p['p_var']
                ])[0])]
            elif p['p_var'] == 'e':
                v = f_c**2 + f_s**2
            elif p['p_var'] == 'om':
                v = np.arctan2(f_s, f_c)
            elif p['p_var'] == 'rsum':
                v = r_1 + r_2
            elif p['p_var'] == 'lrat':
                v = sb2 * (r_2 / r_1)**2
            elif p['p_var'] == 'k':
                v = r_2 / r_1
            else:
                raise Exception('No such prior variable')

            lnlike = lnlike - 0.5 * ((v - p['p_par1']) / (p['p_par2']))**2

    return lnlike