Пример #1
0
def ringfunc(taun, *args):
    'cost function for ring fit to photometric data'
    (t, f, f_err, rad_ri, re, k, dst) = args
    # convolve and make smoothed ring photometry
    strip, dummy, g = exorings.ellipse_strip(rad_ri, \
        exorings.y_to_tau(taun), re[0], re[1], re[2], re[3], k, dst)

    # interpolate the smoothed curve....
    ring_model = interp1d(g[0], g[1], kind='linear')

    # ... to the times of the photometry
    ring_model_phot = ring_model(t)

    # calculate the residuals and the chi squared
    diff = f - ring_model_phot
    chisq = np.sum(np.power(diff / f_err, 2))
    red_chisq = chisq / diff.size

    return red_chisq
Пример #2
0
def ringfunc(taun, *args):
    'cost function for ring fit to photometric data'
    (t, f, f_err, rad_ri, re, k, dst) = args
    # convolve and make smoothed ring photometry
    strip, dummy, g = exorings.ellipse_strip(rad_ri, \
        exorings.y_to_tau(taun), re[0], re[1], re[2], re[3], k, dst)

    # interpolate the smoothed curve....
    ring_model = interp1d(g[0], g[1], kind='linear')

    # ... to the times of the photometry
    ring_model_phot = ring_model(t)

    # calculate the residuals and the chi squared
    diff = f - ring_model_phot
    chisq = np.sum(np.power(diff/f_err, 2))
    red_chisq = chisq / diff.size

    return red_chisq
Пример #3
0
def calc_ring_stats(taun, t, f, f_err, rad_ri, re, k, dst, tmin, tmax):
    'full statistics function for ring fit to photometric data'
    # convolve and make smoothed ring photometry
    strip, dummy, g = exorings.ellipse_strip(rad_ri, \
        exorings.y_to_tau(taun), re[0], re[1], re[2], re[3], k, dst)

    # select points within the rings_tmin/tmax range
    mask = (t > tmin) * (t < tmax)
    t_sel = t[mask]
    f_sel = f[mask]
    f_err_sel = f_err[mask]

    print '%d points in time range %.2f to %.2f' % (t_sel.size, tmin, tmax)

    # interpolate the smoothed curve....
    ring_model = interp1d(g[0], g[1], kind='linear')

    # ... to the times of the photometry
    ring_model_phot = ring_model(t_sel)

    # calculate the residuals and the chi squared
    diff = f_sel - ring_model_phot

    chisq = np.sum(np.power(diff/f_err_sel, 2))
    # degrees of freedom = number of photometry points - number of ring edges - 1
    dof = diff.size - taun.size - 1
    red_chisq = chisq / dof
    print 'number of photometric = %d ' % diff.size
    print 'number of ring edges  = %d ' % taun.size
    print 'number of DOF         = %d ' % dof
    print 'chi squared           = %.2f' % chisq
    print ' reduced chi squared  = %.2f' % red_chisq

    # http://en.wikipedia.org/wiki/Bayesian_information_criterion
    # n - number of points in data
    # k - number of free parameters
    # BIC = chisquared + k . ln(n) + C
    # C is a constant which does not change between candidate models but is
    # dependent on the data points

    BIC = chisq + (taun.size) * np.log(diff.size)
    print ' BIC                  = %.2f' % BIC
    return red_chisq
Пример #4
0
def calc_ring_stats(taun, t, f, f_err, rad_ri, re, k, dst, tmin, tmax):
    'full statistics function for ring fit to photometric data'
    # convolve and make smoothed ring photometry
    strip, dummy, g = exorings.ellipse_strip(rad_ri, \
        exorings.y_to_tau(taun), re[0], re[1], re[2], re[3], k, dst)

    # select points within the rings_tmin/tmax range
    mask = (t > tmin) * (t < tmax)
    t_sel = t[mask]
    f_sel = f[mask]
    f_err_sel = f_err[mask]

    print '%d points in time range %.2f to %.2f' % (t_sel.size, tmin, tmax)

    # interpolate the smoothed curve....
    ring_model = interp1d(g[0], g[1], kind='linear')

    # ... to the times of the photometry
    ring_model_phot = ring_model(t_sel)

    # calculate the residuals and the chi squared
    diff = f_sel - ring_model_phot

    chisq = np.sum(np.power(diff / f_err_sel, 2))
    # degrees of freedom = number of photometry points - number of ring edges - 1
    dof = diff.size - taun.size - 1
    red_chisq = chisq / dof
    print 'number of photometric = %d ' % diff.size
    print 'number of ring edges  = %d ' % taun.size
    print 'number of DOF         = %d ' % dof
    print 'chi squared           = %.2f' % chisq
    print ' reduced chi squared  = %.2f' % red_chisq

    # http://en.wikipedia.org/wiki/Bayesian_information_criterion
    # n - number of points in data
    # k - number of free parameters
    # BIC = chisquared + k . ln(n) + C
    # C is a constant which does not change between candidate models but is
    # dependent on the data points

    BIC = chisq + (taun.size) * np.log(diff.size)
    print ' BIC                  = %.2f' % BIC
    return red_chisq
