Пример #1
0
def test_get_morph():
    """Can we get the proper morphology type?"""
    ID = 'OGLE-BLG-ECL-040474'
    P = 1.8995918
    t0 = 7000.90650

    path_to_ogle = 'http://ogledb.astrouw.edu.pl/~ogle/OCVS/data/I/' + ID[
        -2:] + '/' + ID + '.dat'
    lc = np.loadtxt(path_to_ogle).T

    time = lc[0]
    mag = lc[1]
    err = lc[2]

    pf = Polyfitter(scale='mag')
    t0new, phase, polyfit, messages = pf.get_polyfit(time, mag, err, P, t0)

    assert_array_almost_equal(pf.c, np.array([0.42073795]))

    assert_array_almost_equal(pf.get_c(np.vstack((polyfit, polyfit))),
                              np.array([0.42073795, 0.42073795]))
    # This is in magnitude scale
    path_to_ogle = 'http://ogledb.astrouw.edu.pl/~ogle/OCVS/data/I/' + ID[
        -2:] + '/' + ID + '.dat'
    lc = np.loadtxt(path_to_ogle).T

    # For clarity
    time = lc[0]
    mag = lc[1]
    err = lc[2]

    # Create Polyfitter instance by setting the brightness scale of your data
    # Set "mag" or "flux" scale
    pf = Polyfitter(scale='mag')

    # Run polynomial chain fitting
    t0new, phase, polyfit, messages = pf.get_polyfit(time, mag, err, P, t0)

    # Plot and save phase curve and polyfit
    plt.errorbar((time - t0new) / P % 1, mag, err, fmt='k.')
    plt.errorbar((time - t0new) / P % 1 - 1, mag, err, fmt='k.')
    plt.plot(phase, polyfit, c='r', zorder=10)
    plt.plot(phase + 1, polyfit, c='r', zorder=10)
    plt.xlabel('Phase')
    plt.ylabel('Magnitude')
    plt.xlim(-0.5, 1)
    plt.gca().invert_yaxis()
    plt.tight_layout()
    plt.savefig(ID + '.pdf')
    plt.close()

    # Get morphology classification