Ejemplo n.º 1
0
def getVisibilityHeader(f):
    offset = f.tell()
    h = parseDiFX.parse_output_header(f)
    rdlen = f.tell() - offset
    f.seek(offset)
    bin = f.read(rdlen)
    return (h, bin)
Ejemplo n.º 2
0
def getVisibilityHeader(f):
    """Read next DiFX file visibility header and return it in binary was well as a parsed struct"""
    bin = None
    offset = f.tell()
    h = parseDiFX.parse_output_header(f)
    if h:
        rdlen = f.tell() - offset
        f.seek(offset)
        bin = f.read(rdlen)
    return (h, bin)
def checkDiFXViz(job, opts):
    '''Inspect the DiFX output of a job (<job>.difx/DIFX_*) and look at the polarizations of the visibility data'''

    # Antennas that are linear polarized
    linear_antennas = ['AA']

    # Read the .input file of the job
    inputfile = job + '.input'
    commoncfg = parseDiFX.get_common_settings(inputfile)
    (numfreqs, freqs) = parseDiFX.get_freqtable_info(inputfile)
    (numtelescopes, telescopes) = parseDiFX.get_telescopetable_info(inputfile)
    if numfreqs == 0:
        print("Couldn't parse input file " + inputfile + " correctly")
        return False
    antennas = [t.name for t in telescopes]
    has_linpol_ant = any(a in linear_antennas for a in antennas)
    Nvis_stop = numfreqs * 4 * numtelescopes * (numtelescopes - 1) / 2

    # Read the .difx/DIFX_* file referred to from .input
    glob_pattern = commoncfg['difxfile'] + '/DIFX_*.s*.b*'
    difxfileslist = glob.glob(glob_pattern)
    if len(difxfileslist) <= 0:
        print('Error: no visibility data file found in %s!' % (glob_pattern))
        return
    difxfilename = difxfileslist[
        0]  # first file only; TODO what if multiple files?
    difxfile = open(difxfilename, 'r')

    # Check visibility records
    Nvis = 0
    Nvis_linant = 0
    pols_crossed = False
    pols_found = []
    while True:
        hdr = parseDiFX.parse_output_header(difxfile)
        if len(hdr) == 0:
            break
        [
            baseline, mjd, seconds, cfgidx, srcidx, freqindex, polpair,
            pulsarbin, weight, u, v, w, rawhdr
        ] = hdr
        ant2name = telescopes[
            (baseline % 256) -
            1]  # order as in difx2mark4: ref=ant1="256*nr", rem=ant2="nr%256"
        ant1name = telescopes[((baseline - (baseline % 256)) / 256) - 1]
        nchan = freqs[freqindex].numchan / freqs[freqindex].specavg
        difxfile.seek(8 * nchan, 1)

        Nvis = Nvis + 1
        if polpair[0] != polpair[1]:
            pols_crossed = True
        if polpair[0] not in pols_found:
            pols_found.append(polpair[0])
        if polpair[1] not in pols_found:
            pols_found.append(polpair[1])
        if has_linpol_ant:
            if ((ant1name in linear_antennas)
                    or (ant2name in linear_antennas)):
                Nvis_linant = Nvis_linant + 1
            if Nvis_linant > Nvis_stop:
                break
        else:
            if (Nvis > Nvis_stop):
                break

    # Summary
    pols_circular = ('L' in pols_found) or ('R' in pols_found)
    pols_linear = ('X' in pols_found) or ('Y' in pols_found)
    pols_full = ('L' in pols_found) and ('R' in pols_found)
    pols_full = pols_full or (('X' in pols_found) and ('Y' in pols_found))
    if pols_circular and pols_linear:
        polinfo = opts.colors.RED + 'mixed' + opts.colors.ENDC
    elif pols_circular:
        polinfo = 'circular'
    else:
        polinfo = 'linear'
    if pols_full:
        if pols_crossed:
            polinfo += ' full-Stokes'
        else:
            polinfo += ' half-Stokes'
    if not opts.doShort:
        polinfo += ' in ' + difxfilename
    return polinfo
Ejemplo n.º 4
0
if numfreqs == 0:
    parser.error("Couldn't parse input file " + inputfile + " correctly!")
if not os.path.exists(args[0]):
    parser.error("Input difx file %s doesn't exist!" % (args[0]))
if os.path.exists(args[1]):
    parser.error("Output difx file %s already exists!" % (args[1]))
starttime = float(timerange[0])
stoptime = float(timerange[1])

difxinput = open(args[0])
difxoutput = open(args[1], 'w')
vis = []
for j in range(maxchannels):
    vis.append(0.0)

nextheader = parseDiFX.parse_output_header(difxinput)
if len(nextheader) == 0:
    print("Problem with input file " + args[0] + " - aborting")
    sys.exit()

startmjd = nextheader[1]
while not len(nextheader) == 0:
    freqindex = nextheader[5]
    nchan = freqs[freqindex].numchan / freqs[freqindex].specavg
    if nchan > maxchannels:
        print ("How embarrassing - you have tried to read files with more than " + \
              str(maxchannels) + " channels.  Please rerun with --maxchannels=<bigger number>!")
        sys.exit()
    mjd = nextheader[1]
    seconds = nextheader[2]
    buffer = difxinput.read(8 * nchan)
Ejemplo n.º 5
0
amp=[]
phase=[]
for i in range(numfreqs):
    amp.append([])
    phase.append([])
    for j in range(maxchannels):
        amp[i].append([])
        phase[i].append([])
    
chans = []
for i in range(maxchannels):
    chans.append(i)

difxinputA = open(args[0])
difxinputB = open(args[1])
nextheaderA = parseDiFX.parse_output_header(difxinputA)
nextheaderB = parseDiFX.parse_output_header(difxinputB)
savednchan = -1
vislen = 0
lastseconds = -1
while not len(nextheaderA) == 0:
    baseline  = nextheaderA[0]
    mjd       = nextheaderA[1]
    seconds   = nextheaderA[2]
    freqindex = nextheaderA[5]
    polpair   = nextheaderA[6]
    nchan     = freqs[freqindex].numchan/freqs[freqindex].specavg
    if nchan > maxchannels:
        print ("How embarrassing - you have tried to read files with more than " + \
            str(maxchannels) + " channels.  Please rerun with --maxchannels=<bigger number>!")
        sys.exit()
Ejemplo n.º 6
0
freqindex = []
baseline = []
nchan = []
mjd = []
seconds = []
for filename in args:
    difxinputs.append(open(filename, 'rb'))
    freqindex.append(0)
    nchan.append(0)
    baseline.append(0)
    mjd.append(0)
    seconds.append(0)
    nextheader.append([])

for i in range(numfiles):
    nextheader[i] = parseDiFX.parse_output_header(difxinputs[i])

recordcount = 0
headerdisagreecount = 0
longtermabsdiff = 0.0
longtermmeandiff = complex(0.0, 0.0)
disagreeskip = -1
while not len(nextheader[0]) == 0 and not len(nextheader[1]) == 0:
    if maxrecords > 0:
        readrecords = recordcount - skiprecords
        if readrecords >= maxrecords:
            print("Have examined " + str(readrecords) + " - finishing up!")
            break
    for i in range(numfiles):
        baseline[i] = nextheader[i][0]
        freqindex[i] = nextheader[i][5]