Пример #5
0
def onclick(event):
    global rad_rings  # naughty, I know, I know...
    global taun_rings
    global badring

    for case in switch(event.key):

        newt = event.xdata
        newtau = event.ydata
        print 'newtau is %f' % newtau
        if newtau > 1.0:
            newtau = 1.0
        if newtau < 0.0:
            newtau = 0.000001
        newr = hjd_to_ring(newt + hjd_minr)

        if case('r'):
            exorings.plot_tilt_faceon(rad_rings, taun_rings, res, hjd_minr, dstar)

            break

        if case('v'):
            exorings.plot_tilt_faceon_vect(rad_rings, taun_rings, res, \
                hjd_minr, rstart, rend, dstar)

            break

        if case('a'):
            print 'a pressed, adding a new ring'
            # assume that r is ordered

            print ' inserting new ring date %d and radius %d' % (newt, newr)
            bigr = np.append(rad_rings, newr)
            bigtau = np.append(taun_rings, exorings.tau_to_y(newtau))

            # index sort r, rearrange both r and tau to this
            sortedr = np.argsort(bigr)
            rad_rings = bigr[sortedr]
            taun_rings = bigtau[sortedr]
            break

        if case('d'):
            if rad_rings.size > 1:
                # find closest ring distance
                rsel_idx = ind_ring(rad_rings, newr)
                rad_rings = np.delete(rad_rings, rsel_idx)
                taun_rings = np.delete(taun_rings, rsel_idx)
            break

        if case('m'):
            rsel_idx = ind_ring(rad_rings, newr)

            rad_rings[rsel_idx] = newr
            taun_rings[rsel_idx] = exorings.tau_to_y(newtau)

            break

        if case('b'):
            badring *= -1
            print badring

            break

        if case('o'):
            taun_rings = fmin(ringfunc, taun_rings, maxiter=1000, \
                args=(time, flux, flux_err, rad_rings, res, kern, dstar))

            break

        if case('q'):
            print 'q is for quitters'
            break
        if case():
            print 'not a recognised keypress'


    # print stats of fit
    calc_ring_stats(taun_rings, time, flux, flux_err, rad_rings, res, \
        kern, dstar, rings_tmin, rings_tmax)

    # regenerate drawing
    strip, dummy, g = exorings.ellipse_strip(rad_rings, exorings.y_to_tau(taun_rings), \
        res[0], res[1], res[2], res[3], kern, dstar)
    gt_abs = np.abs(g[0]-hjd_minr)
    g1 = g[1]
    gt_ingr = gt_abs[(g[0] <= hjd_minr)]
    gt_egr = gt_abs[(g[0] > hjd_minr)]
    g1_ingr = g1[(g[0] <= hjd_minr)]
    g1_egr = g1[(g[0] > hjd_minr)]

    # save the current axis ranges
    x1, x2 = h1.get_xlim()
    y1, y2 = h1.get_ylim()

    h1.cla()
    plot_folded_phot(fig_fold)
    h1.plot(event.xdata, event.ydata, color='green')
    h1.plot(np.abs(g[0]-hjd_minr), g[1])
    h1.plot(gt_ingr, g1_ingr, color='blue')
    h1.plot(gt_egr, g1_egr, color='red')
    h1.plot(np.abs(g[0]-hjd_minr), g[2], color='orange')
    h1.set_xlabel('Time from eclipse midpoint [days]')
    h1.set_ylabel('Transmission')

    # zoom back the the last view
    h1.set_xlim([x1, x2])
    h1.set_ylim([y1, y2])
    plt.draw()

    # save tmp version
    # erase old version otherwise write_ring_fits throws a fit
    if os.path.isfile('tmp.fits'):
        os.remove('tmp.fits')
    exorings.write_ring_fits('tmp.fits', res, taun_rings, rad_rings, dstar)
