Пример #1
0
def spflg(vis,
          tel=['ST001', 'DE601'],
          lastv=-1,
          datacolumn='DATA',
          pol=0,
          doplot=False):
    # Find which number is which antenna
    itels = np.sort(idx_tels.get_idx_tels(vis, tel))
    if itels == []:
        print 'Failed to find telescopes, returning'
        return -1, -1
    d1 = dget_t(vis, itels[0], itels[1], datacolumn=datacolumn)
    d1 = d1[pol, :, :lastv]
    a1, p1 = np.abs(d1), np.arctan2(d1.imag, d1.real)
    a2 = np.sort(np.ravel(a1))
    amax = a2[99 * len(a2) / 100]
    if doplot:
        plt.subplot(121)
        plt.imshow(a1.T,vmax=amax,origin='lower',aspect='auto',\
                   interpolation='none',cmap=matplotlib.cm.hot)
        plt.title(vis + ' ' + tel[0] + '-' + tel[1])
        plt.xlabel('Amplitude')
        plt.subplot(122)
        plt.imshow(p1.T,origin='lower',aspect='auto',interpolation='none',\
                   cmap=matplotlib.cm.hot)
        plt.xlabel('Phase')
        plt.show()
    else:
        return a1.T, p1.T
Пример #2
0
def closure(vis, tel, lastv=-1, plotfile='clplot.png'):
    # Find which number is which antenna
    itels = np.sort(idx_tels.get_idx_tels(vis, tel))
    if itels == []:
        return -1

    # Make three reference MSs with pointers
    print 'itels', itels
    if have_tables:
        d1, ut1, uvw = dget_t(vis, itels[0], itels[1])
        d2, ut2, uvw = dget_t(vis, itels[1], itels[2])
        d3, ut3, uvw = dget_t(vis, itels[0], itels[2])
    else:
        d1, ut1, uvw = dget_c(vis, itels[0], itels[1])
        d2, ut2, uvw = dget_c(vis, itels[1], itels[2])
        d3, ut3, uvw = dget_c(vis, itels[0], itels[2])
    a1, p1 = getap(d1[:lastv])
    a2, p2 = getap(d2[:lastv])
    a3, p3 = getap(d3[:lastv])
    clph = p1 + p2 - p3
    np.putmask(clph, clph > np.pi, clph - 2 * np.pi)
    np.putmask(clph, clph < -np.pi, clph + 2 * np.pi)
    # return a statistic - is 1.64 for random closure phase, less for coherent
    if len(plotfile):
        plt.plot(clph, 'b+')
        plt.savefig(plotfile)
    return np.mean(np.gradient(np.unwrap(clph))**2)
Пример #3
0
def data_extract(vis):
    global uvw01, uvw02, uvw12, cp012, a01, a02, a12, ra, dec
    chw = taql_calc(vis, 'SPECTRAL_WINDOW', 'CHAN_WIDTH', 'mean')
    ch0 = taql_calc(vis, 'SPECTRAL_WINDOW', 'REF_FREQUENCY', 'mean')
    nchan = taql_calc(vis, 'SPECTRAL_WINDOW', 'NUM_CHAN', 'mean')
    sra, sdec = taql_from(vis, 'FIELD', 'PHASE_DIR')
    nspw = taql_num(vis, 'SPECTRAL_WINDOW', 'NUM_CHAN')
    sra = np.asarray(sra.replace('h', ' ').replace('m', ' ').split(),
                     dtype='f')
    sdec = np.asarray(sdec.replace('d', ' ').replace('m', ' ').split(),
                      dtype='f')
    ra = 15.0 * (sra[0] + sra[1] / 60.0 + sra[2] / 3600.0)
    dec = sdec[0] + sdec[1] / 60.0 + sdec[2] / 3600.0
    wlength = np.mean(LIGHT / (ch0 + chw * np.arange(nspw * nchan)))
    itel = np.array(idx_tels.get_idx_tels(vis, trname))
    # order of telescopes on baselines 0-1, 0-2, 1-2; -1 if in "wrong" order
    otel = 1. - 2. * np.asarray(
        [itel[0] > itel[1], itel[0] > itel[2], itel[1] > itel[2]], dtype=float)
    btel = [min(itel[0],itel[1]),max(itel[0],itel[1]),min(itel[0],itel[2]),\
            max(itel[0],itel[2]),min(itel[1],itel[2]),max(itel[1],itel[2])]
    if have_tables:
        d01, ut01, uvw01 = dget_t(vis, btel[0], btel[1])
        d02, ut02, uvw02 = dget_t(vis, btel[2], btel[3])
        d12, ut12, uvw12 = dget_t(vis, btel[4], btel[5])
    else:
        d01, ut01, uvw01 = dget_c(vis, btel[0], btel[1])
        d02, ut02, uvw02 = dget_c(vis, btel[2], btel[3])
        d12, ut12, uvw12 = dget_c(vis, btel[4], btel[5])
    # check for flagged data in one of the baselines. If so cut the other arrays
    # this is ugly and inaccurate
    mindat = min(d01.shape[2], d02.shape[2], d12.shape[2])
    maxdat = max(d01.shape[2], d02.shape[2], d12.shape[2])
    if mindat != maxdat:
        print 'Warning - arrays are not the same length. Cutting the longer one at the end.'
        print '(Inaccurate - watch the results carefully)'
        d01, d02, d12 = d01[:, :, :mindat], d02[:, :, :mindat], d12[:, :, :
                                                                    mindat]
        minuv = min(uvw01.shape[0], uvw02.shape[0], uvw12.shape[0])
        uvw01, uvw02, uvw12 = uvw01[:minuv], uvw02[:minuv], uvw12[:minuv]
        mint = min(ut01.shape[0], ut02.shape[0], ut12.shape[0])
        ut01, ut02, ut12 = ut01[:minuv], ut02[:minuv], ut12[:minuv]
    a01, p01 = getap(d01)
    a02, p02 = getap(d02)
    a12, p12 = getap(d12)
    cp012 = norm(otel[0] * p01 - otel[1] * p02 + otel[2] * p12, False)
    uvw01 /= wlength
    uvw02 /= wlength
    uvw12 /= wlength
    print trname, '-> antenna numbers:', itel
    print 'Baseline lengths: %s-%s: %dkm %s-%s: %dkm %s-%s: %dkm' % \
       (trname[0],trname[1],int(np.sqrt((uvw01[0]**2).sum())*wlength/1000),\
        trname[0],trname[2],int(np.sqrt((uvw02[0]**2).sum())*wlength/1000),\
        trname[1],trname[2],int(np.sqrt((uvw12[0]**2).sum())*wlength/1000))
    os.system('rm -fr cl_tmp*.ms')
    return itel, np.mean(wlength)
