Пример #1
0
def updateObsTable(image, msName, minbl, maxbl, aswvl, usedCounts, visCounts,
                   minTime, maxTime, totTime):
    obstab = pt.table(image.name() + "/LOFAR_OBSERVATION",
                      readonly=False,
                      ack=False)
    oritab = pt.table(image.name() + "/LOFAR_ORIGIN", ack=False)
    minfreq = pt.taql("calc min([select FREQUENCY_MIN from '" + oritab.name() +
                      "'])")
    maxfreq = pt.taql("calc max([select FREQUENCY_MAX from '" + oritab.name() +
                      "'])")
    obstab.putcell("OBSERVATION_FREQUENCY_MIN", 0, minfreq[0])
    obstab.putcell("OBSERVATION_FREQUENCY_MAX", 0, maxfreq[0])
    obstab.putcell("OBSERVATION_FREQUENCY_CENTER", 0,
                   (minfreq[0] + maxfreq[0]) / 2)
    obstab.putcell("OBSERVATION_INTEGRATION_TIME", 0, totTime)
    obstab.putcell("OBSERVATION_START", 0, minTime)
    obstab.putcell("OBSERVATION_END", 0, maxTime)
    obstab.putcell("TIME_RANGE", 0, (minTime, maxTime))
    obstab.putcell("FILENAME", 0, os.path.basename(image.name()))
    obstab.putcell("FILETYPE", 0, "sky")
    pt.taql("update '" + obstab.name() + "' set FILEDATE = mjd(date()), " +
            "RELEASE_DATE = mjd(date()+365)")
    # Determine minimum and maximum baseline length
    # If needed, convert from wavelengths to meters.
    mstab = pt.table(msName, ack=False)
    if aswvl:
        minbl *= 2.99792e8 / maxfreq[0]
        maxbl *= 2.99792e8 / minfreq[0]
    if minbl <= 0:
        mbl = pt.taql("calc sqrt(min([select sumsqr(UVW[:2]) from " + msName +
                      "]))")
        minbl = max(mbl[0], abs(minbl))
    if maxbl <= 0:
        mbl = pt.taql("calc sqrt(max([select sumsqr(UVW[:2]) from " + msName +
                      "]))")
        if maxbl == 0:
            maxbl = mbl[0]
        else:
            maxbl = min(mbl[0], abs(maxbl))
    mstab.close()
    # Add and fill a few extra columns.
    col1 = pt.makescacoldesc("MIN_BASELINE_LENGTH", 0, valuetype='double')
    col2 = pt.makescacoldesc("MAX_BASELINE_LENGTH", 0, valuetype='double')
    col3 = pt.makearrcoldesc("NVIS_USED", 0, valuetype='int')
    col4 = pt.makearrcoldesc("NVIS_TOTAL", 0, valuetype='int')
    obstab.addcols(pt.maketabdesc([col1, col2, col3, col4]))
    obstab.putcolkeyword("MIN_BASELINE_LENGTH", "QuantumUnits", ["m"])
    obstab.putcolkeyword("MAX_BASELINE_LENGTH", "QuantumUnits", ["m"])
    obstab.putcell("MIN_BASELINE_LENGTH", 0, minbl)
    obstab.putcell("MAX_BASELINE_LENGTH", 0, maxbl)
    # Get sum for all MSs.
    tusedCounts = usedCounts.sum(axis=0)
    tvisCounts = visCounts.sum(axis=0)
    obstab.putcell("NVIS_USED", 0, tusedCounts)
    obstab.putcell("NVIS_TOTAL", 0, tvisCounts)
    obstab.close()
    oritab.close()
    print "Updated subtable LOFAR_OBSERVATION"
