processing_components/visibility/base.py
def export_blockvisibility_to_ms(msname, vis_list, source_name=None, ack=False):
    """ Minimal BlockVisibility to MS converter

    The MS format is much more general than the ARL BlockVisibility so we cut many corners. This requires casacore to be
    installed. If not an exception ModuleNotFoundError is raised.

    Write a list of BlockVisibility's to a MS file, split by field and spectral window

    :param msname: File name of MS
    :param vislist: BlockVisibility
    :return:
    """
    try:
        import casacore.tables.tableutil as pt
        from casacore.tables import (makescacoldesc, makearrcoldesc, table, maketabdesc, tableexists, tableiswritable,
                             tableinfo, tablefromascii, tabledelete, makecoldesc, msconcat, removeDerivedMSCal,
                             taql, tablerename, tablecopy, tablecolumn, addDerivedMSCal, removeImagingColumns,
                             addImagingColumns, required_ms_desc, tabledefinehypercolumn, default_ms, makedminfo,
                             default_ms_subtable)
        from processing_components.visibility.msv2fund import Antenna, Stand
    except ModuleNotFoundError:
        raise ModuleNotFoundError("casacore is not installed")

    try:
        from processing_components.visibility import msv2
    except ModuleNotFoundError:
        raise ModuleNotFoundError("cannot import msv2")

    # log.debug("create_blockvisibility_from_ms: %s" % str(tab.info()))
    # Start the table
    tbl = msv2.Ms(msname, ref_time=0, source_name= source_name, if_delete=True)
    if source_name is None:
        source_name = 'ARL'
    for vis in vis_list:
        # Check polarisition
        npol = vis.npol
        nchan = vis.nchan
        nants = vis.nants
        if vis.polarisation_frame.type == 'linear':
            polarization = ['XX','XY','YX','YY']
        elif vis.polarisation_frame.type == 'stokesI':
            polarization = ['XX']
        elif vis.polarisation_frame.type == 'circular':
            polarization = ['RR','RL','LR','LL']
        elif vis.polarisation_frame.type == 'stokesIQUV':
            polarization = ['I','Q','U','V']
        # Current ARL suppots I
        tbl.set_stokes(polarization)
        tbl.set_frequency(vis.frequency,vis.channel_bandwidth)
        n_ant = len(vis.configuration.xyz)

        antennas = []
        names = vis.configuration.names
        mount = vis.configuration.mount
        diameter = vis.configuration.diameter
        xyz = vis.configuration.xyz
        for i in range(len(names)):
            antennas.append(Antenna(i, Stand(names[i], xyz[i, 0], xyz[i, 1], xyz[i, 2])))

        # Set baselines and data
        blList = []

        antennas2 = antennas

        for i in range(0, n_ant - 1):
            for j in range(i + 1, n_ant):
                blList.append((antennas[i], antennas2[j]))

        tbl.set_geometry(vis.configuration, antennas)
        nbaseline = len(blList)
        ntimes = len(vis.data['time'])

        ms_vis = numpy.zeros([ntimes, nbaseline, nchan, npol]).astype('complex')
        ms_uvw = numpy.zeros([ntimes, nbaseline, 3])
        # bv_vis = numpy.zeros([ntimes, nants, nants, nchan, npol]).astype('complex')
        # bv_weight = numpy.zeros([ntimes, nants, nants, nchan, npol])
        # bv_imaging_weight = numpy.zeros([ntimes, nants, nants, nchan, npol])
        # bv_uvw = numpy.zeros([ntimes, nants, nants, 3])
        time = vis.data['time']
        int_time = vis.data['integration_time']
        bv_vis = vis.data['vis']
        bv_uvw = vis.data['uvw']

        # bv_antenna1 = vis.data['antenna1']
        # bv_antenna2 = vis.data['antenna2']

        time_last = time[0]
        time_index = 0
        for row,_ in enumerate(time):
            # MS has shape [row, npol, nchan]
            # BV has shape [ntimes, nants, nants, nchan, npol]
            bl = 0
            for i in range(0, n_ant - 1):
                for j in range(i + 1, n_ant):
                    ms_vis[row, bl,...] = bv_vis[row, j, i, ...]
                    # bv_weight[time_index, antenna2[row], antenna1[row], :, ...] = ms_weight[row, numpy.newaxis, ...]
                    # bv_imaging_weight[time_index, antenna2[row], antenna1[row], :, ...] = ms_weight[row, numpy.newaxis, ...]
                    ms_uvw[row,bl,:] = bv_uvw[row, j, i, :]
                    bl += 1

        # ms_vis = numpy.zeros([ntimes*vis.nants*vis.nants, vis.nchan, vis.npol]).astype('complex')
        # ms_uvw = vis.uvw.reshape(ntimes,-1,3)
        for ntime, time in enumerate(vis.data['time']):
            for ipol, pol in enumerate(polarization):
                if int_time[ntime] is not None:
                    tbl.add_data_set(time, int_time[ntime], blList, ms_vis[ntime, ..., ipol], pol=pol, source=source_name,
                                     phasecentre=vis.phasecentre, uvw=ms_uvw[ntime, :, :])
                else:
                    tbl.add_data_set(time, 0, blList, ms_vis[ntime, ..., ipol], pol=pol,
                                     source=source_name, phasecentre = vis.phasecentre, uvw=ms_uvw[ntime, :, :])
    tbl.write()
 Minimal BlockVisibility to MS converter

    The MS format is much more general than the ARL BlockVisibility so we cut many corners. This requires casacore to be
    installed. If not an exception ModuleNotFoundError is raised.

    Write a list of BlockVisibility's to a MS file, split by field and spectral window

    :param msname: File name of MS
    :param vislist: BlockVisibility
    :return:
    
