def predict_skycomponent_visibility_old(vis: Visibility, sc: Union[Skycomponent, List[Skycomponent]]) -> Visibility:
    """Predict the visibility from a Skycomponent, add to existing visibility, for Visibility

    :param vis: Visibility
    :param sc: Skycomponent or list of SkyComponents
    :return: Visibility
    """
    assert isinstance(vis, Visibility), "vis is not a Visibility: %r" % vis
    
    if not isinstance(sc, collections.Iterable):
        sc = [sc]
    
    _, im_nchan = list(get_frequency_map(vis, None))
    npol = vis.polarisation_frame.npol
    
    for comp in sc:
        
        assert_same_chan_pol(vis, comp)
        
        l, m, n = skycoord_to_lmn(comp.direction, vis.phasecentre)
        phasor = simulate_point(vis.uvw, l, m)
        for ivis in range(vis.nvis):
            for pol in range(npol):
                vis.data['vis'][ivis, pol] += comp.flux[im_nchan[ivis], pol] * phasor[ivis]
            
            # coords = phasor, ichan
            # for pol in range(npol):
            #     vis.data['vis'][:,pol] += [comp.flux[ic, pol] * p for p, ic in zip(*coords)]
    
    return vis
示例#2
0
def predict_skycomponent_visibility(
        vis: Union[Visibility, BlockVisibility],
        sc: Union[Skycomponent, List[Skycomponent]]) -> Visibility:
    """Predict the visibility from a Skycomponent, add to existing visibility, for Visibility or BlockVisibility

    :param vis: Visibility or BlockVisibility
    :param sc: Skycomponent or list of SkyComponents
    :return: Visibility or BlockVisibility
    """
    if not isinstance(sc, collections.Iterable):
        sc = [sc]

    if isinstance(vis, Visibility):

        _, im_nchan = list(get_frequency_map(vis, None))
        npol = vis.polarisation_frame.npol

        for comp in sc:

            assert_same_chan_pol(vis, comp)

            l, m, n = skycoord_to_lmn(comp.direction, vis.phasecentre)
            phasor = simulate_point(vis.uvw, l, m)
            for ivis in range(vis.nvis):
                for pol in range(npol):
                    vis.data['vis'][ivis, pol] += comp.flux[im_nchan[ivis],
                                                            pol] * phasor[ivis]

    elif isinstance(vis, BlockVisibility):

        nchan = vis.nchan
        npol = vis.npol

        k = numpy.array(vis.frequency) / constants.c.to('m/s').value

        for comp in sc:
            assert_same_chan_pol(vis, comp)

            flux = comp.flux
            if comp.polarisation_frame != vis.polarisation_frame:
                flux = convert_pol_frame(flux, comp.polarisation_frame,
                                         vis.polarisation_frame)

            l, m, n = skycoord_to_lmn(comp.direction, vis.phasecentre)
            for chan in range(nchan):
                phasor = simulate_point(vis.uvw * k[chan], l, m)
                for pol in range(npol):
                    vis.data['vis'][..., chan,
                                    pol] += flux[chan, pol] * phasor[...]

    return vis
示例#3
0
def apply_beam_to_skycomponent(sc: Union[Skycomponent, List[Skycomponent]], beam: Image, flux_limit=0.0) \
        -> Union[Skycomponent, List[Skycomponent]]:
    """ Insert a Skycomponent into an image
    
    :param beam:
    :param sc: SkyComponent or list of SkyComponents
    :param flux_limit: flux limit on input
    :return: List of skycomponents
    """
    assert isinstance(beam, Image)
    single = not isinstance(sc, collections.Iterable)

    if single:
        sc = [sc]

    nchan, npol, ny, nx = beam.shape

    log.debug('apply_beam_to_skycomponent: Processing %d components' %
              (len(sc)))

    newsc = []
    total_flux = numpy.zeros([nchan, npol])
    for comp in sc:

        assert comp.shape == 'Point', "Cannot handle shape %s" % comp.shape

        assert_same_chan_pol(beam, comp)

        pixloc = skycoord_to_pixel(comp.direction, beam.wcs, 1, 'wcs')
        if not numpy.isnan(pixloc).any():
            x, y = int(round(float(pixloc[0]))), int(round(float(pixloc[1])))
            if x >= 0 and x < nx and y >= 0 and y < ny:
                comp.flux[:, :] *= beam.data[:, :, y, x]
                #                if comp.flux[:, :].any() > flux_limit:
                if comp.flux[0, 0] > flux_limit:
                    total_flux += comp.flux
                    newsc.append(
                        Skycomponent(
                            comp.direction,
                            comp.frequency,
                            comp.name,
                            comp.flux,
                            shape=comp.shape,
                            polarisation_frame=comp.polarisation_frame))

    log.debug('apply_beam_to_skycomponent: %d components with total flux %s' %
              (len(newsc), total_flux))
    if single:
        return newsc[0]
    else:
        return newsc