Пример #2
0
def updateObsTable (image, msName, minbl, maxbl, aswvl,
                    usedCounts, visCounts, minTime, maxTime, totTime):
    obstab = pt.table (image.name() + "/LOFAR_OBSERVATION", readonly=False,
                       ack=False)
    oritab = pt.table (image.name() + "/LOFAR_ORIGIN", ack=False)
    minfreq = pt.taql ("calc min([select FREQUENCY_MIN from '" +
                       oritab.name() + "'])")
    maxfreq = pt.taql ("calc max([select FREQUENCY_MAX from '" +
                       oritab.name() + "'])") 
    obstab.putcell ("OBSERVATION_FREQUENCY_MIN", 0, minfreq[0]);
    obstab.putcell ("OBSERVATION_FREQUENCY_MAX", 0, maxfreq[0]);
    obstab.putcell ("OBSERVATION_FREQUENCY_CENTER", 0, (minfreq[0]+maxfreq[0])/2);
    obstab.putcell ("OBSERVATION_INTEGRATION_TIME", 0, totTime);
    obstab.putcell ("OBSERVATION_START", 0, minTime);
    obstab.putcell ("OBSERVATION_END", 0, maxTime);
    obstab.putcell ("TIME_RANGE", 0, (minTime, maxTime));
    obstab.putcell ("FILENAME", 0, os.path.basename(image.name()))
    obstab.putcell ("FILETYPE", 0, "sky")
    pt.taql ("update '" + obstab.name() + "' set FILEDATE = mjd(date()), " +
             "RELEASE_DATE = mjd(date()+365)")
    # Determine minimum and maximum baseline length
    # If needed, convert from wavelengths to meters.
    mstab = pt.table(msName, ack=False)
    if aswvl:
        minbl *= 2.99792e8 / maxfreq[0]
        maxbl *= 2.99792e8 / minfreq[0]
    if minbl <= 0:
        mbl = pt.taql ("calc sqrt(min([select sumsqr(UVW[:2]) from " + msName + "]))")
        minbl = max(mbl[0], abs(minbl))
    if maxbl <= 0:
        mbl = pt.taql ("calc sqrt(max([select sumsqr(UVW[:2]) from " + msName + "]))")
        if maxbl == 0:
            maxbl = mbl[0]
        else:
            maxbl = min(mbl[0], abs(maxbl))
    mstab.close()
    # Add and fill a few extra columns.
    col1 = pt.makescacoldesc ("MIN_BASELINE_LENGTH", 0, valuetype='double')
    col2 = pt.makescacoldesc ("MAX_BASELINE_LENGTH", 0, valuetype='double')
    col3 = pt.makearrcoldesc ("NVIS_USED", 0, valuetype='int')
    col4 = pt.makearrcoldesc ("NVIS_TOTAL", 0, valuetype='int')
    obstab.addcols (pt.maketabdesc ([col1, col2, col3, col4]))
    obstab.putcolkeyword ("MIN_BASELINE_LENGTH", "QuantumUnits", ["m"])
    obstab.putcolkeyword ("MAX_BASELINE_LENGTH", "QuantumUnits", ["m"])
    obstab.putcell ("MIN_BASELINE_LENGTH", 0, minbl)
    obstab.putcell ("MAX_BASELINE_LENGTH", 0, maxbl)
    # Get sum for all MSs.
    tusedCounts = usedCounts.sum (axis=0)
    tvisCounts  =  visCounts.sum (axis=0)
    obstab.putcell ("NVIS_USED", 0, tusedCounts)
    obstab.putcell ("NVIS_TOTAL", 0, tvisCounts)
    obstab.close()
    oritab.close()
    print "Updated subtable LOFAR_OBSERVATION"
