示例#1
0
def convert_blockvisibility_to_visibility(vis: BlockVisibility) -> Visibility:
    """ Convert the BlockVisibility data with no coalescence

    :param vis: BlockVisibility to be converted
    :return: Visibility with  cindex and blockvis filled in
    """

    assert isinstance(
        vis, BlockVisibility), "vis is not a BlockVisibility: %r" % vis

    cvis, cuvw, cwts, ctime, cfrequency, cchannel_bandwidth, ca1, ca2, cintegration_time, cindex \
        = convert_blocks(vis.data['vis'], vis.data['uvw'], vis.data['weight'], vis.time, vis.integration_time,
                         vis.frequency, vis.channel_bandwidth)
    cimwt = numpy.ones(cvis.shape)
    converted_vis = Visibility(uvw=cuvw,
                               time=ctime,
                               frequency=cfrequency,
                               channel_bandwidth=cchannel_bandwidth,
                               phasecentre=vis.phasecentre,
                               antenna1=ca1,
                               antenna2=ca2,
                               vis=cvis,
                               weight=cwts,
                               imaging_weight=cimwt,
                               configuration=vis.configuration,
                               integration_time=cintegration_time,
                               polarisation_frame=vis.polarisation_frame,
                               cindex=cindex,
                               blockvis=vis)

    log.debug('convert_visibility: Original %s, converted %s' %
              (vis_summary(vis), vis_summary(converted_vis)))

    return converted_vis
示例#2
0
def coalesce_visibility(vis: BlockVisibility, **kwargs) -> Visibility:
    """ Coalesce the BlockVisibility data. The output format is a Visibility, as needed for imaging

    Coalesce by baseline-dependent averaging (optional). The number of integrations averaged goes as the ratio of the
    maximum possible baseline length to that for this baseline. This number can be scaled by coalescence_factor and
    limited by max_coalescence.
    
    When faceting, the coalescence factors should be roughly the same as the number of facets on one axis.

    If coalescence_factor=0.0 then just a format conversion is done

    :param vis: BlockVisibility to be coalesced
    :return: Coalesced visibility with  cindex and blockvis filled in
    """
    # 将blockvisibility合并为一个visibility
    assert type(
        vis) is BlockVisibility, "vis is not a BlockVisibility: %r" % vis

    time_coal = get_parameter(kwargs, 'time_coal', 0.0)
    max_time_coal = get_parameter(kwargs, 'max_time_coal', 100)
    frequency_coal = get_parameter(kwargs, 'frequency_coal', 0.0)
    max_frequency_coal = get_parameter(kwargs, 'max_frequency_coal', 100)

    if time_coal == 0.0 and frequency_coal == 0.0:
        # 若time和frequency的合并率均为0,则只做一个简单的blockvisibility到visibility的变换
        return convert_blockvisibility_to_visibility((vis))
    # 否则使用average_in_blocks做一系列较为复杂的合并变换
    cvis, cuvw, cwts, ctime, cfrequency, cchannel_bandwidth, ca1, ca2, cintegration_time, cindex \
        = average_in_blocks(vis.data['vis'], vis.data['uvw'], vis.data['weight'], vis.time, vis.integration_time,
                            vis.frequency, vis.channel_bandwidth, time_coal, max_time_coal,
                            frequency_coal, max_frequency_coal)
    cimwt = numpy.ones(cvis.shape)
    coalesced_vis = Visibility(uvw=cuvw,
                               time=ctime,
                               frequency=cfrequency,
                               channel_bandwidth=cchannel_bandwidth,
                               phasecentre=vis.phasecentre,
                               antenna1=ca1,
                               antenna2=ca2,
                               vis=cvis,
                               weight=cwts,
                               imaging_weight=cimwt,
                               configuration=vis.configuration,
                               integration_time=cintegration_time,
                               polarisation_frame=vis.polarisation_frame,
                               cindex=cindex,
                               blockvis=vis)

    log.debug(
        'coalesce_visibility: Created new Visibility for coalesced data, coalescence factors (t,f) = (%.3f,%.3f)'
        % (time_coal, frequency_coal))
    log.debug('coalesce_visibility: Maximum coalescence (t,f) = (%d, %d)' %
              (max_time_coal, max_frequency_coal))
    log.debug('coalesce_visibility: Original %s, coalesced %s' %
              (vis_summary(vis), vis_summary(coalesced_vis)))

    return coalesced_vis