Пример #6
0
dstar = (Rstar * rsol * 2 / v) / 86400.

print 'Primary diameter = %5.2f  days' % dstar

if read_in_ring_parameters:
    print 'Reading in rings from %s' % fitsin_ring
    (resxx, taun_rings, rad_rings, xxxdstar) = exorings.read_ring_fits(fitsin_ring)
else:
    print "Starting with new rings...."
    rad_rings = np.array([59.0])
    taun_rings = np.array([0.0])
    rad_rings = np.append(rad_rings, (100.))
    taun_rings = np.append(taun_rings, (1000.))

exorings.print_ring_tau(rad_rings, exorings.y_to_tau(taun_rings))

if read_in_disk_parameters:
    print 'Reading in disk parameters from %s' % fitsin_disk
    (res, taun_ringsxx, rad_ringsxx, dstarxx) = exorings.read_ring_fits(fitsin_disk)
else:
    # run minimizer to find best guess values
    print 'No disk gradient parameters read in - refitting new ones....'
    res = fmin(costfunc, np.array([y, dt, i_deg, phi_deg]), maxiter=5000, \
        args=(grad_time, grad_mag_norm, tx))

# set up stellar disk
kern = exorings.make_star_limbd(21, 0.8)

# make the radius and projected gradient for the measured gradient points
(ring_disk_fit, grad_disk_fit) = exorings.ring_grad_line(grad_time, res[0], res[1], res[2], res[3])
Пример #7
0
for opt, arg in opts:
    if opt == '-h':
        print help
        sys.exit()
    elif opt in ("-r", "--rfile"):
        fitsin = arg
    elif opt in ("-o", "--ofile"):
        plotout = arg
    elif opt in ("-s", "--vstar"):
        v = np.array(float(arg))

print 'Reading in ring and disk parameters from %s' % fitsin
(res, taun_rings, rad_rings, dstar) = exorings.read_ring_fits(fitsin)

exorings.print_ring_tau(rad_rings, exorings.y_to_tau(taun_rings))

# set up stellar disk
kern = exorings.make_star_limbd(21, 0.8)

# make the radius and projected gradient for the measured gradient points
(ring_disk_fit,
 grad_disk_fit) = exorings.ring_grad_line(grad_time, res[0], res[1], res[2],
                                          res[3])

# produce fine grained gradient and ring values
samp_t = np.arange(-100, 100, 0.001) + 54222.
(samp_r, samp_g) = exorings.ring_grad_line(samp_t, res[0], res[1], res[2],
                                           res[3])
hjd_minr = samp_t[np.argmin(samp_g)]
Пример #8
0
for opt, arg in opts:
    if opt == '-h':
        print help
        sys.exit()
    elif opt in ("-r", "--rfile"):
        fitsin = arg
    elif opt in ("-o", "--ofile"):
        plotout = arg
    elif opt in ("-s", "--vstar"):
        v = np.array(float(arg))

print 'Reading in ring and disk parameters from %s' % fitsin
(res, taun_rings, rad_rings, dstar) = exorings.read_ring_fits(fitsin)

exorings.print_ring_tau(rad_rings, exorings.y_to_tau(taun_rings))

# set up stellar disk
kern = exorings.make_star_limbd(21, 0.8)

# make the radius and projected gradient for the measured gradient points
(ring_disk_fit,
 grad_disk_fit) = exorings.ring_grad_line(grad_time, res[0], res[1], res[2],
                                          res[3])

# produce fine grained gradient and ring values
samp_t = np.arange(-100, 100, 0.001) + 54222.
(samp_r, samp_g) = exorings.ring_grad_line(samp_t, res[0], res[1], res[2],
                                           res[3])
hjd_minr = samp_t[np.argmin(samp_g)]
for opt, arg in opts:
    if opt == '-h':
        print help
        sys.exit()
    elif opt in ("-r", "--rfile"):
        fitsin = arg
    elif opt in ("-o", "--ofile"):
        plotout = arg
    elif opt in ("-s", "--vstar"):
        v = np.array(float(arg))