Пример #3
0
def main(options):
    ms = options.ms
    if ms == '':
            print 'Error: you have to specify an input MS, use -h for help'
            return
    cols = options.cols
    incol = options.incol
    
    t = pt.table(ms, readonly=False, ack=False)

    for col in cols.split(','):
        if col not in t.colnames():
            logging.info('Adding the output column '+col+' to '+ms+'.')
            if incol == '':
                incol = 'DATA'
                update = False
            else:
                update = True

            coldmi = t.getdminfo(incol)
            coldmi['NAME'] = col
            t.addcols(pt.maketabdesc(pt.makearrcoldesc(col, 0., valuetype=t.col(incol).datatype(), shape=numpy.array(t.getcell(incol,0)).shape)), coldmi)  
            if update:
                logging.warning('Setting '+col+' = '+incol+'.')
                t.putcol(col, t.getcol(incol))
        else:
            logging.warning('Column '+col+' already exists.')

    t.close()
Пример #4
0
def main(options):
    inms = options.inms
    if inms == '':
        print 'Error: you have to specify an input MS, use -h for help'
        return
    outcol = options.outcol

    t = pt.table(inms, readonly=False, ack=True)

    if outcol not in t.colnames():
        print 'Adding the output column', outcol, 'to', inms
        coldmi = t.getdminfo('DATA')
        coldmi['NAME'] = outcol
        t.addcols(
            pt.maketabdesc(
                pt.makearrcoldesc(outcol,
                                  0.,
                                  valuetype='complex',
                                  shape=numpy.array(t.getcell('DATA',
                                                              0)).shape)),
            coldmi)
        data = t.getcol('DATA')
        t.putcol(outcol, data)
    else:
        print outcol, 'column already exist'
Пример #5
0
def main(options):

        cI = numpy.complex(0.,1.)

        inms = options.inms
        if inms == '':
                print 'Error: you have to specify an input MS, use -h for help'
                return
        column = options.column
        outcol = options.outcol

        t = pt.table(inms, readonly=False, ack=True)
        if outcol not in t.colnames():
                print 'Adding output column',outcol,'to',inms
                coldmi = t.getdminfo(column)
                coldmi['NAME'] = outcol
                t.addcols(pt.maketabdesc(pt.makearrcoldesc(outcol, 0., valuetype='complex', shape=numpy.array(t.getcell(column,0)).shape)), coldmi)
        print 'Reading input column'
        data = t.getcol(column)
        print 'Computing output column'
        outdata = numpy.transpose(numpy.array([
                data[:,:,0]-cI*data[:,:,1]+cI*data[:,:,2]+data[:,:,3],
                data[:,:,0]+cI*data[:,:,1]+cI*data[:,:,2]-data[:,:,3],
                data[:,:,0]-cI*data[:,:,1]-cI*data[:,:,2]-data[:,:,3],
                data[:,:,0]+cI*data[:,:,1]-cI*data[:,:,2]+data[:,:,3]]),
                (1,2,0))
        print 'Finishing up'
        t.putcol(outcol, outdata)
Пример #6
0
def create_ms(msname, input_fits, ms_dict):
    """ create empty MS """
    x.sh(return_simms_string(msname, input_fits, **ms_dict))

    # set STATION names to same as NAME col
    antt = pt.table(os.path.join(msname, 'ANTENNA'), readonly=False, ack=False)
    antt.putcol('STATION', antt.getcol('NAME'))
    antt.close()

    # set FIELD name to input filename (minus extension)
    fieldtab = pt.table(os.path.join(msname, 'FIELD'),
                        readonly=False,
                        ack=False)
    fieldtab.putcol('NAME', input_fits.split('/')[-1].split('.')[0])
    fieldtab.close()

    # set SOURCE name to input filename (minus extension)
    srctab = pt.table(os.path.join(msname, 'SOURCE'),
                      readonly=False,
                      ack=False)
    srctab.putcol('NAME', input_fits.split('/')[-1].split('.')[0])
    srctab.close()

    # set SPW name to input filename (minus extension)
    spwtab = pt.table(os.path.join(msname, 'SPECTRAL_WINDOW'),
                      readonly=False,
                      ack=False)
    spwtab.putcol('NAME', input_fits.split('/')[-1].split('.')[0])
    spwtab.close()

    # INI: Add WEIGHT_SPECTRUM and SIGMA_SPECTRUM columns to the MS
    tab = pt.table(msname, readonly=False)
    data = tab.getcol('DATA')
    tab.addcols(
        pt.makearrcoldesc('SIGMA_SPECTRUM',
                          value=1.0,
                          shape=[data.shape[1], data.shape[2]],
                          valuetype='float'))
    tab.addcols(
        pt.makearrcoldesc('WEIGHT_SPECTRUM',
                          value=1.0,
                          shape=[data.shape[1], data.shape[2]],
                          valuetype='float'))
    tab.close()

    info('Measurement Set %s created ' % msname)
