def fit_rv_shift(template, orders):
    template_lines = []
    order_lines = []
    for t, o in zip(template, orders):
        plt.plot(t.x, t.y/t.cont, 'k-', alpha=0.4)
        plt.plot(o.x, o.y/o.cont, 'r-', alpha=0.5)

        tlines = FittingUtilities.FindLines(t, tol=0.8)
        olines = FittingUtilities.FindLines(o, tol=0.8)
        if len(tlines) == 0 or len(tlines) != len(olines):
            continue
        template_lines.append(t.x[tlines])
        order_lines.append(o.x[olines])
    template_lines = np.hstack(template_lines)
    order_lines = np.hstack(order_lines)
    rv = (np.median(order_lines/template_lines) - 1.0)*c
    #plt.scatter(template_lines, order_lines)
    #plt.plot(plt.xlim(), plt.xlim(), 'r--')
    plt.scatter(template_lines, order_lines - template_lines*(1.+rv/c))
    plt.show()
    return rv
示例#2
0
            order.cont = FittingUtilities.Continuum(order.x,
                                                    order.y,
                                                    fitorder=3,
                                                    lowreject=1.5,
                                                    highreject=10)
            fitter.ImportData(order)
            fitter.resolution_fit_mode = "gauss"
            fitter.fit_source = False
            fitter.fit_primary = False
            model = fitter.GenerateModel(fitpars,
                                         separate_source=False,
                                         return_resolution=False)

            # Find the best scale factor
            model.cont = np.ones(model.size())
            lines = FittingUtilities.FindLines(model, tol=0.95).astype(int)
            if len(lines) > 5:
                scale = np.median(
                    np.log(order.y[lines] / order.cont[lines]) /
                    np.log(model.y[lines]))
            else:
                scale = 1.0
            print i, scale
            h2o_scale.append(scale)

        # Now, find the best O2 scale factor
        o2_scale = []
        for i in FindOrderNums(orders, [630, 690]):
            print "\n***************************\nFitting order %i: " % (i)
            order = orders[i]
            fitter.AdjustValue({