print 'Reading in ring and disk parameters from %s' % fitsin
(res, taun_rings, rad_rings, dstar) = exorings.read_ring_fits(fitsin)

exorings.print_ring_tau(rad_rings, exorings.y_to_tau(taun_rings))

# set up stellar disk
kern = exorings.make_star_limbd(21, 0.8)

# make the radius and projected gradient for the measured gradient points
(ring_disk_fit, grad_disk_fit) = exorings.ring_grad_line(grad_time, res[0], res[1], res[2], res[3])

# produce fine grained gradient and ring values
samp_t = np.arange(-100, 100, 0.001) + 54222.
(samp_r, samp_g) = exorings.ring_grad_line(samp_t, res[0], res[1], res[2], res[3])
hjd_minr = samp_t[np.argmin(samp_g)]

# times when there is no photometry
(rstart, rend) = exorings.ring_mask_no_photometry(kern, dstar, time, res[0], res[1], res[2], res[3])
Пример #10
0
def onclick(event):
    global rad_rings  # naughty, I know, I know...
    global taun_rings
    global badring

    for case in switch(event.key):

        newt = event.xdata
        newtau = event.ydata
        print 'newtau is %f' % newtau
        if newtau > 1.0:
            newtau = 1.0
        if newtau < 0.0:
            newtau = 0.000001
        newr = hjd_to_ring(newt + hjd_minr)

        if case('r'):
            exorings.plot_tilt_faceon(rad_rings, taun_rings, res, hjd_minr,
                                      dstar)

            break

        if case('v'):
            exorings.plot_tilt_faceon_vect(rad_rings, taun_rings, res, \
                hjd_minr, rstart, rend, dstar)

            break

        if case('a'):
            print 'a pressed, adding a new ring'
            # assume that r is ordered

            print ' inserting new ring date %d and radius %d' % (newt, newr)
            bigr = np.append(rad_rings, newr)
            bigtau = np.append(taun_rings, exorings.tau_to_y(newtau))

            # index sort r, rearrange both r and tau to this
            sortedr = np.argsort(bigr)
            rad_rings = bigr[sortedr]
            taun_rings = bigtau[sortedr]
            break

        if case('d'):
            if rad_rings.size > 1:
                # find closest ring distance
                rsel_idx = ind_ring(rad_rings, newr)
                rad_rings = np.delete(rad_rings, rsel_idx)
                taun_rings = np.delete(taun_rings, rsel_idx)
            break

        if case('m'):
            rsel_idx = ind_ring(rad_rings, newr)

            rad_rings[rsel_idx] = newr
            taun_rings[rsel_idx] = exorings.tau_to_y(newtau)

            break

        if case('b'):
            badring *= -1
            print badring

            break

        if case('o'):
            taun_rings = fmin(ringfunc, taun_rings, maxiter=1000, \
                args=(time, flux, flux_err, rad_rings, res, kern, dstar))

            break

        if case('q'):
            print 'q is for quitters'
            break
        if case():
            print 'not a recognised keypress'

    # print stats of fit
    calc_ring_stats(taun_rings, time, flux, flux_err, rad_rings, res, \
        kern, dstar, rings_tmin, rings_tmax)

    # regenerate drawing
    strip, dummy, g = exorings.ellipse_strip(rad_rings, exorings.y_to_tau(taun_rings), \
        res[0], res[1], res[2], res[3], kern, dstar)
    gt_abs = np.abs(g[0] - hjd_minr)
    g1 = g[1]
    gt_ingr = gt_abs[(g[0] <= hjd_minr)]
    gt_egr = gt_abs[(g[0] > hjd_minr)]
    g1_ingr = g1[(g[0] <= hjd_minr)]
    g1_egr = g1[(g[0] > hjd_minr)]

    # save the current axis ranges
    x1, x2 = h1.get_xlim()
    y1, y2 = h1.get_ylim()

    h1.cla()
    plot_folded_phot(fig_fold)
    h1.plot(event.xdata, event.ydata, color='green')
    h1.plot(np.abs(g[0] - hjd_minr), g[1])
    h1.plot(gt_ingr, g1_ingr, color='blue')
    h1.plot(gt_egr, g1_egr, color='red')
    h1.plot(np.abs(g[0] - hjd_minr), g[2], color='orange')
    h1.set_xlabel('Time from eclipse midpoint [days]')
    h1.set_ylabel('Transmission')

    # zoom back the the last view
    h1.set_xlim([x1, x2])
    h1.set_ylim([y1, y2])
    plt.draw()

    # save tmp version
    # erase old version otherwise write_ring_fits throws a fit
    if os.path.isfile('tmp.fits'):
        os.remove('tmp.fits')
    exorings.write_ring_fits('tmp.fits', res, taun_rings, rad_rings, dstar)