Пример #7
0
def addcol(ms, incol, outcol):
    if outcol not in ms.colnames():
        logging.info('Adding column: '+outcol)
        coldmi = ms.getdminfo(incol)
        coldmi['NAME'] = outcol
        datatype = ms.col(incol).datatype()
        ms.addcols(pt.maketabdesc(pt.makearrcoldesc(outcol, 0., valuetype=datatype, shape=np.array(ms.getcell(incol,0)).shape)), coldmi)
    if outcol != incol:
        # copy columns val
        logging.info('Set '+outcol+'='+incol)
        ms.putcol(outcol, ms.getcol(incol))
Пример #8
0
def addcol(msname='$MS',colname=None,shape=None,
           data_desc_type='array',valuetype=None,init_with=0,**kw):
    """ add column to MS 
        msanme : MS to add colmn to
        colname : column name
        shape : shape
        valuetype : data type 
        data_desc_type : 'scalar' for scalar elements and array for 'array' elements
        init_with : value to initialise the column with 
    """
    msname, colname = interpolate_locals('msname colname')
    tab = pyrap.tables.table(msname,readonly=False)

    try: 
        tab.getcol(colname)
        info('Column already exists')

    except RuntimeError:
        info('Attempting to add %s column to %s'%(colname,msname))
        from pyrap.tables import maketabdesc
        valuetype = valuetype or 'complex'

        if shape is None: 
            dshape = list(tab.getcol('DATA').shape)
            shape = dshape[1:]

        if data_desc_type=='array':
            from pyrap.tables import makearrcoldesc
            coldmi = tab.getdminfo('DATA') # God forbid this (or the TIME) column doesn't exist
            coldmi['NAME'] = colname.lower()
            tab.addcols(maketabdesc(makearrcoldesc(colname,init_with,shape=shape,valuetype=valuetype)),coldmi)

        elif data_desc_type=='scalar':
            from pyrap.tables import makescacoldesc
            coldmi = tab.getdminfo('TIME')
            coldmi['NAME'] = colname.lower()
            tab.addcols(maketabdesc(makescacoldesc(colname,init_with,valuetype=valuetype)),coldmi)

        info('Column added successfuly.')

        if init_with:
            nrows = dshape[0]

            rowchunk = nrows//10 if nrows > 1000 else nrows
            for row0 in range(0,nrows,rowchunk):
                nr = min(rowchunk,nrows-row0)
                dshape[0] = nr
                tab.putcol(colname,numpy.ones(dshape,dtype=valuetype)*init_with,row0,nr)

    tab.close()
def main(options):
    inms = options.inms
    if inms == '':
        print 'Error: you have to specify an input MS, use -h for help'
        return
    outcol = options.outcol

    t = pt.table(inms, readonly=False, ack=True)

    if outcol not in t.colnames():
        print 'Adding the output column',outcol,'to',inms
        coldmi = t.getdminfo('WEIGHT_SPECTRUM')
        coldmi['NAME'] = outcol
        t.addcols(pt.maketabdesc(pt.makearrcoldesc(outcol, 0., valuetype='float', shape=numpy.array(t.getcell('WEIGHT_SPECTRUM',0)).shape)), coldmi)
        data = t.getcol('WEIGHT_SPECTRUM')
        t.putcol(outcol, data)
    else:
        print outcol, 'column already exist'
