Ejemplo n.º 1
0
def task (args):
    """Run as a command-line task.

   args: list of strings; command-line arguments, not including the
         program name (no traditional argv[0]).
returns: None

Will call mirtask.util.die on some errors.
"""
    util.checkusage (__doc__, ['dummy'] + args)

    ks = keys.KeySpec ()
    ks.keyword ('out', 'f', ' ')
    ks.keyword ('naver', 'i', -1)
    ks.keyword ('slop', 'd', DEFAULT_SLOP)
    ks.uvdat (UVDAT_OPTIONS + 'dslr')
    opts = ks.process (args)

    if opts.out == ' ':
        util.wrongusage (__doc__, 'must specify an output filename (out=...)')

    out = VisData (opts.out)

    if opts.naver == -1:
        util.wrongusage (__doc__,
                         'must specify the number of channels to average (naver=...)')

    try:
        channelAverage (out, opts.naver, opts.slop, banner=DEFAULT_BANNER, args=args)
    except (InputStructureError, ValueError), e:
        util.die (str (e))
Ejemplo n.º 2
0
def task(args=None):
    banner = util.printBannerGit('pwflux', 'calculate flux from UV data',
                                 IDENT)

    ks = keys.KeySpec()
    ks.keyword('interval', 'd', 1)
    ks.mkeyword('offset', 'd', 2)
    ks.keyword('textapp', 'f', ' ')
    ks.option('plot')
    ks.uvdat('dsl3w', True)
    opts = ks.process(args)

    interval = opts.interval / (24. * 60.)

    if interval <= 0:
        print >> sys.stderr, 'Error: averaging interval must be positive, not', opts.interval
        return 1

    if len(opts.offset) == 0:
        offset = np.zeros(2)
    elif len(opts.offset) == 2:
        offset = np.asarray(opts.offset) / 206265.
    else:
        print >> sys.stderr, (
            'Error: zero or two values must be specified for source offset;'
            ' got'), opts.offset
        return 1

    if opts.plot:
        try:
            import omega
        except ImportError:
            util.die('cannot import Python module "omega" for plotting')

    f = Fluxer(interval, offset)
    onflush = flushPrint

    if opts.textapp != ' ':
        appobj = TabularAppender(file(opts.textapp, 'a'), onflush)
        onflush = appobj.onFlush

    if opts.plot:
        plotacc = PlotAccumulator(onflush)
        onflush = plotacc.onFlush

    f.onFlush(onflush)
    f.process()

    if opts.plot:
        plotacc.plot().show()

    return 0
Ejemplo n.º 3
0
def task(args):
    from miriad import CalData
    from mirtask import cliutil, keys

    banner = util.printBannerGit('gptext', 'convert gains to and from text',
                                 IDENT)

    ks = keys.KeySpec()
    ks.keyword('vis', 'f', ' ')
    ks.keyword('out', 'f', ' ')
    ks.keymatch('mode', 1, ['totext', 'applyvis', 'createvis'])
    opts = ks.process(args)

    if opts.out == ' ':
        util.die('must specify an output filename (out=...)')

    if opts.vis == ' ':
        util.die('must specify an input filename (vis=...)')

    mode = opts.mode[0]
    gi = GainsInfo()

    if mode == 'totext':
        gi.fromDataset(CalData(opts.vis).open('rw'))

        if opts.out == '-':
            gi.toText(sys.stdout)
        else:
            gi.toText(open(opts.out, 'w'))
    elif mode == 'applyvis':
        gi.fromText(open(opts.vis))
        h = CalData(opts.out).open('rw')
        gi.toDataset(h)
        h.openHistory()
        h.writeHistory(banner)
        h.logInvocation('PYTHON gptext', args)
        h.closeHistory()
        h.close()
    elif mode == 'createvis':
        gi.fromText(open(opts.vis))
        h = CalData(opts.out).open('c')
        gi.toDataset(h)
        h.openHistory()
        h.writeHistory(banner)
        h.logInvocation('PYTHON gptext', args)
        h.closeHistory()
        h.close()
    else:
        util.die('unrecognized mode "%s"', mode)