Пример #11
0
dstar = (Rstar * rsol * 2 / v) / 86400.

print 'Primary diameter = %5.2f  days' % dstar

if read_in_ring_parameters:
    print 'Reading in rings from %s' % fitsin_ring
    (resxx, taun_rings, rad_rings,
     xxxdstar) = exorings.read_ring_fits(fitsin_ring)
else:
    print "Starting with new rings...."
    rad_rings = np.array([59.0])
    taun_rings = np.array([0.0])
    rad_rings = np.append(rad_rings, (100.))
    taun_rings = np.append(taun_rings, (1000.))

exorings.print_ring_tau(rad_rings, exorings.y_to_tau(taun_rings))

if read_in_disk_parameters:
    print 'Reading in disk parameters from %s' % fitsin_disk
    (res, taun_ringsxx, rad_ringsxx,
     dstarxx) = exorings.read_ring_fits(fitsin_disk)
else:
    # run minimizer to find best guess values
    print 'No disk gradient parameters read in - refitting new ones....'
    res = fmin(costfunc, np.array([y, dt, i_deg, phi_deg]), maxiter=5000, \
        args=(grad_time, grad_mag_norm, tx))

# set up stellar disk
kern = exorings.make_star_limbd(21, 0.8)

# make the radius and projected gradient for the measured gradient points
Пример #12
0
for opt, arg in opts:
    if opt == '-h':
        print help
        sys.exit()
    elif opt in ("-r", "--rfile"):
        fitsin = arg
    elif opt in ("-o", "--ofile"):
        plotout = arg
    elif opt in ("-s", "--vstar"):
        v = np.array(float(arg))

print 'Reading in ring and disk parameters from %s' % fitsin
(res, taun_rings, rad_rings, dstar) = exorings.read_ring_fits(fitsin)

exorings.print_ring_tau(rad_rings, exorings.y_to_tau(taun_rings))

# set up stellar disk
kern = exorings.make_star_limbd(21, 0.8)

# make the radius and projected gradient for the measured gradient points
(ring_disk_fit, grad_disk_fit) = exorings.ring_grad_line(grad_time, res[0], res[1], res[2], res[3])

# produce fine grained gradient and ring values
samp_t = np.arange(-100, 100, 0.001) + 54222.
(samp_r, samp_g) = exorings.ring_grad_line(samp_t, res[0], res[1], res[2], res[3])
hjd_minr = samp_t[np.argmin(samp_g)]

# times when there is no photometry
(rstart, rend) = exorings.ring_mask_no_photometry(kern, dstar, time, res[0], res[1], res[2], res[3])
rmask = (rstart < 40)
Пример #13
0
for opt, arg in opts:
    if opt == '-h':
        print help
        sys.exit()
    elif opt in ("-r", "--rfile"):
        fitsin = arg
    elif opt in ("-o", "--ofile"):
        plotout = arg
    elif opt in ("-s", "--vstar"):
        v = np.array(float(arg))

print 'Reading in ring and disk parameters from %s' % fitsin
(res, taun_rings, rad_rings, dstar) = exorings.read_ring_fits(fitsin)

exorings.print_ring_tau(rad_rings, exorings.y_to_tau(taun_rings))

# set up stellar disk
kern = exorings.make_star_limbd(21, 0.8)

# make the radius and projected gradient for the measured gradient points
(ring_disk_fit, grad_disk_fit) = exorings.ring_grad_line(grad_time, res[0], res[1], res[2], res[3])

# produce fine grained gradient and ring values
samp_t = np.arange(-100, 100, 0.001) + 54222.
(samp_r, samp_g) = exorings.ring_grad_line(samp_t, res[0], res[1], res[2], res[3])
hjd_minr = samp_t[np.argmin(samp_g)]

(rstart, rend) = exorings.ring_mask_no_photometry(kern, dstar, time, res[0], res[1], res[2], res[3])

rmask = (rstart < 40)