Пример #10
0
def export_ms(hdf_file, ms_file, verbosity=1):
    """ Convert an HDF file to MS
    :param hdf_file: Input HDF-MS filename
    :param ms_file: Output MS filename

    TODO: Get this working properly.
    """
    pp = PrintLog(verbosity=verbosity)
    hdul = IdiHdulist(verbosity=1)
    hdul.read_hdf("testms.h5")

    main_hdu = hdul["MAIN"]

    vdict = {
        'float32': 'float',
        'float64': 'double',
        'complex64': 'complex',
        'complex128': 'dcomplex',
        'int32': 'int',
        'uint32': 'uint',
        'str': 'string',
        'bool': 'bool'
    }

    col_descs = []
    for col, cdata in main_hdu.data.items():
        col = str(col)
        pp.pp("%16s %s %s" % (col, cdata.shape, cdata.dtype))

        if cdata.ndim == 1:
            vt = vdict[str(cdata.dtype)]
            cdesc = pt.makescacoldesc(col, cdata[0], valuetype=vt)
        else:
            cdesc = pt.makearrcoldesc(col, cdata[0], valuetype=vt)
        col_descs.append(cdesc)

    tdesc = pt.maketabdesc(col_descs)

    t = pt.table("table.ms", tdesc, nrow=main_hdu.n_rows)
Пример #11
0
def main(options):

    cI = numpy.complex(0., 1.)

    inms = options.inms
    if inms == '':
        print 'Error: you have to specify an input MS, use -h for help'
        return
    column = options.column
    outcol = options.outcol

    t = pt.table(inms, readonly=False, ack=True)
    if outcol not in t.colnames():
        print 'Adding output column', outcol, 'to', inms
        coldmi = t.getdminfo(column)
        coldmi['NAME'] = outcol
        t.addcols(
            pt.maketabdesc(
                pt.makearrcoldesc(outcol,
                                  0.,
                                  valuetype='complex',
                                  shape=numpy.array(t.getcell(column,
                                                              0)).shape)),
            coldmi)
    print 'Reading input column'
    data = t.getcol(column)
    print 'Computing output column'
    outdata = numpy.transpose(
        numpy.array([
            data[:, :, 0] - cI * data[:, :, 1] + cI * data[:, :, 2] +
            data[:, :, 3], data[:, :, 0] + cI * data[:, :, 1] +
            cI * data[:, :, 2] - data[:, :, 3], data[:, :, 0] -
            cI * data[:, :, 1] - cI * data[:, :, 2] - data[:, :, 3],
            data[:, :, 0] + cI * data[:, :, 1] - cI * data[:, :, 2] +
            data[:, :, 3]
        ]), (1, 2, 0))
    print 'Finishing up'
    t.putcol(outcol, outdata)
Пример #12
0
def export_ms(hdf_file, ms_file, verbosity=1):
    """ Convert an HDF file to MS
    :param hdf_file: Input HDF-MS filename
    :param ms_file: Output MS filename

    TODO: Get this working properly.
    """
    pp = PrintLog(verbosity=verbosity)
    hdul = IdiHdulist(verbosity=1)
    hdul.read_hdf("testms.h5")

    main_hdu = hdul["MAIN"]

    vdict = {'float32' : 'float',
               'float64' : 'double',
               'complex64' : 'complex',
               'complex128' : 'dcomplex',
               'int32'  : 'int',
               'uint32' : 'uint',
               'str'    : 'string',
               'bool'   : 'bool'
                }

    col_descs = []
    for col, cdata in main_hdu.data.items():
        col = str(col)
        pp.pp("%16s %s %s" % (col, cdata.shape, cdata.dtype))

        if cdata.ndim == 1:
            vt = vdict[str(cdata.dtype)]
            cdesc = pt.makescacoldesc(col, cdata[0], valuetype=vt)
        else:
            cdesc = pt.makearrcoldesc(col, cdata[0], valuetype=vt)
        col_descs.append(cdesc)

    tdesc = pt.maketabdesc(col_descs)

    t = pt.table("table.ms", tdesc, nrow=main_hdu.n_rows)