Ejemplo n.º 4
0
def task(args):
    banner = printBannerGit('gpmergepols',
                            'merge gains table for multi-pol data', IDENT)

    # Args
    ks = keys.KeySpec()
    ks.mkeyword('vis', 'f', 2)
    ks.keyword('out', 'f', ' ')
    ks.keyword('ttol', 'd', DEFAULT_TTOL * 86400)
    ks.option('replace')
    opts = ks.process(args)

    if len(opts.vis) != 2:
        print >> sys.stderr, 'Error: must specify two input vis or gains files'
        return 1

    if opts.out == ' ':
        print >> sys.stderr, 'Error: must specify an output dataset'
        return 1

    ttol = opts.ttol / 86400

    # Run it
    ds1 = miriad.Data(opts.vis[0]).open('rw')
    ds2 = miriad.Data(opts.vis[1]).open('rw')

    if opts.replace:
        outset = miriad.Data(opts.out).open('rw')
    else:
        outset = miriad.Data(opts.out).open('c')
        ds1.copyItem(outset, 'history')

    try:
        merge(opts.vis[0], ds1, opts.vis[1], ds2, outset, banner, ttol)
    except FormatError, e:
        print >> sys.stderr, 'Error:', e.args[0]
        return 1
Ejemplo n.º 5
0
def task(args):
    banner = util.printBannerGit(
        'closanal', 'attempt to identify bad baselines based on '
        'closure quantities', IDENT)

    ks = keys.KeySpec()
    ks.keyword('interval', 'd', 10.)
    ks.keyword('nclos', 'i', 10)
    ks.keyword('nbl', 'i', 10)
    ks.keyword('nant', 'i', 10)
    ks.option('rmshist', 'best', 'uvdplot', 'blhist', 'amplitude', 'relative')
    ks.uvdat('dsl3xw', True)
    args = ks.process(args)

    # Verify arguments

    interval = args.interval / 60. / 24.
    if interval < 0:
        print >> sys.stderr, 'Error: averaging interval must be nonnegative'
        return 1

    # Summarize parameters

    if args.amplitude:
        cc = QuadComputer(args.rmshist, args.relative)
    else:
        cc = TripleComputer(args.rmshist, args.relative)

    print 'Configuration:'
    print '  Averaging interval: %g minutes' % (args.interval)
    print '  Calculating %s closure %s' % (cc.item, cc.datum)

    if args.relative:
        print '  Using relative (x/sigma_x) ranking'
    else:
        print '  Using absolute ranking'

    # Read the info

    cp = ClosureProcessor(interval, [cc], args.uvdplot)

    print 'Reading data ...',
    cp.readUVDat()
    print 'done.'
    cc.pDataSummary()

    # Compute and print out the statistics

    cc.computeStats()

    cc.pQuantities(args.nclos, args.best)
    cc.pBasepols(args.nbl, args.best)
    cc.pAntpols(args.nant, args.best)

    # Misc queries

    if args.uvdplot:
        print
        print 'Showing baseline closure errors as function of UV distance ...'
        cp.plotUVDs().show()

    if args.rmshist:
        print
        print 'Showing histogram of closure quantities ...'
        cc.valHist().show()

    if args.blhist:
        print
        print 'Showing histogram of baseline closure values ...'
        cc.bpHist().show()

    # All done!

    return 0