Minimal BlockVisibility to MS converter
The MS format is much more general than the ARL BlockVisibility so we cut many corners. This requires casacore to be
installed. If not an exception ModuleNotFoundError is raised.

Write a list of BlockVisibility's to a MS file, split by field and spectral window
Minimal BlockVisibility to MS converter The MS format is much more general than the ARL BlockVisibility so we cut many corners . This requires casacore to be installed . If not an exception ModuleNotFoundError is raised . Write a list of BlockVisibility ' s to a MS file split by field and spectral window
def export_blockvisibility_to_ms(msname, vis_list, source_name=None, ack=False):
    try:
        import casacore.tables.tableutil as pt
        from casacore.tables import (makescacoldesc, makearrcoldesc, table, maketabdesc, tableexists, tableiswritable,
                             tableinfo, tablefromascii, tabledelete, makecoldesc, msconcat, removeDerivedMSCal,
                             taql, tablerename, tablecopy, tablecolumn, addDerivedMSCal, removeImagingColumns,
                             addImagingColumns, required_ms_desc, tabledefinehypercolumn, default_ms, makedminfo,
                             default_ms_subtable)
        from processing_components.visibility.msv2fund import Antenna, Stand
    except ModuleNotFoundError:
        raise ModuleNotFoundError("casacore is not installed")
    try:
        from processing_components.visibility import msv2
    except ModuleNotFoundError:
        raise ModuleNotFoundError("cannot import msv2")
    tbl = msv2.Ms(msname, ref_time=0, source_name= source_name, if_delete=True)
    if source_name is None:
        source_name = 'ARL'
    for vis in vis_list:
        npol = vis.npol
        nchan = vis.nchan
        nants = vis.nants
        if vis.polarisation_frame.type == 'linear':
            polarization = ['XX','XY','YX','YY']
        elif vis.polarisation_frame.type == 'stokesI':
            polarization = ['XX']
        elif vis.polarisation_frame.type == 'circular':
            polarization = ['RR','RL','LR','LL']
        elif vis.polarisation_frame.type == 'stokesIQUV':
            polarization = ['I','Q','U','V']
        tbl.set_stokes(polarization)
        tbl.set_frequency(vis.frequency,vis.channel_bandwidth)
        n_ant = len(vis.configuration.xyz)
        antennas = []
        names = vis.configuration.names
        mount = vis.configuration.mount
        diameter = vis.configuration.diameter
        xyz = vis.configuration.xyz
        for i in range(len(names)):
            antennas.append(Antenna(i, Stand(names[i], xyz[i, 0], xyz[i, 1], xyz[i, 2])))
        blList = []
        antennas2 = antennas
        for i in range(0, n_ant - 1):
            for j in range(i + 1, n_ant):
                blList.append((antennas[i], antennas2[j]))
        tbl.set_geometry(vis.configuration, antennas)
        nbaseline = len(blList)
        ntimes = len(vis.data['time'])
        ms_vis = numpy.zeros([ntimes, nbaseline, nchan, npol]).astype('complex')
        ms_uvw = numpy.zeros([ntimes, nbaseline, 3])
        time = vis.data['time']
        int_time = vis.data['integration_time']
        bv_vis = vis.data['vis']
        bv_uvw = vis.data['uvw']
        time_last = time[0]
        time_index = 0
        for row,_ in enumerate(time):
            bl = 0
            for i in range(0, n_ant - 1):
                for j in range(i + 1, n_ant):
                    ms_vis[row, bl,...] = bv_vis[row, j, i, ...]
                    ms_uvw[row,bl,:] = bv_uvw[row, j, i, :]
                    bl += 1
        for ntime, time in enumerate(vis.data['time']):
            for ipol, pol in enumerate(polarization):
                if int_time[ntime] is not None:
                    tbl.add_data_set(time, int_time[ntime], blList, ms_vis[ntime, ..., ipol], pol=pol, source=source_name,
                                     phasecentre=vis.phasecentre, uvw=ms_uvw[ntime, :, :])
                else:
                    tbl.add_data_set(time, 0, blList, ms_vis[ntime, ..., ipol], pol=pol,
                                     source=source_name, phasecentre = vis.phasecentre, uvw=ms_uvw[ntime, :, :])
    tbl.write()