Пример #13
0
def addcol(msname,
           colname=None,
           shape=None,
           data_desc_type='array',
           valuetype=None,
           init_with=None,
           coldesc=None,
           coldmi=None,
           clone='DATA',
           rowchunk=None,
           **kw):
    """ Add column to MS 
        msanme : MS to add colmn to
        colname : column name
        shape : shape
        valuetype : data type 
        data_desc_type : 'scalar' for scalar elements and array for 'array' elements
        init_with : value to initialise the column with 
    """
    tab = table(msname, readonly=False)

    if colname in tab.colnames():
        print('Column already exists')
        return 'exists'

    print('Attempting to add %s column to %s' % (colname, msname))

    valuetype = valuetype or 'complex'

    if coldesc:
        data_desc = coldesc
        shape = coldesc['shape']
    elif shape:
        data_desc = maketabdesc(
            makearrcoldesc(colname,
                           init_with,
                           shape=shape,
                           valuetype=valuetype))
    elif valuetype == 'scalar':
        data_desc = maketabdesc(
            makearrcoldesc(colname, init_with, valuetype=valuetype))
    elif clone:
        element = tab.getcell(clone, 0)
        try:
            shape = element.shape
            data_desc = maketabdesc(
                makearrcoldesc(colname,
                               element.flatten()[0],
                               shape=shape,
                               valuetype=valuetype))
        except AttributeError:
            shape = []
            data_desc = maketabdesc(
                makearrcoldesc(colname, element, valuetype=valuetype))

    colinfo = [data_desc, coldmi] if coldmi else [data_desc]
    tab.addcols(*colinfo)

    print('Column added successfuly.')

    if init_with is None:
        tab.close()
        return 'added'
    else:
        spwids = set(tab.getcol('DATA_DESC_ID'))
        for spw in spwids:
            print('Initialising {0:s} column with {1}. DDID is {2:d}'.format(
                colname, init_with, spw))
            tab_spw = tab.query('DATA_DESC_ID=={0:d}'.format(spw))
            nrows = tab_spw.nrows()

            rowchunk = rowchunk or nrows / 10
            dshape = [0] + [a for a in shape]
            for row0 in range(0, nrows, rowchunk):
                nr = min(rowchunk, nrows - row0)
                dshape[0] = nr
                print("Wrtiting to column  %s (rows %d to %d)" %
                      (colname, row0, row0 + nr - 1))
                tab_spw.putcol(
                    colname,
                    numpy.ones(dshape, dtype=type(init_with)) * init_with,
                    row0, nr)
            tab_spw.close()
    tab.close()

    return 'added'
Пример #14
0
def main(options):

    cI = numpy.complex(0., 1.)

    inms = options.inms
    if inms == '':
        print 'Error: you have to specify an input MS, use -h for help'
        return
    column = options.column
    outcol = options.outcol

    t = pt.table(inms, readonly=False, ack=True)
    if options.back:
        lincol = options.lincol
        if lincol not in t.colnames():
            print 'Adding the output linear polarization column', lincol, 'to', inms
            coldmi = t.getdminfo(column)
            coldmi['NAME'] = lincol
            t.addcols(
                pt.maketabdesc(
                    pt.makearrcoldesc(lincol,
                                      0.,
                                      valuetype='complex',
                                      shape=numpy.array(t.getcell(column,
                                                                  0)).shape)),
                coldmi)

