コード例 #1
0
ファイル: velocity.py プロジェクト: AtomyChan/JLU-python-code
def velocityAverage(alignRoot, polyRoot, magCut=15):
    """
    Calculate the mean (and error on mean) of the velocities from
    a align/polyfit.

    Input Parameters:
    -- the root name of the align output (e.g. 'align/align_d_rms_t'
    -- the root name of the polyfit output( e.g. 'polyfit_d/fit')
    """
    # This should be an absolute aligned data set. 
    cc = objects.Constants()
    s = starset.StarSet(alignRoot)
    s.loadPolyfit(polyRoot, accel=0)

    vx = s.getArray('fitXv.v') * 10**3
    vy = s.getArray('fitYv.v') * 10**3
    vxerr = s.getArray('fitXv.verr') * 10**3
    vyerr = s.getArray('fitYv.verr') * 10**3

    mag = s.getArray('mag')
    idx = np.where(mag <= magCut)[0]

    py.clf()
    py.hist(vx[idx])
    py.hist(vy[idx])
    
    print 'Number of Stars: %d' % len(idx)
    print 'X Mean Velocity: %5.2f' % (vx[idx].mean())
    print 'X Error on Mean: %5.2f' % (vx[idx].std() / math.sqrt(len(vx)))
    print 'Y Mean Velocity: %5.2f' % (vy[idx].mean())
    print 'Y Error on Mean: %5.2f' % (vy[idx].std() / math.sqrt(len(vx)))


    # Plot distribution of velocity errors
    py.clf()
    binsIn = np.arange(0, max([max(vxerr), max(vyerr)]), 0.1)
    (bins,data)=histNofill.hist(binsIn,vxerr)
    py.plot(bins,data,'r',linewidth=2)
    (bins,data)=histNofill.hist(binsIn,vyerr)
    py.plot(bins,data,'b',linewidth=2)
    py.axis([0,10,0,600])
    py.xlabel('Velocity Errors (mas/yr)')
    py.ylabel('N')
    py.savefig('plots/histVelErr.png')
コード例 #2
0
def velocityAverage(alignRoot, polyRoot, magCut=15):
    """
    Calculate the mean (and error on mean) of the velocities from
    a align/polyfit.

    Input Parameters:
    -- the root name of the align output (e.g. 'align/align_d_rms_t'
    -- the root name of the polyfit output( e.g. 'polyfit_d/fit')
    """
    # This should be an absolute aligned data set.
    cc = objects.Constants()
    s = starset.StarSet(alignRoot)
    s.loadPolyfit(polyRoot, accel=0)

    vx = s.getArray('fitXv.v') * 10**3
    vy = s.getArray('fitYv.v') * 10**3
    vxerr = s.getArray('fitXv.verr') * 10**3
    vyerr = s.getArray('fitYv.verr') * 10**3

    mag = s.getArray('mag')
    idx = np.where(mag <= magCut)[0]

    py.clf()
    py.hist(vx[idx])
    py.hist(vy[idx])

    print 'Number of Stars: %d' % len(idx)
    print 'X Mean Velocity: %5.2f' % (vx[idx].mean())
    print 'X Error on Mean: %5.2f' % (vx[idx].std() / math.sqrt(len(vx)))
    print 'Y Mean Velocity: %5.2f' % (vy[idx].mean())
    print 'Y Error on Mean: %5.2f' % (vy[idx].std() / math.sqrt(len(vx)))

    # Plot distribution of velocity errors
    py.clf()
    binsIn = np.arange(0, max([max(vxerr), max(vyerr)]), 0.1)
    (bins, data) = histNofill.hist(binsIn, vxerr)
    py.plot(bins, data, 'r', linewidth=2)
    (bins, data) = histNofill.hist(binsIn, vyerr)
    py.plot(bins, data, 'b', linewidth=2)
    py.axis([0, 10, 0, 600])
    py.xlabel('Velocity Errors (mas/yr)')
    py.ylabel('N')
    py.savefig('plots/histVelErr.png')
コード例 #3
0
ファイル: sim.py プロジェクト: AtomyChan/JLU-python-code
def compareParams(column, file1=root+'08_02_16/MC/mc_zero.log.a',
                  file2=root+'08_02_16/MCast/mc_zero.log'):
    """
    Compare parameters via their 1D PDFs. 

    Input Parameters:
    column - a string indicating what variable from the efit MC should
    be plotted. Here are the options:

    'r0' (column #1 of efit MC file)
    'x0' (column #2 of efit MC file)
    'y0' (column #3 of efit MC file)
    'a'  (column #4 of efit MC file)
    'p'  (column #5 of efit MC file)
    'e'  (column #6 of efit MC file)
    'm'  (combine columns #1, #4, #5 of efit MC file)
    'periapse' (Periapse distance)
    """
    cc = objects.Constants()

    # Read in the efit monte carlo output file. Reading in this way
    # organizes stuff by column (e.g. table[0] = first column
    table = asciidata.open(file1)

    # Make things into arrays of floats, etc.
    r01 = table[0].tonumpy()  # in pc
    x01 = table[1].tonumpy()  # in pix (working on abs, scale = 1)
    y01 = table[2].tonumpy()  # in pix (working on abs, scale = 1)
    a1 = table[3].tonumpy()   # in mas
    p1 = table[4].tonumpy()   # in yrs
    e1 = table[5].tonumpy()

    # convert semi-major axis and period into mass
    m1 = (a1 * r01 / 1000.0)**3 / p1**2

    # calculate periapse distance (in pc)
    pdist1 = a1 * r01 * (1.0 - e1) / (cc.au_in_pc * 1000.0)

    # Read in the efit monte carlo output file. Reading in this way
    # organizes stuff by column (e.g. table[0] = first column
    table = asciidata.open(file2)

    # Make things into arrays of floats, etc.
    r02 = table[0].tonumpy()  # in pc
    x02 = table[1].tonumpy()  # in pix
    y02 = table[2].tonumpy()  # in pix
    a2 = table[3].tonumpy()   # in mas
    p2 = table[4].tonumpy()   # in yrs
    e2 = table[5].tonumpy()

    # convert semi-major axis and period into mass
    m2 = (a2 * r02 / 1000.0)**3 / p2**2

    # calculate periapse distance (in pc)
    pdist2 = a2 * r02 * (1.0 - e2) / (cc.au_in_pc * 1000.0)

    if (column == 'r0'): 
        var1 = r01
        var2 = r02
        axisLabel = 'Ro (pc)'
    if (column == 'x0'): 
        var1 = x01 * 1000.0
        var2 = x02 * 1000.0
        axisLabel = 'Sgr A* X Position (mas)'
    if (column == 'y0'): 
        var1 = y01 * 1000.0
        var2 = y02 * 1000.0
        axisLabel = 'Sgr A* X Position (mas)'
    if (column == 'p'): 
        var1 = p1
        var2 = p2
        axisLabel = 'Period (yr)' 
    if (column == 'a'): 
        var1 = a1
        var2 = a2
        axisLabel = 'Semi-Major Axis (mas)' 
    if (column == 'e'): 
        var1 = e1
        var2 = e2
        axisLabel = 'Eccentricity' 
    if (column == 'm'): 
        var1 = m1
        var2 = m2
        axisLabel = 'Mass (Msun)' 
    if (column == 'periapse'): 
        var1 = pdist1
        var2 = pdist2
        axisLabel = 'Periapse Distance (pc)' 
    
    minVar = concatenate((var1, var2)).min()
    maxVar = concatenate((var1, var2)).max()
    binsIn = arange(minVar, maxVar, (maxVar - minVar) / 10.0)

    (bins1, data1) = histNofill.hist(binsIn, var1)
    (bins2, data2) = histNofill.hist(binsIn, var2)

    foo = stats.stats.ks_2samp(var1, var2)
    print 'KS Test: Distance Statistic (0 is same) = %5.2f' % (foo[0])

    clf()
    hist1 = plot(bins1, data1/data1.sum(), color='red', linewidth=3)
    hist2 = plot(bins2, data2/data2.sum(), color='blue', linewidth=3)
    legend((hist1, hist2), (file1, file2))
    xlabel(axisLabel)
    ylabel('Probability')

    savefig('compareParams_' + column + '.png')
    savefig('compareParams_' + column + '.eps')