def insert_skycomponent(im: Image, sc: Union[Skycomponent, List[Skycomponent]], insert_method='Nearest',
                        bandwidth=1.0, support=8) -> Image:
    """ Insert a Skycomponent into an image
    :param params:
    :param im:
    :param sc: SkyComponent or list of SkyComponents
    :param insert_method: '' | 'Sinc' | 'Lanczos'
    :param bandwidth: Fractional of uv plane to optimise over (1.0)
    :param support: Support of kernel (7)
    :return: image
    """
    
    assert isinstance(im, Image)
    
    support = int(support / bandwidth)
    
    nchan, npol, ny, nx = im.data.shape
    
    if not isinstance(sc, collections.Iterable):
        sc = [sc]
    
    log.debug("insert_skycomponent: Using insert method %s" % insert_method)
    
    for comp in sc:
        
        assert comp.shape == 'Point', "Cannot handle shape %s" % comp.shape
        
        assert_same_chan_pol(im, comp)
        pixloc = skycoord_to_pixel(comp.direction, im.wcs, origin=0, mode='wcs')
        if insert_method == "Lanczos":
            insert_array(im.data, pixloc[0], pixloc[1], comp.flux, bandwidth, support,
                         insert_function=insert_function_L)
        elif insert_method == "Sinc":
            insert_array(im.data, pixloc[0], pixloc[1], comp.flux, bandwidth, support,
                         insert_function=insert_function_sinc)
        elif insert_method == "PSWF":
            insert_array(im.data, pixloc[0], pixloc[1], comp.flux, bandwidth, support,
                         insert_function=insert_function_pswf)
        else:
            insert_method = 'Nearest'
            y, x = numpy.round(pixloc[1]).astype('int'), numpy.round(pixloc[0]).astype('int')
            if x >= 0 and x < nx and y >= 0 and y < ny:
                im.data[:, :, y, x] += comp.flux
    
    return im
示例#5
0
文件: base.py 项目: Luffky/arl_backup
def predict_skycomponent_blockvisibility(vis: BlockVisibility,
                                         sc: Union[Skycomponent,
                                                   List[Skycomponent]],
                                         **kwargs) -> BlockVisibility:
    """Predict the visibility from a Skycomponent, add to existing visibility, for BlockVisibility

    :param vis: BlockVisibility
    :param sc: Skycomponent or list of SkyComponents
    :param spectral_mode: {mfs|channel} (channel)
    :return: BlockVisibility
    """
    assert type(
        vis) is BlockVisibility, "vis is not a BlockVisibility: %r" % vis

    if not isinstance(sc, collections.Iterable):
        sc = [sc]

    nchan = vis.nchan
    npol = vis.npol

    if not isinstance(sc, collections.Iterable):
        sc = [sc]

    k = vis.frequency / constants.c.to('m/s').value

    for comp in sc:

        assert_same_chan_pol(vis, comp)

        flux = comp.flux
        if comp.polarisation_frame != vis.polarisation_frame:
            flux = convert_pol_frame(flux, comp.polarisation_frame,
                                     vis.polarisation_frame)

        l, m, n = skycoord_to_lmn(comp.direction, vis.phasecentre)
        for chan in range(nchan):
            phasor = simulate_point(vis.uvw * k[chan], l, m)
            for pol in range(npol):
                vis.data['vis'][..., chan,
                                pol] += flux[chan, pol] * phasor[...]

    return vis