Esempio n. 1
0
            for i in range(pmask.sum()):
                objects.append({
                    'm':
                    float(data[pmask]['pl_bmassj'].iloc[i]) * mjup / msun,
                    'P':
                    float(data[pmask]['pl_orbper'].iloc[i]),
                    'inc':
                    3.14159 / 2,
                    'e':
                    float(data[pmask]['pl_orbeccen'].iloc[i]),
                    'omega':
                    0
                })

            # create REBOUND simulation
            sim = generate(objects)

            print(objects)
            # year long integrations, timestep = 1 hour
            sim_data = integrate(sim, objects, 20 * objects[-1]['P'],
                                 int(20 * objects[-1]['P'] * 24))

            # collect the analytics from the simulation
            ttv_data = analyze(sim_data)

            #if name=='Kepler-30':
            #    import pdb; pdb.set_trace()

            # save simulation data
            for i in range(pmask.sum()):
                iname = data[pmask].iloc[i].name
Esempio n. 2
0
def nbody_limits(newobj, nlstats, n=1):
    # TODO create wrapper?
    upper = np.copy(ttv)
    lower = np.copy(ttv)

    obj = copy.deepcopy(newobj)
    obj[2]['m'] = nlstats['marginals'][3][
        'median'] - n * nlstats['marginals'][3]['sigma']
    obj[2]['omega'] = nlstats['marginals'][5][
        'median'] - n * nlstats['marginals'][5]['sigma']
    sim_data = generate(obj, newobj[1]['P'] * (len(ttv) + 1),
                        int((len(ttv) + 1) * newobj[1]['P'] * 24))
    ttv_data = analyze(sim_data)
    for i in range(len(ttv_data['planets'][0]['ttv'])):
        try:
            upper[i] = max(upper[i], ttv_data['planets'][0]['ttv'][i])
            lower[i] = min(lower[i], ttv_data['planets'][0]['ttv'][i])
        except:
            pass

    obj = copy.deepcopy(newobj)
    obj[2]['m'] = nlstats['marginals'][3][
        'median'] - n * nlstats['marginals'][3]['sigma']
    sim_data = generate(obj, newobj[1]['P'] * (len(ttv) + 1),
                        int((len(ttv) + 1) * newobj[1]['P'] * 24))
    ttv_data = analyze(sim_data)
    for i in range(len(ttv_data['planets'][0]['ttv'])):
        try:
            upper[i] = max(upper[i], ttv_data['planets'][0]['ttv'][i])
            lower[i] = min(lower[i], ttv_data['planets'][0]['ttv'][i])
        except:
            pass

    obj = copy.deepcopy(newobj)
    obj[2]['m'] = nlstats['marginals'][3][
        'median'] + n * nlstats['marginals'][3]['sigma']
    sim_data = generate(obj, newobj[1]['P'] * (len(ttv) + 1),
                        int((len(ttv) + 1) * newobj[1]['P'] * 24))
    ttv_data = analyze(sim_data)
    for i in range(len(ttv_data['planets'][0]['ttv'])):
        try:
            upper[i] = max(upper[i], ttv_data['planets'][0]['ttv'][i])
            lower[i] = min(lower[i], ttv_data['planets'][0]['ttv'][i])
        except:
            pass

    obj = copy.deepcopy(newobj)
    obj[2]['m'] = nlstats['marginals'][3][
        'median'] - n * nlstats['marginals'][3]['sigma']
    obj[2]['omega'] = nlstats['marginals'][5][
        'median'] + n * nlstats['marginals'][5]['sigma']
    sim_data = generate(obj, newobj[1]['P'] * (len(ttv) + 1),
                        int((len(ttv) + 1) * newobj[1]['P'] * 24))
    ttv_data = analyze(sim_data)
    for i in range(len(ttv_data['planets'][0]['ttv'])):
        try:
            upper[i] = max(upper[i], ttv_data['planets'][0]['ttv'][i])
            lower[i] = min(lower[i], ttv_data['planets'][0]['ttv'][i])
        except:
            pass

    obj = copy.deepcopy(newobj)
    obj[2]['m'] = nlstats['marginals'][3][
        'median'] + n * nlstats['marginals'][3]['sigma']
    obj[2]['omega'] = nlstats['marginals'][5][
        'median'] - n * nlstats['marginals'][5]['sigma']
    sim_data = generate(obj, newobj[1]['P'] * (len(ttv) + 1),
                        int((len(ttv) + 1) * newobj[1]['P'] * 24))
    ttv_data = analyze(sim_data)
    for i in range(len(ttv_data['planets'][0]['ttv'])):
        try:
            upper[i] = max(upper[i], ttv_data['planets'][0]['ttv'][i])
            lower[i] = min(lower[i], ttv_data['planets'][0]['ttv'][i])
        except:
            pass

    obj = copy.deepcopy(newobj)
    obj[2]['m'] = nlstats['marginals'][3][
        'median'] + n * nlstats['marginals'][3]['sigma']
    obj[2]['omega'] = nlstats['marginals'][5][
        'median'] + n * nlstats['marginals'][5]['sigma']
    sim_data = generate(obj, newobj[1]['P'] * (len(ttv) + 1),
                        int((len(ttv) + 1) * newobj[1]['P'] * 24))
    ttv_data = analyze(sim_data)
    for i in range(len(ttv_data['planets'][0]['ttv'])):
        try:
            upper[i] = max(upper[i], ttv_data['planets'][0]['ttv'][i])
            lower[i] = min(lower[i], ttv_data['planets'][0]['ttv'][i])
        except:
            pass
    return upper, lower
