コード例 #1
0
def plot_fit(data, model):
    p = FormatParams(model.params, data)  #FIXME

    sns.set_palette("muted")
    palette = sns.color_palette("muted", data.nvisit)

    #ind = model.phase > 0.5
    #model.phase[ind] -= 1.

    #calculate a range of times at higher resolution to make model look nice
    phase_hr = np.linspace(model.phase.min() - 0.05,
                           model.phase.max() + 0.05, 1000)
    print "per", p.per
    t_hr = phase_hr * p.per[0] + p.t0[0]

    #plot data
    plt.subplot(211)
    #plot best fit model from first visit
    plt.plot(phase_hr, calc_astro(t_hr, model.params, data, model.myfuncs, 0))

    #plot systematics removed data
    for i in range(data.nvisit):
        ind = data.vis_num == i
        plt.plot(model.phase[ind],
                 model.data_nosys[ind],
                 color='b',
                 marker='o',
                 markersize=3,
                 linestyle="none")

    #add labels/set axes
    #xlo, xhi = np.min(model.phase)*0.9, np.max(model.phase)*1.1
    xlo, xhi = 0.38, 0.62
    plt.xlim(xlo, xhi)
    plt.ylabel("Relative Flux")

    #annotate plot with fit diagnostics
    ax = plt.gca()
    ax.text(0.85,
            0.29,
            '$\chi^2_\\nu$:    ' + '{0:0.2f}'.format(model.chi2red) + '\n' +
            'obs. rms:  ' + '{0:0d}'.format(int(model.rms)) + '\n' +
            'exp. rms:  ' + '{0:0d}'.format(int(model.rms_predicted)),
            verticalalignment='top',
            horizontalalignment='left',
            transform=ax.transAxes,
            fontsize=12)

    #plot fit residuals
    plt.subplot(212)
    plt.axhline(0, zorder=1, color='0.2', linestyle='dashed')

    for i in range(data.nvisit):
        ind = data.vis_num == i
        plt.plot(model.phase[ind],
                 1.0e6 * model.norm_resid[ind],
                 color='b',
                 marker='o',
                 markersize=3,
                 linestyle="none")

    #add labels/set axes
    plt.xlim(xlo, xhi)
    plt.ylabel("Residuals (ppm)")
    plt.xlabel("Orbital phase")

    plt.show()
コード例 #2
0
def plot_fit(data, model):
    p = FormatParams(model.params, data)  #FIXME

    sns.set_palette("muted")
    palette = sns.color_palette("muted", data.nvisit)

    #ind = model.phase > 0.5
    #model.phase[ind] -= 1.

    #calculate a range of times at higher resolution to make model look nice
    phase_hr = np.linspace(model.phase.min() - 0.05,
                           model.phase.max() + 0.05, 1000)
    t_hr = phase_hr * p.per[0] + p.t0[0]

    #plot data
    plt.subplot(211)
    #plt.title("Best fit white light curve, no eclipse")
    plt.title("Best fit white light curve, with eclipse")
    #plot best fit model from first visit
    #plt.plot(phase_hr, calc_astro(t_hr, model.params, data, model.myfuncs, 0))
    """data.time = np.linspace(0, 1., 1000)
    t0 = 2454163.22367
    phase = (data.time - t0)/per - np.floor((data.time - t0)/per)"""
    data.time = t_hr

    idx = phase_hr > -10000.
    plt.plot(phase_hr, calc_astro(idx, model.params, data, model.myfuncs, 0))

    #idx = data.vis_num == 0
    #plt.plot(model.phase[idx], calc_astro(idx, model.params, data, model.myfuncs, 0))

    colors = ['blue', 'red']
    #plot systematics removed data
    for i in range(data.nvisit):
        ind = data.vis_num == i
        plt.plot(model.phase[ind],
                 model.data_nosys[ind],
                 color=colors[i],
                 marker='o',
                 markersize=3,
                 linestyle="none")

    #add labels/set axes
    #xlo, xhi = np.min(model.phase)*0.9, np.max(model.phase)*1.1
    xlo, xhi = 0.35, 0.65
    plt.xlim(xlo, xhi)
    plt.ylabel("Relative Flux")

    #annotate plot with fit diagnostics
    """ax = plt.gca()
    ax.text( 0.85, 0.29, 
             '$\chi^2_\\nu$:    ' + '{0:0.2f}'.format(model.chi2red) + '\n'
            + 'obs. rms:  ' + '{0:0d}'.format(int(model.rms)) + '\n' 
            + 'exp. rms:  ' + '{0:0d}'.format(int(model.rms_predicted)), 
            verticalalignment='top',horizontalalignment='left', 
            transform=ax.transAxes, fontsize = 12
    )"""

    #plot fit residuals
    plt.subplot(212)
    plt.axhline(0, zorder=1, color='0.2', linestyle='dashed')

    for i in range(data.nvisit):
        ind = data.vis_num == i
        plt.plot(model.phase[ind],
                 1.0e6 * model.norm_resid[ind],
                 color=colors[i],
                 marker='o',
                 markersize=3,
                 linestyle="none")

    #add labels/set axes
    plt.xlim(xlo, xhi)
    plt.ylabel("Residuals (ppm)")
    plt.xlabel("Orbital phase")
    plt.tight_layout()
    plt.savefig("white_light.pdf")

    plt.show()