### RVW EDIT 2012
        print 'Reading the input column (circular)', column
        if column not in t.colnames():
            print 'Error: Input column does not exist'
            return

        ### RVW EDIT 2012 Input column with the -c switch
        cirdata = t.getcol(column)
        #cirdata = t.getcol(outcol)
        #print 'SHAPE ARRAY', numpy.shape(cirdata)

        print 'Computing the linear polarization terms...'
        lindata = numpy.transpose(
            numpy.array([
                0.5 * (cirdata[:, :, 0] + cirdata[:, :, 1] + cirdata[:, :, 2] +
                       cirdata[:, :, 3]),
                0.5 * (cI * cirdata[:, :, 0] - cI * cirdata[:, :, 1] +
                       cI * cirdata[:, :, 2] - cI * cirdata[:, :, 3]),
                0.5 * (-cI * cirdata[:, :, 0] - cI * cirdata[:, :, 1] +
                       cI * cirdata[:, :, 2] + cI * cirdata[:, :, 3]),
                0.5 * (cirdata[:, :, 0] - cirdata[:, :, 1] - cirdata[:, :, 2] +
                       cirdata[:, :, 3])
            ]), (1, 2, 0))
        print 'Finishing up...'
        t.putcol(lincol, lindata)
    else:
        if outcol not in t.colnames():
            print 'Adding the output column', outcol, 'to', inms
            coldmi = t.getdminfo(column)
            coldmi['NAME'] = outcol
            t.addcols(
                pt.maketabdesc(
                    pt.makearrcoldesc(outcol,
                                      0.,
                                      valuetype='complex',
                                      shape=numpy.array(t.getcell(column,
                                                                  0)).shape)),
                coldmi)
        print 'Reading the input column (linear)', column
        data = t.getcol(column)
        print 'Computing the output column'
        outdata = numpy.transpose(
            numpy.array([
                0.5 * (data[:, :, 0] - cI * data[:, :, 1] +
                       cI * data[:, :, 2] + data[:, :, 3]),
                0.5 * (data[:, :, 0] + cI * data[:, :, 1] +
                       cI * data[:, :, 2] - data[:, :, 3]),
                0.5 * (data[:, :, 0] - cI * data[:, :, 1] -
                       cI * data[:, :, 2] - data[:, :, 3]),
                0.5 * (data[:, :, 0] + cI * data[:, :, 1] -
                       cI * data[:, :, 2] + data[:, :, 3])
            ]), (1, 2, 0))
        print 'Finishing up...'
        t.putcol(outcol, outdata)
    if options.poltable:
        print 'Updating the POLARIZATION table...'
        tp = pt.table(inms + '/POLARIZATION', readonly=False, ack=True)

        ### RVW EDIT 2012
        if options.back:
            tp.putcol('CORR_TYPE',
                      numpy.array([[9, 10, 11, 12]],
                                  dtype=numpy.int32))  # FROM CIRC-->LIN
        else:
            tp.putcol('CORR_TYPE',
                      numpy.array([[5, 6, 7, 8]],
                                  dtype=numpy.int32))  # FROM LIN-->CIRC