Esempio n. 3
0
def get_ttv(objects, ndays=60, ttvfast=True):
    sim = generate(objects)
    sim_data = integrate(sim, objects, ndays, ndays * 24 * 2)  # dt=30 minutes
    return analyze(sim_data, ttvfast=ttvfast)
Esempio n. 4
0
    # plot the results 
    #report(ttv_data)

    periods = np.linspace(1.25*objects[1]['P'], 2.2*objects[1]['P'], 50 )
    #masses = np.linspace( objects[1]['m']*0.25, objects[1]['m']*6, 100 ) 
    masses = np.linspace( mearth/msun, 20*mearth/msun, 50 ) 
    
    ttvs = np.zeros((periods.shape[0],masses.shape[0]))

    for i in range(periods.shape[0]):
        print(i)
        for j in range(masses.shape[0]):
            objects[2]['P'] = periods[i]
            objects[2]['m'] = masses[j]

            sim_data = generate(objects, 180, 180*24)

            ttv_data = analyze(sim_data)

            ttvs[i,j] = ttv_data['planets'][0]['max']*24*60


    top = cm.get_cmap('viridis', 200)
    newcolors = top(np.linspace(0., 1, 200))
    newcolors[int(200* 2./30):int(200* 5./30), 3] = np.linspace(0,1,int(200* 5./30)-int(200* 2./30) ) # faded 1-3
    newcolors[:int(200* 2./30), 3] = 0 # white under 1 minutes
    newcmp = ListedColormap(newcolors)


    plt.imshow(ttvs, vmin=0, vmax=30, cmap=newcmp, origin='lower',
                extent=[ min(masses)*msun/mearth, max(masses)*msun/mearth, min(periods)/objects[1]['P'],max(periods)/objects[1]['P']],
Esempio n. 5
0
            #'omega':[ objects[2]['omega']-1,  objects[2]['omega']+1 ],
        }),
    ]
    print(bounds)

    newobj, nlposteriors, nlstats = nlfit( 
        data[~bmask,0], data[~bmask,1], data[~bmask,2], 
        objects, bounds,
        myloss='linear',
    )

    # O-C Model #######################################################################################
    ocdata_l = data[:,1] - ( data[:,0]*lstats['marginals'][1]['median'] + lstats['marginals'][0]['median'] )
    ocdata_nl = data[:,1] - ( data[:,0]*nlstats['marginals'][1]['median'] + nlstats['marginals'][0]['median'] )

    sim_data = generate(newobj, newobj[1]['P']* (data[:,0].max()+1), int( (data[:,0].max()+1)*newobj[1]['P']*24) )
    ttv_data = analyze(sim_data)
    upper, lower = nbody_limits( newobj, nlstats, ttv_data['planets'][0]['ttv'] )

    f,ax = plt.subplots(1, figsize=(7,4))
    ax.errorbar(data[:,0],ocdata_nl*24*60,yerr=data[:,2]*24*60,ls='none',marker='.',label='Data',color='black')
    ax.plot( ttv_data['planets'][0]['ttv']*24*60, label='Linear+Nbody ({:.1f})'.format(nlstats['global evidence']),color='red')
    ax.fill_between( np.arange(upper.shape[0]),24*60*upper,24*60*lower,alpha=0.1,label='Nbody 3 sigma',color='red')
    ax.axhline(ls='--',label='Linear ({:.1f})'.format(lstats['global evidence']))
    ax.legend(loc='best')
    ax.set_xlabel('Epochs')
    ax.set_xlim([min(data[:,0]),max(data[:,0])])
    ax.set_ylim([min(ocdata_nl)*24*60-1,max(ocdata_nl)*24*60+1])
    ax.set_ylabel('O-C [min]')
    ax.grid(True)
    plt.savefig('ttv_model.pdf',bbox_inches='tight')
    parser.add_argument("-o", "--omegas", help=help_, default=10, type=int)
    help_ = "Number of planet 1 orbital periods to integrate the simulation for"
    parser.add_argument("-p", "--periods", help=help_, default=30, type=int)

    args = parser.parse_args()

    try:
        X, y = pickle.load(open(args.file, 'rb'))
    except:
        X, y = [], []

    # seed simulation
    og_objects = randomize()
    sim_data = generate(
        og_objects,
        Ndays=og_objects[1]['P'] * args.periods + 1,
        Noutputs=round(og_objects[1]['P'] * args.periods * 24 +
                       24)  # dt = 1 hr
    )
    ttv_data = analyze(sim_data)
    # report(ttv_data)

    for ii in range(len(X), args.samples):

        print('simulation:', ii)

        # randomize objec ts
        og_objects = randomize()
        sim_data = generate(
            og_objects,
            Ndays=og_objects[1]['P'] * args.periods + 1,
            Noutputs=round(og_objects[1]['P'] * args.periods * 24 +
Esempio n. 7
0
        {
            'm': args.mass1,
            'P': args.period1,
            'inc': 3.14159 / 2,
            'e': 0,
            'omega': 0
        },
        {
            'm': (ypred[i, 1]) * mearth / msun,
            'P': ypred[i, 0],
            'inc': 3.14159 / 2,
            'e': ypred[i, 3],
            'omega': ypred[i, 2]
        },
    ]
    sim_data = generate(pred, max(data[:, 1]), int(max(data[:, 1]) * 24))
    ttv_pred = analyze(sim_data)

    ml_error = lambda x: x  # TODO

    nlstats = {
        'marginals': [
            {
                'median': 0,
                'sigma': 0
            },  # Tmid
            {
                'median': pred[1]['P'],
                'sigma': 0
            },  # P1
            {
Esempio n. 8
0
            'inc': 3.14159 / 2,
            'e': 0,
            'omega': 0
        },
        {
            'm': 40 * mearth / msun,
            'P': 7,
            'inc': 3.14159 / 2,
            'e': 0,
            'omega': 0
        },
        #{'m':0.432*mjup/msun, 'P':12, 'inc':3.14159/2, 'e':0,  'omega':0  },
    ]

    # create REBOUND simulation
    sim_data = generate(objects, objects[1]['P'] * 30,
                        int(30 * objects[1]['P'] * 24))

    # collect the analytics of interest from the simulation
    ttv_data = analyze(sim_data)

    # plot the results
    report(ttv_data, savefile='report.png')

    import numpy as np
    ttv = ttv_data['planets'][0]['ttv']
    epochs = np.arange(len(ttv))
    ttdata = ttv_data['planets'][0]['tt'] + np.random.normal(
        0, 0.5, len(ttv)) / (24 * 60)
    err = (30 + np.random.normal(30, 30, len(ttv))) / (24 * 60 * 60)
    np.vstack([epochs, ttdata, err]).T
    np.savetxt('sim_data.txt',
            'inc': [np.pi / 2 * 0.8, np.pi / 2 * 0.9],
            'e': [0.025, 0.05],
            'omega': [np.pi / 4, np.pi / 2],
            # add longitude of ascending node
        },
        {
            'm': [2 * mjup / msun, 10 * mjup / msun],
            'P': [6, 9],
            'inc': [np.pi / 2 * 0.8, np.pi / 2 * 0.9],
            'e': [0.05, 0.075],
            'omega': [np.pi / 4, np.pi / 2],
        },
    ]

    # run original simulation
    sim = generate(objects)
    sim_data = integrate(sim, objects, 180, 180 *
                         24)  # year long integrations, timestep = 1 minute
    ttv_data_og = analyze(sim_data)

    # create a plot
    f = plt.figure(figsize=(9, 13))
    plt.subplots_adjust()
    ax = [
        plt.subplot2grid((6, 2), (0, 0)),
        plt.subplot2grid((6, 2), (1, 0)),
        plt.subplot2grid((6, 2), (2, 0)),
        plt.subplot2grid((6, 2), (3, 0)),
        plt.subplot2grid((6, 2), (4, 0)),
        plt.subplot2grid((6, 2), (5, 0)),
        plt.subplot2grid((6, 2), (1, 1)),
Esempio n. 10
0
        'm': 1.12
    }, {
        'm': 0.25 * mjup / msun,
        'inc': 1.570795,
        'e': 0,
        'P': 3.2887967652699728
    }, {
        'e': 0.06,
        'inc': 1.570795,
        'm': 100 * mearth / msun,
        'P': 7.29,
        'omega': np.pi / 3,
    }]

    # create REBOUND simulation
    sim_data = generate(objects, 31 * objects[1]['P'],
                        int(31 * objects[1]['P'] * 24))
    ttv_data = analyze(sim_data)
    report(ttv_data)

    # simulate some observational data with noise
    ttv = ttv_data['planets'][0]['ttv']
    epochs = np.arange(len(ttv))
    ttdata = ttv_data['planets'][0]['tt'] + np.random.normal(
        0, 0.5, len(ttv)) / (24 * 60)
    err = np.random.normal(90, 30, len(ttv)) / (24 * 60 * 60)

    # perform nested sampling linear fit to transit data
    lstats, lposteriors = lfit(epochs,
                               ttdata,
                               err,
                               bounds=[