def data_extract(vis):
    global uvw01, uvw02, uvw12, cp012, a01, a02, a12
    chw = taql_calc(vis, 'SPECTRAL_WINDOW', 'CHAN_WIDTH', 'mean')
    ch0 = taql_calc(vis, 'SPECTRAL_WINDOW', 'REF_FREQUENCY', 'mean')
    nchan = taql_calc(vis, 'SPECTRAL_WINDOW', 'NUM_CHAN', 'mean')
    sra, sdec = taql_from(vis, 'FIELD', 'PHASE_DIR')
    nspw = taql_num(vis, 'SPECTRAL_WINDOW', 'NUM_CHAN')
    sra = np.asarray(sra.replace('h', ' ').replace('m', ' ').split(),
                     dtype='f')
    sdec = np.asarray(sdec.replace('d', ' ').replace('m', ' ').split(),
                      dtype='f')
    ra = 15.0 * (sra[0] + sra[1] / 60.0 + sra[2] / 3600.0)
    dec = sdec[0] + sdec[1] / 60.0 + sdec[2] / 3600.0
    wlength = np.mean(LIGHT / (ch0 + chw * np.arange(nspw * nchan)))
    itel = np.array(idx_tels.get_idx_tels(vis, trname))
    # order of telescopes on baselines 0-1, 0-2, 1-2; -1 if in "wrong" order
    otel = 1. - 2. * np.asarray(
        [itel[0] > itel[1], itel[0] > itel[2], itel[1] > itel[2]], dtype=float)
    btel = [min(itel[0],itel[1]),max(itel[0],itel[1]),min(itel[0],itel[2]),\
            max(itel[0],itel[2]),min(itel[1],itel[2]),max(itel[1],itel[2])]
    if have_tables:
        d01, ut01, uvw01 = dget_t(vis, btel[0], btel[1])
        d02, ut02, uvw02 = dget_t(vis, btel[2], btel[3])
        d12, ut12, uvw12 = dget_t(vis, btel[4], btel[5])
    else:
        d01, ut01, uvw01 = dget_c(vis, btel[0], btel[1])
        d02, ut02, uvw02 = dget_c(vis, btel[2], btel[3])
        d12, ut12, uvw12 = dget_c(vis, btel[4], btel[5])
    a01, p01 = getap(d01)
    a02, p02 = getap(d02)
    a12, p12 = getap(d12)
    cp012 = otel[0] * p01 - otel[1] * p02 + otel[2] * p12
    np.putmask(cp012, cp012 > np.pi, cp012 - 2 * np.pi)
    np.putmask(cp012, cp012 < -np.pi, cp012 + 2 * np.pi)
    uvw01 /= wlength
    uvw02 /= wlength
    uvw12 /= wlength
    print trname, '-> antenna numbers:', itel
    print 'Baseline lengths: %s-%s: %dkm %s-%s: %dkm %s-%s: %dkm' % \
       (trname[0],trname[1],int(np.sqrt((uvw01[0]**2).sum())*wlength/1000),\
        trname[0],trname[2],int(np.sqrt((uvw02[0]**2).sum())*wlength/1000),\
        trname[1],trname[2],int(np.sqrt((uvw12[0]**2).sum())*wlength/1000))
    os.system('rm -fr cl_tmp*.ms')
    return itel, np.mean(wlength), ra, dec