Пример #15
0
        c1 = c + (3 * d * k)
        d1 = d

        print "Adding %s\t%d\t%3.2f\t%3.2f\t%.4f\t%.4f\t%.4f\t%.4f" % \
            (name, epoch, ra, decl, a1, b1, c1, d1)

        # append to standards table
        fc.addrows()
        fc.putcell("Name", fc.nrows() - 1, name)
        fc.putcell("RA_J2000", fc.nrows() - 1, ra)
        fc.putcell("Dec_J2000", fc.nrows() - 1, decl)
        fc.putcell("AltNames", fc.nrows() - 1, np.array([[name]]))

        coeffs = tbls.makearrcoldesc(name + "_coeffs",
                                     None,
                                     ndim=1,
                                     shape=[4],
                                     valuetype="float")
        coefferrs = tbls.makearrcoldesc(name + "_coefferrs",
                                        None,
                                        ndim=1,
                                        shape=[4],
                                        valuetype="float")
        pb.addcols(coeffs)
        pb.addcols(coefferrs)
        pb.putcol(
            name + "_coeffs",
            np.tile(np.array([a1, b1, c1, d1], dtype=np.float32),
                    (pb.nrows(), 1)))
        pb.putcol(
            name + "_coefferrs",
Пример #16
0
def main(options):

	cI = numpy.complex(0.,1.)
	
	inms = options.inms
	if inms == '':
			print 'Error: you have to specify an input MS, use -h for help'
			return
	column = options.column
	outcol = options.outcol
	
	t = pt.table(inms, readonly=False, ack=True)
	if options.back:
		lincol = options.lincol
		if lincol not in t.colnames():
				print 'Adding the output linear polarization column',lincol,'to',inms
				coldmi = t.getdminfo(column)
				coldmi['NAME'] = lincol
				t.addcols(pt.maketabdesc(pt.makearrcoldesc(lincol, 0., valuetype='complex', shape=numpy.array(t.getcell(column,0)).shape)), coldmi)

                ### RVW EDIT 2012   
		print 'Reading the input column (circular)', column
		if column not in t.colnames():
			print 'Error: Input column does not exist'
			return
		
		### RVW EDIT 2012 Input column with the -c switch 
		cirdata = t.getcol(column)
		#cirdata = t.getcol(outcol)
		#print 'SHAPE ARRAY', numpy.shape(cirdata)
		
		print 'Computing the linear polarization terms...'
		lindata = numpy.transpose(numpy.array([
				0.5*(cirdata[:,:,0]+cirdata[:,:,1]+cirdata[:,:,2]+cirdata[:,:,3]),
				0.5*(cI*cirdata[:,:,0]-cI*cirdata[:,:,1]+cI*cirdata[:,:,2]-cI*cirdata[:,:,3]),
				0.5*(-cI*cirdata[:,:,0]-cI*cirdata[:,:,1]+cI*cirdata[:,:,2]+cI*cirdata[:,:,3]),
				0.5*(cirdata[:,:,0]-cirdata[:,:,1]-cirdata[:,:,2]+cirdata[:,:,3])]),
				(1,2,0))
		print 'Finishing up...'
		t.putcol(lincol, lindata)
	else:
		if outcol not in t.colnames():
			print 'Adding the output column',outcol,'to',inms
			coldmi = t.getdminfo(column)
			coldmi['NAME'] = outcol
			t.addcols(pt.maketabdesc(pt.makearrcoldesc(outcol, 0., valuetype='complex', shape=numpy.array(t.getcell(column,0)).shape)), coldmi)
		print 'Reading the input column (linear)', column
		data = t.getcol(column)
		print 'Computing the output column'
		outdata = numpy.transpose(numpy.array([
				0.5*(data[:,:,0]-cI*data[:,:,1]+cI*data[:,:,2]+data[:,:,3]),
				0.5*(data[:,:,0]+cI*data[:,:,1]+cI*data[:,:,2]-data[:,:,3]),
				0.5*(data[:,:,0]-cI*data[:,:,1]-cI*data[:,:,2]-data[:,:,3]),
				0.5*(data[:,:,0]+cI*data[:,:,1]-cI*data[:,:,2]+data[:,:,3])]),
				(1,2,0))
		print 'Finishing up...'
		t.putcol(outcol, outdata)
	if options.poltable:
		print 'Updating the POLARIZATION table...'
		tp = pt.table(inms+'/POLARIZATION',readonly=False,ack=True)
		
		### RVW EDIT 2012
		if options.back:
		   tp.putcol('CORR_TYPE',numpy.array([[9,10,11,12]],dtype=numpy.int32)) # FROM CIRC-->LIN
                else:
		   tp.putcol('CORR_TYPE',numpy.array([[5,6,7,8]],dtype=numpy.int32)) # FROM LIN-->CIRC