def export_blockvisibility_to_ms ( msname , vis_list , source_name = None , ack = False ) : try : import casacore . tables . tableutil as pt from casacore . tables import ( makescacoldesc , makearrcoldesc , table , maketabdesc , tableexists , tableiswritable , tableinfo , tablefromascii , tabledelete , makecoldesc , msconcat , removeDerivedMSCal , taql , tablerename , tablecopy , tablecolumn , addDerivedMSCal , removeImagingColumns , addImagingColumns , required_ms_desc , tabledefinehypercolumn , default_ms , makedminfo , default_ms_subtable ) from processing_components . visibility . msv2fund import Antenna , Stand except ModuleNotFoundError : raise ModuleNotFoundError ( "casacore is not installed" ) try : from processing_components . visibility import msv2 except ModuleNotFoundError : raise ModuleNotFoundError ( "cannot import msv2" ) tbl = msv2 . Ms ( msname , ref_time = 0 , source_name = source_name , if_delete = True ) if source_name is None : source_name = 'ARL' for vis in vis_list : npol = vis . npol nchan = vis . nchan nants = vis . nants if vis . polarisation_frame . type == 'linear' : polarization = [ 'XX' , 'XY' , 'YX' , 'YY' ] elif vis . polarisation_frame . type == 'stokesI' : polarization = [ 'XX' ] elif vis . polarisation_frame . type == 'circular' : polarization = [ 'RR' , 'RL' , 'LR' , 'LL' ] elif vis . polarisation_frame . type == 'stokesIQUV' : polarization = [ 'I' , 'Q' , 'U' , 'V' ] tbl . set_stokes ( polarization ) tbl . set_frequency ( vis . frequency , vis . channel_bandwidth ) n_ant = len ( vis . configuration . xyz ) antennas = [ ] names = vis . configuration . names mount = vis . configuration . mount diameter = vis . configuration . diameter xyz = vis . configuration . xyz for i in range ( len ( names ) ) : antennas . append ( Antenna ( i , Stand ( names [ i ] , xyz [ i , 0 ] , xyz [ i , 1 ] , xyz [ i , 2 ] ) ) ) blList = [ ] antennas2 = antennas for i in range ( 0 , n_ant - 1 ) : for j in range ( i + 1 , n_ant ) : blList . append ( ( antennas [ i ] , antennas2 [ j ] ) ) tbl . set_geometry ( vis . configuration , antennas ) nbaseline = len ( blList ) ntimes = len ( vis . data [ 'time' ] ) ms_vis = numpy . zeros ( [ ntimes , nbaseline , nchan , npol ] ) . astype ( 'complex' ) ms_uvw = numpy . zeros ( [ ntimes , nbaseline , 3 ] ) time = vis . data [ 'time' ] int_time = vis . data [ 'integration_time' ] bv_vis = vis . data [ 'vis' ] bv_uvw = vis . data [ 'uvw' ] time_last = time [ 0 ] time_index = 0 for row , _ in enumerate ( time ) : bl = 0 for i in range ( 0 , n_ant - 1 ) : for j in range ( i + 1 , n_ant ) : ms_vis [ row , bl , ... ] = bv_vis [ row , j , i , ... ] ms_uvw [ row , bl , : ] = bv_uvw [ row , j , i , : ] bl += 1 for ntime , time in enumerate ( vis . data [ 'time' ] ) : for ipol , pol in enumerate ( polarization ) : if int_time [ ntime ] is not None : tbl . add_data_set ( time , int_time [ ntime ] , blList , ms_vis [ ntime , ... , ipol ] , pol = pol , source = source_name , phasecentre = vis . phasecentre , uvw = ms_uvw [ ntime , : , : ] ) else : tbl . add_data_set ( time , 0 , blList , ms_vis [ ntime , ... , ipol ] , pol = pol , source = source_name , phasecentre = vis . phasecentre , uvw = ms_uvw [ ntime , : , : ] ) tbl . write ( )
Minimal BlockVisibility to MS converter
The MS format is much more general than the ARL BlockVisibility so we cut many corners.
Minimal BlockVisibility to MS converter The MS format is much more general than the ARL BlockVisibility so we cut many corners .
""" Minimal BlockVisibility to MS converter

    The MS format is much more general than the ARL BlockVisibility so we cut many corners. This requires casacore to be
    installed. If not an exception ModuleNotFoundError is raised.

    Write a list of BlockVisibility's to a MS file, split by field and spectral window

    :param msname: File name of MS
    :param vislist: BlockVisibility
    :return:
    """ # log.debug("create_blockvisibility_from_ms: %s" % str(tab.info())) # Start the table # Check polarisition # Current ARL suppots I # Set baselines and data # bv_vis = numpy.zeros([ntimes, nants, nants, nchan, npol]).astype('complex') # bv_weight = numpy.zeros([ntimes, nants, nants, nchan, npol]) # bv_imaging_weight = numpy.zeros([ntimes, nants, nants, nchan, npol]) # bv_uvw = numpy.zeros([ntimes, nants, nants, 3]) # bv_antenna1 = vis.data['antenna1'] # bv_antenna2 = vis.data['antenna2'] # MS has shape [row, npol, nchan] # BV has shape [ntimes, nants, nants, nchan, npol] # bv_weight[time_index, antenna2[row], antenna1[row], :, ...] = ms_weight[row, numpy.newaxis, ...] # bv_imaging_weight[time_index, antenna2[row], antenna1[row], :, ...] = ms_weight[row, numpy.newaxis, ...] # ms_vis = numpy.zeros([ntimes*vis.nants*vis.nants, vis.nchan, vis.npol]).astype('complex') # ms_uvw = vis.uvw.reshape(ntimes,-1,3)
None
msname
File name of MS
File name of MS
vis_list
source_name
ack
vislist
None