示例#3
0
def decoalesce_visibility(vis: Visibility, overwrite=False) -> BlockVisibility:
    """ Decoalesce the visibilities to the original values (opposite of coalesce_visibility)
    
    This relies upon the block vis and the index being part of the vis.
    
    'uv': Needs the original image used in coalesce_visibility
    'tb': Needs the index generated by coalesce_visibility

    :param vis: (Coalesced visibility)
    :return: BlockVisibility with vis and weight columns overwritten
    """
    # 去合并,元数据不变,vis按照cindex填入
    assert type(vis) is Visibility, "vis is not a Visibility: %r" % vis
    assert type(vis.blockvis) is BlockVisibility, "No blockvisibility in vis"
    assert vis.cindex is not None, "No reverse index in Visibility"

    if overwrite:
        log.debug(
            'decoalesce_visibility: Created new Visibility for decoalesced data'
        )
        decomp_vis = copy_visibility(vis.blockvis)
    else:
        log.debug(
            'decoalesce_visibility: Filled decoalesced data into template')
        decomp_vis = vis.blockvis

    vshape = decomp_vis.data['vis'].shape

    npol = vshape[-1]
    dvis = numpy.zeros(vshape, dtype='complex')
    assert numpy.max(vis.cindex) < dvis.size
    # print(vis.cindex)
    # TODO 感觉此处逻辑有误
    # for i in range(dvis.size // npol):
    #     decomp_vis.data['vis'].flat[i:i + npol] = vis.data['vis'][vis.cindex[i]]

    # 修改后
    for i in range(dvis.size // npol):
        decomp_vis.data['vis'].flat[i * npol:i * npol +
                                    npol] = vis.data['vis'][vis.cindex[i]]

    log.debug('decoalesce_visibility: Coalesced %s, decoalesced %s' %
              (vis_summary(vis), vis_summary(decomp_vis)))

    return decomp_vis
def decoalesce_visibility(vis: Visibility,
                          overwrite=False,
                          **kwargs) -> BlockVisibility:
    """ Decoalesce the visibilities to the original values (opposite of coalesce_visibility)

    This relies upon the block vis and the index being part of the vis. Needs the index generated by coalesce_visibility

    :param vis: (Coalesced visibility)
    :return: BlockVisibility with vis and weight columns overwritten
    """

    assert isinstance(vis, Visibility), "vis is not a Visibility: %r" % vis
    assert isinstance(vis.blockvis,
                      BlockVisibility), "No blockvisibility in vis %r" % vis
    assert vis.cindex is not None, "No reverse index in Visibility %r" % vis

    if overwrite:
        log.debug(
            'decoalesce_visibility: Created new Visibility for decoalesced data'
        )
        decomp_vis = copy_visibility(vis.blockvis)
    else:
        log.debug(
            'decoalesce_visibility: Filled decoalesced data into template')
        decomp_vis = vis.blockvis

    vshape = decomp_vis.data['vis'].shape

    npol = vshape[-1]
    dvis = numpy.zeros(vshape, dtype='complex')
    assert numpy.max(vis.cindex) < dvis.size
    assert numpy.max(
        vis.cindex
    ) < vis.vis.shape[0], "Incorrect template used in decoalescing"
    for i in range(dvis.size // npol):
        decomp_vis.data['vis'].flat[i:i +
                                    npol] = vis.data['vis'][vis.cindex[i]]

    log.debug('decoalesce_visibility: Coalesced %s, decoalesced %s' %
              (vis_summary(vis), vis_summary(decomp_vis)))

    return decomp_vis