Ejemplo n.º 6
0
def task (args):
    banner = util.printBannerGit ('atabpass', 'correct for ATA digital filter bandpass', IDENT)

    ks = keys.KeySpec ()
    ks.keyword ('out', 'f', ' ')
    ks.uvdat ('ds3', False)
    opts = ks.process (args)

    if opts.out == ' ':
        print >>sys.stderr, 'Error: must give an output filename'
        sys.exit (1)

    bpass = getData ()

    # Multifile UV copying algorithm copied from uvdat.for;
    # implementation copied from fxcal.py

    dOut = miriad.VisData (opts.out).open ('c')
    dOut.setPreambleType ('uvw', 'time', 'baseline')

    first = True
    curFile = None
    saveNPol = 0
    polsVaried = False

    windowVars = ['ischan', 'nschan', 'nspect', 'restfreq',
                  'sdf', 'sfreq', 'systemp', 'xtsys', 'ytsys']

    for dIn, preamble, data, flags in uvdat.read ():
        anyChange = False

        if dIn is not curFile:
            # Started reading a new file (or the first file)
            corrType, corrLen, corrUpd = dIn.probeVar ('corr')

            if corrType != 'r' and corrType != 'j' and corrType != 'c':
                raise Exception ('No channels to copy')

            if first:
                # This is NOT a close approximation to uvcat.for
                # We don't use an 'init' var since we assume dochan=True.
                dOut.setCorrelationType (corrType)

            dIn.initVarsAsInput (' ') # what does ' ' signify?
            dOut.initVarsAsOutput (dIn, ' ')

            uvt = dIn.makeVarTracker ()
            uvt.track (*windowVars)

            tup = dIn.probeVar ('npol')
            doPol = tup is not None and (tup[0] == 'i')
            nPol = 0
            doneNPol = False
            curFile = dIn
            anyChange = True

        if first:
            # If very first file, copy the history entry.
            dIn.copyItem (dOut, 'history')
            first = False

        if nPol == 0:
            # We're on to a new set of baselines. Get the number
            # of pols in this next set and remind ourselves to
            # update the 'npol' variable if necessary.
            nPol = dIn.getNPol ()
            doneNPol = False

        if uvt.updated ():
            nAnts = dIn.getVarInt ('nants')

            tbl = {}

            dIn.probeVar ('nspect')
            nSpec = dIn.getVarInt ('nspect')
            tbl['nspect'] = ('i', nSpec)

            for v in ['nschan', 'ischan']:
                dIn.probeVar (v)
                tbl[v] = ('i', dIn.getVarInt (v, nSpec))

            for v in ['sdf', 'sfreq', 'restfreq']:
                dIn.probeVar (v)
                tbl[v] = ('d', dIn.getVarDouble (v, nSpec))

            for v in ['systemp', 'xtsys', 'ytsys', 'xyphase']:
                tup = dIn.probeVar (v)

                if tup is not None and tup[0] == 'r':
                    tbl[v] = ('r', dIn.getVarFloat (v, tup[1]))

            for (name, (code, val)) in tbl.iteritems ():
                if code == 'i':
                    dOut.writeVarInt (name, val)
                elif code == 'r':
                    dOut.writeVarFloat (name, val)
                elif code == 'd':
                    dOut.writeVarDouble (name, val)
                else:
                    assert (False)

            anyChange = True

        pol = dIn.getPol ()

        if not doneNPol:
            # If necessary, write out a new value for the
            # 'npol' variable. If npol has changed, note
            # that so that we know not to write a
            # dataset-wide npol item.

            if nPol != saveNPol:
                dOut.writeVarInt ('npol', nPol)
                polsVaried = polsVaried or saveNPol != 0
                saveNPol = nPol
            doneNPol = True

        dIn.copyLineVars (dOut)

        # Hey! We actually have some data processing to do!

        data /= bpass

        # That was fast.

        dOut.writeVarInt ('pol', pol)
        dOut.write (preamble, data, flags, flags.size)

        # Count down the number of polarizations left for this baseline.
        # When we reach zero, we may reset the npol variable.
        nPol -= 1

    if not polsVaried:
        # Number of pols never varied, so it's valid to write out
        # a single 'npol' item for the entire dataset.
        dOut.setScalarItem ('npol', np.int32, saveNPol)

    # All done. Write history entry and quit.

    dOut.openHistory ()
    dOut.writeHistory (banner)
    dOut.logInvocation ('ATABPASS')
    dOut.closeHistory ()
    dOut.close ()

    return 0