コード例 #4
0
ファイル: pairwise.py プロジェクト: Nijaid/JLU-python-code
def compareDAR(pwDARfixOn, pwDARfixOff, outdir='./'):
    """
    Pass in either the filename to a pickle file containing a
    Pairwise object or pass in the Pairwise object itself for both
    a DAR corrected and uncorrected data set. This way we can plot up
    both and compare them for all the stars.
    """
    # Rename variables for brevity
    if (type(pwDARfixOn) == type('')):
        pw1 = pickle.load(open(pwDARfixOn))
    else:
        pw1 = pwDARfixOn

    if (type(pwDARfixOff) == type('')):
        pw2 = pickle.load(open(pwDARfixOff))
    else:
        pw2 = pwDARfixOff

    # We can only compare stars that have matches in both.
    # Also restrict to just those stars with K<14.
    idx1 = []
    idx2 = []
    for j1 in range(pw1.starCnt):
        try:
            j2 = pw2.names.index(pw1.names[j1])

            if (pw1.mag[j1] > 14):
                idx1.append(j1)
                idx2.append(j2)
        except ValueError:
            # Skip
            continue
    
    # Calculate the average position of each star relative
    # to the reference star.
    starCnt = len(idx1)
    avgx1 = np.zeros(starCnt, dtype=float)
    avgy1 = np.zeros(starCnt, dtype=float)
    rmsx1 = np.zeros(starCnt, dtype=float)
    rmsy1 = np.zeros(starCnt, dtype=float)
    rmsz1 = np.zeros(starCnt, dtype=float)
    rmsh1 = np.zeros(starCnt, dtype=float)
    rmsr1 = np.zeros(starCnt, dtype=float)
    rmst1 = np.zeros(starCnt, dtype=float)

    avgx2 = np.zeros(starCnt, dtype=float)
    avgy2 = np.zeros(starCnt, dtype=float)
    rmsx2 = np.zeros(starCnt, dtype=float)
    rmsy2 = np.zeros(starCnt, dtype=float)
    rmsz2 = np.zeros(starCnt, dtype=float)
    rmsh2 = np.zeros(starCnt, dtype=float)
    rmsr2 = np.zeros(starCnt, dtype=float)
    rmst2 = np.zeros(starCnt, dtype=float)

    for ii in range(starCnt):
        j1 = idx1[ii]
        j2 = idx2[ii]

        # For this star, find the epochs with data.
        e1 = np.where(pw1.hasData[j1] == 1)[0]
        e2 = np.where(pw2.hasData[j2] == 1)[0]

        avgx1[ii] = pw1.posx[j1, e1].mean()
        avgy1[ii] = pw1.posy[j1, e1].mean()
        rmsx1[ii] = np.sqrt((pw1.diffx[j1, e1]**2).sum() / (starCnt - 1))
        rmsy1[ii] = np.sqrt((pw1.diffy[j1, e1]**2).sum() / (starCnt - 1))
        rmsh1[ii] = np.sqrt((pw1.diffh[j1, e1]**2).sum() / (starCnt - 1))
        rmsz1[ii] = np.sqrt((pw1.diffz[j1, e1]**2).sum() / (starCnt - 1))
        rmsr1[ii] = np.sqrt((pw1.diffr[j1, e1]**2).sum() / (starCnt - 1))
        rmst1[ii] = np.sqrt((pw1.difft[j1, e1]**2).sum() / (starCnt - 1))

        avgx2[ii] = pw2.posx[j2, e2].mean()
        avgy2[ii] = pw2.posy[j2, e2].mean()
        rmsx2[ii] = np.sqrt((pw2.diffx[j2, e2]**2).sum() / (starCnt - 1))
        rmsy2[ii] = np.sqrt((pw2.diffy[j2, e2]**2).sum() / (starCnt - 1))
        rmsh2[ii] = np.sqrt((pw2.diffh[j2, e2]**2).sum() / (starCnt - 1))
        rmsz2[ii] = np.sqrt((pw2.diffz[j2, e2]**2).sum() / (starCnt - 1))
        rmsr2[ii] = np.sqrt((pw2.diffr[j2, e2]**2).sum() / (starCnt - 1))
        rmst2[ii] = np.sqrt((pw2.difft[j2, e2]**2).sum() / (starCnt - 1))

    # Now calculate average separation
    avgr1 = np.hypot(avgx1, avgy1)
    avgr2 = np.hypot(avgx2, avgy2)

    py.clf()
    py.plot(avgr1, (avgr1-avgr2)*10**3, 'k.')
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], 'k--')
    py.xlabel('DAR Corrected (arcsec)')
    py.ylabel('DAR Corrected - Uncorrected (mas)')
    py.title('Average Distance from S1-5')
    py.axis([0, 7, -0.5, 2.5])
    py.savefig(outdir + 'plots/compare_dar_sep.eps')
    py.savefig(outdir + 'plots/compare_dar_sep.png')

    # Same thing but convert back to pixels.
    py.clf()
    py.plot(avgr1 / 0.00996, (avgr1-avgr2)/0.00996, 'k.')
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], 'k--')
    py.xlabel('DAR Corrected (pixels)')
    py.ylabel('DAR Corrected - Uncorrected (pixels)')
    py.title('Average Distance from S1-5')
    py.axis([0, 700, -0.05, 0.3])
    py.savefig(outdir + 'plots/compare_dar_sep_pix.eps')
    py.savefig(outdir + 'plots/compare_dar_sep_pix.png')

    py.clf()
    py.plot(rmsx2, rmsx2-rmsx1, 'r,')
    py.plot(rmsy2, rmsy2-rmsy1, 'b,')
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], 'k--')
    py.xlabel('DAR Uncorrected (mas)')
    py.ylabel('DAR Uncorrected - Corrected (mas)')
    py.title('RMS Error in Distance from S1-5')
    leg = py.legend(('NIRC2 X', 'NIRC2 Y'), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color('r')
    txts[1].set_color('b')
    py.ylim(-0.6, 0.6)
    py.savefig(outdir + 'plots/compare_dar_rmsxy.eps')
    py.savefig(outdir + 'plots/compare_dar_rmsxy.png')

    py.clf()
    py.plot(rmsh2, rmsh2-rmsh1, 'r,')
    py.plot(rmsz2, rmsz2-rmsz1, 'b,')
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], 'k--')    
    py.xlabel('DAR Uncorrected (mas)')
    py.ylabel('DAR Uncorrected - Corrected (mas)')
    py.title('RMS Error in Distance from S1-5')
    leg = py.legend(('Horizon', 'Zenith'), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color('r')
    txts[1].set_color('b')
    py.ylim(-0.6, 0.6)
    py.savefig(outdir + 'plots/compare_dar_rmshz.eps')
    py.savefig(outdir + 'plots/compare_dar_rmshz.png')

    py.clf()
    py.plot(avgr1, (rmsh2 - rmsh1)/rmsh2, 'r.')
    py.plot(avgr1, (rmsz2 - rmsz1)/rmsz2, 'b.')
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], 'k--')
    py.xlabel('Distance from S1-5 (arcsec)')
    py.ylabel('Fractional Reduction in RMS Error')
    py.title('RMS Error in Distance from S1-5')
    leg = py.legend(('Horizon', 'Zenith'), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color('r')
    txts[1].set_color('b')
    py.quiver([6.1, 6.1], [0, 0], [0, 0], [0.09, -0.09], scale=1.0)
    py.text(6.1, 0.1, 'Decreased\nErrors', fontsize=10,
            horizontalalignment='center', verticalalignment='bottom')
    py.text(6.1, -0.1, 'Increased\nErrors', fontsize=10,
            horizontalalignment='center', verticalalignment='top')
    py.ylim(-0.5, 0.5)
    py.savefig(outdir + 'plots/compare_dar_rmshz_sep.eps')
    py.savefig(outdir + 'plots/compare_dar_rmshz_sep.png')

    py.clf()
    py.plot(rmsh2, (rmsh2 - rmsh1)/rmsh2, 'r.')
    py.plot(rmsz2, (rmsz2 - rmsz1)/rmsz2, 'b.')
    py.xlabel('RMS Error in Distance (mas)')
    py.ylabel('Fractional Reduction in RMS Error')
    leg = py.legend(('Horizon', 'Zenith'), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color('r')
    txts[1].set_color('b')
    py.quiver([4.1, 4.1], [0, 0], [0, 0], [0.09, -0.09], scale=1.0)
    py.text(4.1, 0.1, 'Decreased\nErrors', fontsize=10,
            horizontalalignment='center', verticalalignment='bottom')
    py.text(4.1, -0.1, 'Increased\nErrors', fontsize=10,
            horizontalalignment='center', verticalalignment='top')
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], 'k--')
    py.ylim(-0.5, 0.5)
    py.savefig(outdir + 'plots/compare_dar_rmshz_rms.eps')
    py.savefig(outdir + 'plots/compare_dar_rmshz_rms.png')

    py.clf()
    py.plot(rmsr2, rmsr2-rmsr1, 'r,')
    py.plot(rmst2, rmst2-rmst1, 'b,')
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], 'k--')
    py.xlabel('DAR Uncorrected (mas)')
    py.ylabel('DAR Uncorrected - Corrected (mas)')
    py.title('RMS Error in Distance from S1-5')
    leg = py.legend(('Radial', 'Tangential'), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color('r')
    txts[1].set_color('b')
    py.ylim(-0.6, 0.6)
    py.savefig(outdir + 'plots/compare_dar_rmsrt.eps')
    py.savefig(outdir + 'plots/compare_dar_rmsrt.png')

    # Also plot histograms for each of the RMS values.
    binsIn = np.arange(-0.5, 0.5, 0.05)

    (binx, datx) = histNofill.hist(binsIn, rmsx2-rmsx1)
    (biny, daty) = histNofill.hist(binsIn, rmsy2-rmsy1)
    datx /= len(rmsx2)
    daty /= len(rmsx2)
    py.clf()
    py.plot(binx, datx, 'r-')
    py.plot(biny, daty, 'b-')
    py.quiver([-0.1, 0.1], [0.2, 0.2], [-0.2, 0.2], [0, 0], scale=1.1)
    py.text(0.2, 0.21, 'Decreased\nErrors', fontsize=10,
            horizontalalignment='left', verticalalignment='bottom')
    py.text(-0.2, 0.21, 'Increased\nErrors', fontsize=10,
            horizontalalignment='right', verticalalignment='bottom')
    rng = py.axis()
    py.plot([0, 0], [rng[2], rng[3]], 'k--')
    py.ylabel('Fraction of Stars')
    py.xlabel('DAR Uncorrected - Corrected (mas)')
    py.title('RMS Error in Distance from S1-5')
    leg = py.legend(('NIRC2 X', 'NIRC2 Y'), markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color('r')
    txts[1].set_color('b')
    py.savefig(outdir + 'plots/compare_dar_rmsxy_hist.eps')
    py.savefig(outdir + 'plots/compare_dar_rmsxy_hist.png')

    (binh, dath) = histNofill.hist(binsIn, rmsh2-rmsh1)
    (binz, datz) = histNofill.hist(binsIn, rmsz2-rmsz1)
    dath /= len(rmsh2)
    datz /= len(rmsz2)
    py.clf()
    py.plot(binh, dath, 'r-')
    py.plot(binz, datz, 'b-')
    py.quiver([-0.1, 0.1], [0.2, 0.2], [-0.2, 0.2], [0, 0], scale=1.1)
    py.text(0.2, 0.21, 'Decreased\nErrors', fontsize=10,
            horizontalalignment='left', verticalalignment='bottom')
    py.text(-0.2, 0.21, 'Increased\nErrors', fontsize=10,
            horizontalalignment='right', verticalalignment='bottom')
    rng = py.axis()
    py.plot([0, 0], [rng[2], rng[3]], 'k--')
    py.ylabel('Number of Stars')
    py.xlabel('DAR Uncorrected - Corrected (mas)')
    py.title('RMS Error in Distance from S1-5')
    leg = py.legend(('Horizon', 'Zenith'), markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color('r')
    txts[1].set_color('b')
    py.savefig(outdir + 'plots/compare_dar_rmshz_hist.eps')
    py.savefig(outdir + 'plots/compare_dar_rmshz_hist.png')

    (binr, datr) = histNofill.hist(binsIn, rmsr2-rmsr1)
    (bint, datt) = histNofill.hist(binsIn, rmst2-rmst1)
    datr /= len(rmsr2)
    datt /= len(rmst2)
    py.clf()
    py.plot(binr, datr, 'r-')
    py.plot(bint, datt, 'b-')
    py.quiver([-0.1, 0.1], [0.2, 0.2], [-0.2, 0.2], [0, 0], scale=1.1)
    py.text(0.2, 0.21, 'Decreased\nErrors', fontsize=10,
            horizontalalignment='left', verticalalignment='bottom')
    py.text(-0.2, 0.21, 'Increased\nErrors', fontsize=10,
            horizontalalignment='right', verticalalignment='bottom')
    rng = py.axis()
    py.plot([0, 0], [rng[2], rng[3]], 'k--')
    py.ylabel('Number of Stars')
    py.xlabel('DAR Uncorrected - Corrected (mas)')
    py.title('RMS Error in Distance from S1-5')
    leg = py.legend(('Radial', 'Tangential'), markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color('r')
    txts[1].set_color('b')
    py.savefig(outdir + 'plots/compare_dar_rmsrt_hist.eps')
    py.savefig(outdir + 'plots/compare_dar_rmsrt_hist.png')
コード例 #5
0
ファイル: pairwise.py プロジェクト: Nijaid/JLU-python-code
def histZHrms(pairwise, plot=True, outdir='./'):
    """
    Make a histogram of the RMS error in the zenith and horizon components
    of all star's separation vectors.
    """
    if (type(pairwise) == type('')):
        pw = pickle.load(open(pariwise))
    else:
        pw = pairwise

    rmsh = np.zeros(pw.starCnt, dtype=float)
    rmsz = np.zeros(pw.starCnt, dtype=float)
    rmsx = np.zeros(pw.starCnt, dtype=float)
    rmsy = np.zeros(pw.starCnt, dtype=float)
    rmsx2 = np.zeros(pw.starCnt, dtype=float)
    rmsy2 = np.zeros(pw.starCnt, dtype=float)

    for ii in range(pw.starCnt):
        ee = np.where(pw.hasData[ii] == 1)[0]

        rmsh[ii] = math.sqrt( (pw.diffh[ii,ee]**2).sum() / (len(ee) - 1.0) )
        rmsz[ii] = math.sqrt( (pw.diffz[ii,ee]**2).sum() / (len(ee) - 1.0) )
        rmsx[ii] = math.sqrt( (pw.diffx[ii,ee]**2).sum() / (len(ee) - 1.0) )
        rmsy[ii] = math.sqrt( (pw.diffy[ii,ee]**2).sum() / (len(ee) - 1.0) )
        rmsx2[ii] = pw.posx[ii,ee].std() * 10**3
        rmsy2[ii] = pw.posy[ii,ee].std() * 10**3

    # We only care about those stars that are K<14 and within 4".
    # This helps us avoid issues in the corners and with faint stars.
    idx = np.where((pw.mag < 14) & (pw.r < 4))[0]
    rmsh = rmsh[idx]
    rmsz = rmsz[idx]
    
    binsIn = np.arange(0, 5, 0.2)
    (binsh, datah) = histNofill.hist(binsIn, rmsh)
    (binsz, dataz) = histNofill.hist(binsIn, rmsz)
    (binsx, datax) = histNofill.hist(binsIn, rmsx)
    (binsy, datay) = histNofill.hist(binsIn, rmsy)
    (binsx2, datax2) = histNofill.hist(binsIn, rmsx2)
    (binsy2, datay2) = histNofill.hist(binsIn, rmsy2)

    peakh = binsh[datah.argmax()]
    peakz = binsz[dataz.argmax()]
    peakx = binsx[datax.argmax()]
    peaky = binsy[datay.argmax()]
    peakx2 = binsx2[datax2.argmax()]
    peaky2 = binsy2[datay2.argmax()]

    print 'RMS error in separation vector (mas): '
    print 'Horizon: mean = %4.2f  median = %4.2f  peak = %4.2f' % \
          (rmsh.mean(), np.median(rmsh), peakh)
    print 'Zenith:  mean = %4.2f  median = %4.2f  peak = %4.2f' % \
          (rmsz.mean(), np.median(rmsz), peakz)
    print 'x-axis:  mean = %4.2f  median = %4.2f  peak = %4.2f' % \
          (rmsx.mean(), np.median(rmsx), peakx)
    print 'y-axis:  mean = %4.2f  median = %4.2f  peak = %4.2f' % \
          (rmsy.mean(), np.median(rmsy), peaky)
    print 'x-axis2: mean = %4.2f  median = %4.2f  peak = %4.2f' % \
          (rmsx2.mean(), np.median(rmsx2), peakx2)
    print 'y-axis2: mean = %4.2f  median = %4.2f  peak = %4.2f' % \
          (rmsy2.mean(), np.median(rmsy2), peaky2)
    
    if (plot == True):
        py.clf()
        py.plot(binsh, datah, 'r-')
        py.plot(binsz, dataz, 'b-')
        py.xlabel('RMS Error In Separation (mas)')
        py.ylabel('Number of Stars')
        
        py.legend(('Horizon Median = %4.2f mas' % np.median(rmsh),
                   'Zenith Median  = %4.2f mas' % np.median(rmsz)))
    
        py.savefig(outdir + '/plots/hist_zh_rms.eps')
        py.savefig(outdir + '/plots/hist_zh_rms.png')

    return (np.median(rmsh), np.median(rmsz))
コード例 #6
0
ファイル: pairwise.py プロジェクト: AtomyChan/JLU-python-code
def histZHrms(pairwise, plot=True, outdir="./"):
    """
    Make a histogram of the RMS error in the zenith and horizon components
    of all star's separation vectors.
    """
    if type(pairwise) == type(""):
        pw = pickle.load(open(pariwise))
    else:
        pw = pairwise

    rmsh = np.zeros(pw.starCnt, dtype=float)
    rmsz = np.zeros(pw.starCnt, dtype=float)
    rmsx = np.zeros(pw.starCnt, dtype=float)
    rmsy = np.zeros(pw.starCnt, dtype=float)
    rmsx2 = np.zeros(pw.starCnt, dtype=float)
    rmsy2 = np.zeros(pw.starCnt, dtype=float)

    for ii in range(pw.starCnt):
        ee = np.where(pw.hasData[ii] == 1)[0]

        rmsh[ii] = math.sqrt((pw.diffh[ii, ee] ** 2).sum() / (len(ee) - 1.0))
        rmsz[ii] = math.sqrt((pw.diffz[ii, ee] ** 2).sum() / (len(ee) - 1.0))
        rmsx[ii] = math.sqrt((pw.diffx[ii, ee] ** 2).sum() / (len(ee) - 1.0))
        rmsy[ii] = math.sqrt((pw.diffy[ii, ee] ** 2).sum() / (len(ee) - 1.0))
        rmsx2[ii] = pw.posx[ii, ee].std() * 10 ** 3
        rmsy2[ii] = pw.posy[ii, ee].std() * 10 ** 3

    # We only care about those stars that are K<14 and within 4".
    # This helps us avoid issues in the corners and with faint stars.
    idx = np.where((pw.mag < 14) & (pw.r < 4))[0]
    rmsh = rmsh[idx]
    rmsz = rmsz[idx]

    binsIn = np.arange(0, 5, 0.2)
    (binsh, datah) = histNofill.hist(binsIn, rmsh)
    (binsz, dataz) = histNofill.hist(binsIn, rmsz)
    (binsx, datax) = histNofill.hist(binsIn, rmsx)
    (binsy, datay) = histNofill.hist(binsIn, rmsy)
    (binsx2, datax2) = histNofill.hist(binsIn, rmsx2)
    (binsy2, datay2) = histNofill.hist(binsIn, rmsy2)

    peakh = binsh[datah.argmax()]
    peakz = binsz[dataz.argmax()]
    peakx = binsx[datax.argmax()]
    peaky = binsy[datay.argmax()]
    peakx2 = binsx2[datax2.argmax()]
    peaky2 = binsy2[datay2.argmax()]

    print "RMS error in separation vector (mas): "
    print "Horizon: mean = %4.2f  median = %4.2f  peak = %4.2f" % (rmsh.mean(), np.median(rmsh), peakh)
    print "Zenith:  mean = %4.2f  median = %4.2f  peak = %4.2f" % (rmsz.mean(), np.median(rmsz), peakz)
    print "x-axis:  mean = %4.2f  median = %4.2f  peak = %4.2f" % (rmsx.mean(), np.median(rmsx), peakx)
    print "y-axis:  mean = %4.2f  median = %4.2f  peak = %4.2f" % (rmsy.mean(), np.median(rmsy), peaky)
    print "x-axis2: mean = %4.2f  median = %4.2f  peak = %4.2f" % (rmsx2.mean(), np.median(rmsx2), peakx2)
    print "y-axis2: mean = %4.2f  median = %4.2f  peak = %4.2f" % (rmsy2.mean(), np.median(rmsy2), peaky2)

    if plot == True:
        py.clf()
        py.plot(binsh, datah, "r-")
        py.plot(binsz, dataz, "b-")
        py.xlabel("RMS Error In Separation (mas)")
        py.ylabel("Number of Stars")

        py.legend(("Horizon Median = %4.2f mas" % np.median(rmsh), "Zenith Median  = %4.2f mas" % np.median(rmsz)))

        py.savefig(outdir + "/plots/hist_zh_rms.eps")
        py.savefig(outdir + "/plots/hist_zh_rms.png")

    return (np.median(rmsh), np.median(rmsz))
コード例 #7
0
ファイル: pairwise.py プロジェクト: AtomyChan/JLU-python-code
def compareDAR(pwDARfixOn, pwDARfixOff, outdir="./"):
    """
    Pass in either the filename to a pickle file containing a
    Pairwise object or pass in the Pairwise object itself for both
    a DAR corrected and uncorrected data set. This way we can plot up
    both and compare them for all the stars.
    """
    # Rename variables for brevity
    if type(pwDARfixOn) == type(""):
        pw1 = pickle.load(open(pwDARfixOn))
    else:
        pw1 = pwDARfixOn

    if type(pwDARfixOff) == type(""):
        pw2 = pickle.load(open(pwDARfixOff))
    else:
        pw2 = pwDARfixOff

    # We can only compare stars that have matches in both.
    # Also restrict to just those stars with K<14.
    idx1 = []
    idx2 = []
    for j1 in range(pw1.starCnt):
        try:
            j2 = pw2.names.index(pw1.names[j1])

            if pw1.mag[j1] > 14:
                idx1.append(j1)
                idx2.append(j2)
        except ValueError:
            # Skip
            continue

    # Calculate the average position of each star relative
    # to the reference star.
    starCnt = len(idx1)
    avgx1 = np.zeros(starCnt, dtype=float)
    avgy1 = np.zeros(starCnt, dtype=float)
    rmsx1 = np.zeros(starCnt, dtype=float)
    rmsy1 = np.zeros(starCnt, dtype=float)
    rmsz1 = np.zeros(starCnt, dtype=float)
    rmsh1 = np.zeros(starCnt, dtype=float)
    rmsr1 = np.zeros(starCnt, dtype=float)
    rmst1 = np.zeros(starCnt, dtype=float)

    avgx2 = np.zeros(starCnt, dtype=float)
    avgy2 = np.zeros(starCnt, dtype=float)
    rmsx2 = np.zeros(starCnt, dtype=float)
    rmsy2 = np.zeros(starCnt, dtype=float)
    rmsz2 = np.zeros(starCnt, dtype=float)
    rmsh2 = np.zeros(starCnt, dtype=float)
    rmsr2 = np.zeros(starCnt, dtype=float)
    rmst2 = np.zeros(starCnt, dtype=float)

    for ii in range(starCnt):
        j1 = idx1[ii]
        j2 = idx2[ii]

        # For this star, find the epochs with data.
        e1 = np.where(pw1.hasData[j1] == 1)[0]
        e2 = np.where(pw2.hasData[j2] == 1)[0]

        avgx1[ii] = pw1.posx[j1, e1].mean()
        avgy1[ii] = pw1.posy[j1, e1].mean()
        rmsx1[ii] = np.sqrt((pw1.diffx[j1, e1] ** 2).sum() / (starCnt - 1))
        rmsy1[ii] = np.sqrt((pw1.diffy[j1, e1] ** 2).sum() / (starCnt - 1))
        rmsh1[ii] = np.sqrt((pw1.diffh[j1, e1] ** 2).sum() / (starCnt - 1))
        rmsz1[ii] = np.sqrt((pw1.diffz[j1, e1] ** 2).sum() / (starCnt - 1))
        rmsr1[ii] = np.sqrt((pw1.diffr[j1, e1] ** 2).sum() / (starCnt - 1))
        rmst1[ii] = np.sqrt((pw1.difft[j1, e1] ** 2).sum() / (starCnt - 1))

        avgx2[ii] = pw2.posx[j2, e2].mean()
        avgy2[ii] = pw2.posy[j2, e2].mean()
        rmsx2[ii] = np.sqrt((pw2.diffx[j2, e2] ** 2).sum() / (starCnt - 1))
        rmsy2[ii] = np.sqrt((pw2.diffy[j2, e2] ** 2).sum() / (starCnt - 1))
        rmsh2[ii] = np.sqrt((pw2.diffh[j2, e2] ** 2).sum() / (starCnt - 1))
        rmsz2[ii] = np.sqrt((pw2.diffz[j2, e2] ** 2).sum() / (starCnt - 1))
        rmsr2[ii] = np.sqrt((pw2.diffr[j2, e2] ** 2).sum() / (starCnt - 1))
        rmst2[ii] = np.sqrt((pw2.difft[j2, e2] ** 2).sum() / (starCnt - 1))

    # Now calculate average separation
    avgr1 = np.hypot(avgx1, avgy1)
    avgr2 = np.hypot(avgx2, avgy2)

    py.clf()
    py.plot(avgr1, (avgr1 - avgr2) * 10 ** 3, "k.")
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], "k--")
    py.xlabel("DAR Corrected (arcsec)")
    py.ylabel("DAR Corrected - Uncorrected (mas)")
    py.title("Average Distance from S1-5")
    py.axis([0, 7, -0.5, 2.5])
    py.savefig(outdir + "plots/compare_dar_sep.eps")
    py.savefig(outdir + "plots/compare_dar_sep.png")

    # Same thing but convert back to pixels.
    py.clf()
    py.plot(avgr1 / 0.00996, (avgr1 - avgr2) / 0.00996, "k.")
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], "k--")
    py.xlabel("DAR Corrected (pixels)")
    py.ylabel("DAR Corrected - Uncorrected (pixels)")
    py.title("Average Distance from S1-5")
    py.axis([0, 700, -0.05, 0.3])
    py.savefig(outdir + "plots/compare_dar_sep_pix.eps")
    py.savefig(outdir + "plots/compare_dar_sep_pix.png")

    py.clf()
    py.plot(rmsx2, rmsx2 - rmsx1, "r,")
    py.plot(rmsy2, rmsy2 - rmsy1, "b,")
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], "k--")
    py.xlabel("DAR Uncorrected (mas)")
    py.ylabel("DAR Uncorrected - Corrected (mas)")
    py.title("RMS Error in Distance from S1-5")
    leg = py.legend(("NIRC2 X", "NIRC2 Y"), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color("r")
    txts[1].set_color("b")
    py.ylim(-0.6, 0.6)
    py.savefig(outdir + "plots/compare_dar_rmsxy.eps")
    py.savefig(outdir + "plots/compare_dar_rmsxy.png")

    py.clf()
    py.plot(rmsh2, rmsh2 - rmsh1, "r,")
    py.plot(rmsz2, rmsz2 - rmsz1, "b,")
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], "k--")
    py.xlabel("DAR Uncorrected (mas)")
    py.ylabel("DAR Uncorrected - Corrected (mas)")
    py.title("RMS Error in Distance from S1-5")
    leg = py.legend(("Horizon", "Zenith"), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color("r")
    txts[1].set_color("b")
    py.ylim(-0.6, 0.6)
    py.savefig(outdir + "plots/compare_dar_rmshz.eps")
    py.savefig(outdir + "plots/compare_dar_rmshz.png")

    py.clf()
    py.plot(avgr1, (rmsh2 - rmsh1) / rmsh2, "r.")
    py.plot(avgr1, (rmsz2 - rmsz1) / rmsz2, "b.")
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], "k--")
    py.xlabel("Distance from S1-5 (arcsec)")
    py.ylabel("Fractional Reduction in RMS Error")
    py.title("RMS Error in Distance from S1-5")
    leg = py.legend(("Horizon", "Zenith"), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color("r")
    txts[1].set_color("b")
    py.quiver([6.1, 6.1], [0, 0], [0, 0], [0.09, -0.09], scale=1.0)
    py.text(6.1, 0.1, "Decreased\nErrors", fontsize=10, horizontalalignment="center", verticalalignment="bottom")
    py.text(6.1, -0.1, "Increased\nErrors", fontsize=10, horizontalalignment="center", verticalalignment="top")
    py.ylim(-0.5, 0.5)
    py.savefig(outdir + "plots/compare_dar_rmshz_sep.eps")
    py.savefig(outdir + "plots/compare_dar_rmshz_sep.png")

    py.clf()
    py.plot(rmsh2, (rmsh2 - rmsh1) / rmsh2, "r.")
    py.plot(rmsz2, (rmsz2 - rmsz1) / rmsz2, "b.")
    py.xlabel("RMS Error in Distance (mas)")
    py.ylabel("Fractional Reduction in RMS Error")
    leg = py.legend(("Horizon", "Zenith"), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color("r")
    txts[1].set_color("b")
    py.quiver([4.1, 4.1], [0, 0], [0, 0], [0.09, -0.09], scale=1.0)
    py.text(4.1, 0.1, "Decreased\nErrors", fontsize=10, horizontalalignment="center", verticalalignment="bottom")
    py.text(4.1, -0.1, "Increased\nErrors", fontsize=10, horizontalalignment="center", verticalalignment="top")
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], "k--")
    py.ylim(-0.5, 0.5)
    py.savefig(outdir + "plots/compare_dar_rmshz_rms.eps")
    py.savefig(outdir + "plots/compare_dar_rmshz_rms.png")

    py.clf()
    py.plot(rmsr2, rmsr2 - rmsr1, "r,")
    py.plot(rmst2, rmst2 - rmst1, "b,")
    rng = py.axis()
    py.plot([rng[0], rng[1]], [0, 0], "k--")
    py.xlabel("DAR Uncorrected (mas)")
    py.ylabel("DAR Uncorrected - Corrected (mas)")
    py.title("RMS Error in Distance from S1-5")
    leg = py.legend(("Radial", "Tangential"), numpoints=1, markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color("r")
    txts[1].set_color("b")
    py.ylim(-0.6, 0.6)
    py.savefig(outdir + "plots/compare_dar_rmsrt.eps")
    py.savefig(outdir + "plots/compare_dar_rmsrt.png")

    # Also plot histograms for each of the RMS values.
    binsIn = np.arange(-0.5, 0.5, 0.05)

    (binx, datx) = histNofill.hist(binsIn, rmsx2 - rmsx1)
    (biny, daty) = histNofill.hist(binsIn, rmsy2 - rmsy1)
    datx /= len(rmsx2)
    daty /= len(rmsx2)
    py.clf()
    py.plot(binx, datx, "r-")
    py.plot(biny, daty, "b-")
    py.quiver([-0.1, 0.1], [0.2, 0.2], [-0.2, 0.2], [0, 0], scale=1.1)
    py.text(0.2, 0.21, "Decreased\nErrors", fontsize=10, horizontalalignment="left", verticalalignment="bottom")
    py.text(-0.2, 0.21, "Increased\nErrors", fontsize=10, horizontalalignment="right", verticalalignment="bottom")
    rng = py.axis()
    py.plot([0, 0], [rng[2], rng[3]], "k--")
    py.ylabel("Fraction of Stars")
    py.xlabel("DAR Uncorrected - Corrected (mas)")
    py.title("RMS Error in Distance from S1-5")
    leg = py.legend(("NIRC2 X", "NIRC2 Y"), markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color("r")
    txts[1].set_color("b")
    py.savefig(outdir + "plots/compare_dar_rmsxy_hist.eps")
    py.savefig(outdir + "plots/compare_dar_rmsxy_hist.png")

    (binh, dath) = histNofill.hist(binsIn, rmsh2 - rmsh1)
    (binz, datz) = histNofill.hist(binsIn, rmsz2 - rmsz1)
    dath /= len(rmsh2)
    datz /= len(rmsz2)
    py.clf()
    py.plot(binh, dath, "r-")
    py.plot(binz, datz, "b-")
    py.quiver([-0.1, 0.1], [0.2, 0.2], [-0.2, 0.2], [0, 0], scale=1.1)
    py.text(0.2, 0.21, "Decreased\nErrors", fontsize=10, horizontalalignment="left", verticalalignment="bottom")
    py.text(-0.2, 0.21, "Increased\nErrors", fontsize=10, horizontalalignment="right", verticalalignment="bottom")
    rng = py.axis()
    py.plot([0, 0], [rng[2], rng[3]], "k--")
    py.ylabel("Number of Stars")
    py.xlabel("DAR Uncorrected - Corrected (mas)")
    py.title("RMS Error in Distance from S1-5")
    leg = py.legend(("Horizon", "Zenith"), markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color("r")
    txts[1].set_color("b")
    py.savefig(outdir + "plots/compare_dar_rmshz_hist.eps")
    py.savefig(outdir + "plots/compare_dar_rmshz_hist.png")

    (binr, datr) = histNofill.hist(binsIn, rmsr2 - rmsr1)
    (bint, datt) = histNofill.hist(binsIn, rmst2 - rmst1)
    datr /= len(rmsr2)
    datt /= len(rmst2)
    py.clf()
    py.plot(binr, datr, "r-")
    py.plot(bint, datt, "b-")
    py.quiver([-0.1, 0.1], [0.2, 0.2], [-0.2, 0.2], [0, 0], scale=1.1)
    py.text(0.2, 0.21, "Decreased\nErrors", fontsize=10, horizontalalignment="left", verticalalignment="bottom")
    py.text(-0.2, 0.21, "Increased\nErrors", fontsize=10, horizontalalignment="right", verticalalignment="bottom")
    rng = py.axis()
    py.plot([0, 0], [rng[2], rng[3]], "k--")
    py.ylabel("Number of Stars")
    py.xlabel("DAR Uncorrected - Corrected (mas)")
    py.title("RMS Error in Distance from S1-5")
    leg = py.legend(("Radial", "Tangential"), markerscale=2)
    txts = leg.get_texts()
    txts[0].set_color("r")
    txts[1].set_color("b")
    py.savefig(outdir + "plots/compare_dar_rmsrt_hist.eps")
    py.savefig(outdir + "plots/compare_dar_rmsrt_hist.png")
コード例 #8
0
def compareParams(column,
                  file1=root + '08_02_16/MC/mc_zero.log.a',
                  file2=root + '08_02_16/MCast/mc_zero.log'):
    """
    Compare parameters via their 1D PDFs. 

    Input Parameters:
    column - a string indicating what variable from the efit MC should
    be plotted. Here are the options:

    'r0' (column #1 of efit MC file)
    'x0' (column #2 of efit MC file)
    'y0' (column #3 of efit MC file)
    'a'  (column #4 of efit MC file)
    'p'  (column #5 of efit MC file)
    'e'  (column #6 of efit MC file)
    'm'  (combine columns #1, #4, #5 of efit MC file)
    'periapse' (Periapse distance)
    """
    cc = objects.Constants()

    # Read in the efit monte carlo output file. Reading in this way
    # organizes stuff by column (e.g. table[0] = first column
    table = asciidata.open(file1)

    # Make things into arrays of floats, etc.
    r01 = table[0].tonumpy()  # in pc
    x01 = table[1].tonumpy()  # in pix (working on abs, scale = 1)
    y01 = table[2].tonumpy()  # in pix (working on abs, scale = 1)
    a1 = table[3].tonumpy()  # in mas
    p1 = table[4].tonumpy()  # in yrs
    e1 = table[5].tonumpy()

    # convert semi-major axis and period into mass
    m1 = (a1 * r01 / 1000.0)**3 / p1**2

    # calculate periapse distance (in pc)
    pdist1 = a1 * r01 * (1.0 - e1) / (cc.au_in_pc * 1000.0)

    # Read in the efit monte carlo output file. Reading in this way
    # organizes stuff by column (e.g. table[0] = first column
    table = asciidata.open(file2)

    # Make things into arrays of floats, etc.
    r02 = table[0].tonumpy()  # in pc
    x02 = table[1].tonumpy()  # in pix
    y02 = table[2].tonumpy()  # in pix
    a2 = table[3].tonumpy()  # in mas
    p2 = table[4].tonumpy()  # in yrs
    e2 = table[5].tonumpy()

    # convert semi-major axis and period into mass
    m2 = (a2 * r02 / 1000.0)**3 / p2**2

    # calculate periapse distance (in pc)
    pdist2 = a2 * r02 * (1.0 - e2) / (cc.au_in_pc * 1000.0)

    if (column == 'r0'):
        var1 = r01
        var2 = r02
        axisLabel = 'Ro (pc)'
    if (column == 'x0'):
        var1 = x01 * 1000.0
        var2 = x02 * 1000.0
        axisLabel = 'Sgr A* X Position (mas)'
    if (column == 'y0'):
        var1 = y01 * 1000.0
        var2 = y02 * 1000.0
        axisLabel = 'Sgr A* X Position (mas)'
    if (column == 'p'):
        var1 = p1
        var2 = p2
        axisLabel = 'Period (yr)'
    if (column == 'a'):
        var1 = a1
        var2 = a2
        axisLabel = 'Semi-Major Axis (mas)'
    if (column == 'e'):
        var1 = e1
        var2 = e2
        axisLabel = 'Eccentricity'
    if (column == 'm'):
        var1 = m1
        var2 = m2
        axisLabel = 'Mass (Msun)'
    if (column == 'periapse'):
        var1 = pdist1
        var2 = pdist2
        axisLabel = 'Periapse Distance (pc)'

    minVar = concatenate((var1, var2)).min()
    maxVar = concatenate((var1, var2)).max()
    binsIn = arange(minVar, maxVar, (maxVar - minVar) / 10.0)

    (bins1, data1) = histNofill.hist(binsIn, var1)
    (bins2, data2) = histNofill.hist(binsIn, var2)

    foo = stats.stats.ks_2samp(var1, var2)
    print 'KS Test: Distance Statistic (0 is same) = %5.2f' % (foo[0])

    clf()
    hist1 = plot(bins1, data1 / data1.sum(), color='red', linewidth=3)
    hist2 = plot(bins2, data2 / data2.sum(), color='blue', linewidth=3)
    legend((hist1, hist2), (file1, file2))
    xlabel(axisLabel)
    ylabel('Probability')

    savefig('compareParams_' + column + '.png')
    savefig('compareParams_' + column + '.eps')
コード例 #9
0
ファイル: velocity.py プロジェクト: AtomyChan/JLU-python-code
def compareAlignVels(alignRoot, polyRoot):
    """
    Compare the velocities that are derived in align and in polyfit.
    There must be the same number of stars (and in the same order)
    in the align and polyfit output.

    Input Parameters:
    -- the root name of the align output (e.g. 'align/align_d_rms_t'
    -- the root name of the polyfit output( e.g. 'polyfit_d/fit')
    """
    cc = objects.Constants()
    s = starset.StarSet(alignRoot, absolute=0)
    s.loadPolyfit(polyRoot, arcsec=0)

    pixyr2kms = 0.00995 * cc.asy_to_kms
    #pixyr2kms = cc.asy_to_kms

    # Need to get rid of the central arcsecond sources
    r = s.getArray('r2d')
    idx = (py.where(r > 0.5))[0]
    s.stars = [s.stars[ii] for ii in idx]
    r = s.getArray('r2d')

    # Align Fit in Pixels
    vxa = s.getArray('fitpXalign.v') * pixyr2kms
    vya = s.getArray('fitpYalign.v') * pixyr2kms
    vxa_err = s.getArray('fitpXalign.verr') * pixyr2kms
    vya_err = s.getArray('fitpYalign.verr') * pixyr2kms
    vxp = s.getArray('fitpXv.v') * pixyr2kms
    vyp = s.getArray('fitpYv.v') * pixyr2kms
    vxp_err = s.getArray('fitpXv.verr') * pixyr2kms
    vyp_err = s.getArray('fitpYv.verr') * pixyr2kms

    # Plot differences in Sigmas but can't combine (not independent)
    vxdiff = vxa - vxp
    vydiff = vya - vyp

    vxsig1 = vxdiff / vxa_err
    vysig1 = vydiff / vya_err
    vxsig2 = vxdiff / vxp_err
    vysig2 = vydiff / vyp_err

    #####
    # Crude velocity plot (absolute velocity differences)
    #####
    py.clf()
    py.subplot(2, 1, 1)
    py.plot(vxa, vxp, 'k.')
    py.xlabel('Align vx (km/s)')
    py.ylabel('Polyfit vx (km/s)')
    py.title('Align vs. Polyfit Vel')

    py.subplot(2, 1, 2)
    py.plot(vya, vyp, 'k.')
    py.xlabel('Align vy (km/s)')
    py.ylabel('Polyfit vy (km/s)')
    py.savefig('plots/align_vs_poly_v.png')


    #####
    # Compare velocity errors
    #####
    py.clf()
    py.plot(vxa_err, vxp_err, 'r.')
    py.plot(vya_err, vyp_err, 'b.')
    py.plot([0, 30], [0, 30], 'k--')
    py.axis('equal')
    py.axis([0, 30, 0, 30])
    py.xlabel('Align Vel Error (km/s)')
    py.ylabel('Poly Vel Error (km/s)')
    py.legend(('X', 'Y'))
    py.title('Align vs. Polyfit Vel. Errors')
    py.savefig('plots/align_vs_poly_verr.png')

    #####
    # Absolute velocity differences
    #####
    py.clf()
    py.plot(vxa, vxdiff, 'r.')
    py.plot(vya, vydiff, 'b.')
    py.legend(('X', 'Y'))
    py.xlabel('Align v (km/s)')
    py.ylabel('Align - Poly (km/s)')
    py.title('Align - Polyfit Vel.')
    py.savefig('plots/align_vs_poly_vdiff.png')

    #####
    # Velocity difference in sigmas
    #####
    py.clf()
    py.plot(vxa, vxsig1, 'r.')
    py.plot(vya, vysig1, 'b.')
    py.legend(('X', 'Y'))
    py.title('Diff over align error')
    py.xlabel('Align v (km/s)')
    py.ylabel('Align - Poly (sigma)')
    py.title('(Align - Polyfit) / Align Err')
    py.savefig('plots/align_vs_poly_vsig_alignerr.png')

    py.clf()
    py.plot(vxa, vxsig2, 'r.')
    py.plot(vya, vysig2, 'b.')
    py.legend(('X', 'Y'))
    py.title('Diff over poly error')
    py.xlabel('Align v (km/s)')
    py.ylabel('Align - Poly (sigma)')
    py.title('(Align - Polyfit) / Polyfit Err')
    py.savefig('plots/align_vs_poly_vsig_polyerr.png')

    #####
    # Histogram of Sigmas
    #####
    binsIn = py.arange(-6, 6, 0.5)
    (bins, vxhist1) = histNofill.hist(binsIn, vxsig1, normed=True)
    (bins, vxhist2) = histNofill.hist(binsIn, vxsig2, normed=True)
    (bins, vyhist1) = histNofill.hist(binsIn, vysig1, normed=True)
    (bins, vyhist2) = histNofill.hist(binsIn, vysig2, normed=True)

    # Make a gaussian for what is expected
    gg = stats.distributions.norm()
    gaussian = gg.pdf(bins)

    py.clf()
    py.plot(bins, vxhist1, 'r-')
    py.plot(bins, vyhist1, 'b-')
    py.plot(bins, gaussian, 'k--')
    py.legend(('X', 'Y'))
    py.xlabel('Align - Poly (sigma)')
    py.title('Vel Diff Significance (Align Err)')
    py.savefig('plots/align_vs_poly_hist_alignerr.png')

    py.clf()
    py.plot(bins, vxhist2, 'r-')
    py.plot(bins, vyhist2, 'b-')
    py.plot(bins, gaussian, 'k--')
    py.legend(('X', 'Y'))
    py.xlabel('Align - Poly (sigma)')
    py.title('Vel Diff Significance (Poly Err)')
    py.savefig('plots/align_vs_poly_hist_polyerr.png')
コード例 #10
0
def compareAlignVels(alignRoot, polyRoot):
    """
    Compare the velocities that are derived in align and in polyfit.
    There must be the same number of stars (and in the same order)
    in the align and polyfit output.

    Input Parameters:
    -- the root name of the align output (e.g. 'align/align_d_rms_t'
    -- the root name of the polyfit output( e.g. 'polyfit_d/fit')
    """
    cc = objects.Constants()
    s = starset.StarSet(alignRoot, absolute=0)
    s.loadPolyfit(polyRoot, arcsec=0)

    pixyr2kms = 0.00995 * cc.asy_to_kms
    #pixyr2kms = cc.asy_to_kms

    # Need to get rid of the central arcsecond sources
    r = s.getArray('r2d')
    idx = (py.where(r > 0.5))[0]
    s.stars = [s.stars[ii] for ii in idx]
    r = s.getArray('r2d')

    # Align Fit in Pixels
    vxa = s.getArray('fitpXalign.v') * pixyr2kms
    vya = s.getArray('fitpYalign.v') * pixyr2kms
    vxa_err = s.getArray('fitpXalign.verr') * pixyr2kms
    vya_err = s.getArray('fitpYalign.verr') * pixyr2kms
    vxp = s.getArray('fitpXv.v') * pixyr2kms
    vyp = s.getArray('fitpYv.v') * pixyr2kms
    vxp_err = s.getArray('fitpXv.verr') * pixyr2kms
    vyp_err = s.getArray('fitpYv.verr') * pixyr2kms

    # Plot differences in Sigmas but can't combine (not independent)
    vxdiff = vxa - vxp
    vydiff = vya - vyp

    vxsig1 = vxdiff / vxa_err
    vysig1 = vydiff / vya_err
    vxsig2 = vxdiff / vxp_err
    vysig2 = vydiff / vyp_err

    #####
    # Crude velocity plot (absolute velocity differences)
    #####
    py.clf()
    py.subplot(2, 1, 1)
    py.plot(vxa, vxp, 'k.')
    py.xlabel('Align vx (km/s)')
    py.ylabel('Polyfit vx (km/s)')
    py.title('Align vs. Polyfit Vel')

    py.subplot(2, 1, 2)
    py.plot(vya, vyp, 'k.')
    py.xlabel('Align vy (km/s)')
    py.ylabel('Polyfit vy (km/s)')
    py.savefig('plots/align_vs_poly_v.png')

    #####
    # Compare velocity errors
    #####
    py.clf()
    py.plot(vxa_err, vxp_err, 'r.')
    py.plot(vya_err, vyp_err, 'b.')
    py.plot([0, 30], [0, 30], 'k--')
    py.axis('equal')
    py.axis([0, 30, 0, 30])
    py.xlabel('Align Vel Error (km/s)')
    py.ylabel('Poly Vel Error (km/s)')
    py.legend(('X', 'Y'))
    py.title('Align vs. Polyfit Vel. Errors')
    py.savefig('plots/align_vs_poly_verr.png')

    #####
    # Absolute velocity differences
    #####
    py.clf()
    py.plot(vxa, vxdiff, 'r.')
    py.plot(vya, vydiff, 'b.')
    py.legend(('X', 'Y'))
    py.xlabel('Align v (km/s)')
    py.ylabel('Align - Poly (km/s)')
    py.title('Align - Polyfit Vel.')
    py.savefig('plots/align_vs_poly_vdiff.png')

    #####
    # Velocity difference in sigmas
    #####
    py.clf()
    py.plot(vxa, vxsig1, 'r.')
    py.plot(vya, vysig1, 'b.')
    py.legend(('X', 'Y'))
    py.title('Diff over align error')
    py.xlabel('Align v (km/s)')
    py.ylabel('Align - Poly (sigma)')
    py.title('(Align - Polyfit) / Align Err')
    py.savefig('plots/align_vs_poly_vsig_alignerr.png')

    py.clf()
    py.plot(vxa, vxsig2, 'r.')
    py.plot(vya, vysig2, 'b.')
    py.legend(('X', 'Y'))
    py.title('Diff over poly error')
    py.xlabel('Align v (km/s)')
    py.ylabel('Align - Poly (sigma)')
    py.title('(Align - Polyfit) / Polyfit Err')
    py.savefig('plots/align_vs_poly_vsig_polyerr.png')

    #####
    # Histogram of Sigmas
    #####
    binsIn = py.arange(-6, 6, 0.5)
    (bins, vxhist1) = histNofill.hist(binsIn, vxsig1, normed=True)
    (bins, vxhist2) = histNofill.hist(binsIn, vxsig2, normed=True)
    (bins, vyhist1) = histNofill.hist(binsIn, vysig1, normed=True)
    (bins, vyhist2) = histNofill.hist(binsIn, vysig2, normed=True)

    # Make a gaussian for what is expected
    gg = stats.distributions.norm()
    gaussian = gg.pdf(bins)

    py.clf()
    py.plot(bins, vxhist1, 'r-')
    py.plot(bins, vyhist1, 'b-')
    py.plot(bins, gaussian, 'k--')
    py.legend(('X', 'Y'))
    py.xlabel('Align - Poly (sigma)')
    py.title('Vel Diff Significance (Align Err)')
    py.savefig('plots/align_vs_poly_hist_alignerr.png')

    py.clf()
    py.plot(bins, vxhist2, 'r-')
    py.plot(bins, vyhist2, 'b-')
    py.plot(bins, gaussian, 'k--')
    py.legend(('X', 'Y'))
    py.xlabel('Align - Poly (sigma)')
    py.title('Vel Diff Significance (Poly Err)')
    py.savefig('plots/align_vs_poly_hist_polyerr.png')