processing_components/visibility/base.py
def phaserotate_visibility(vis: Visibility, newphasecentre: SkyCoord, tangent=True, inverse=False) -> Visibility:
    """
    Phase rotate from the current phase centre to a new phase centre

    If tangent is False the uvw are recomputed and the visibility phasecentre is updated.
    Otherwise only the visibility phases are adjusted

    :param vis: Visibility to be rotated
    :param newphasecentre:
    :param tangent: Stay on the same tangent plane? (True)
    :param inverse: Actually do the opposite
    :return: Visibility
    """
    l, m, n = skycoord_to_lmn(newphasecentre, vis.phasecentre)

    # No significant change?
    if numpy.abs(n) < 1e-15:
        return vis

    # Make a new copy
    newvis = copy_visibility(vis)

    if isinstance(vis, Visibility):
        phasor = simulate_point(newvis.uvw, l, m)
        
        if len(newvis.vis.shape) > len(phasor.shape):
            phasor = phasor[:, numpy.newaxis]
        
        if inverse:
            newvis.data['vis'] *= phasor
        else:
            newvis.data['vis'] *= numpy.conj(phasor)
        
        # To rotate UVW, rotate into the global XYZ coordinate system and back. We have the option of
        # staying on the tangent plane or not. If we stay on the tangent then the raster will
        # join smoothly at the edges. If we change the tangent then we will have to reproject to get
        # the results on the same image, in which case overlaps or gaps are difficult to deal with.
        if not tangent:
            if inverse:
                xyz = uvw_to_xyz(vis.data['uvw'], ha=-newvis.phasecentre.ra.rad, dec=newvis.phasecentre.dec.rad)
                newvis.data['uvw'][...] = \
                    xyz_to_uvw(xyz, ha=-newphasecentre.ra.rad, dec=newphasecentre.dec.rad)[...]
            else:
                # This is the original (non-inverse) code
                xyz = uvw_to_xyz(newvis.data['uvw'], ha=-newvis.phasecentre.ra.rad, dec=newvis.phasecentre.dec.rad)
                newvis.data['uvw'][...] = xyz_to_uvw(xyz, ha=-newphasecentre.ra.rad, dec=newphasecentre.dec.rad)[
                    ...]
            newvis.phasecentre = newphasecentre
        return newvis

    elif isinstance(vis, BlockVisibility):
        
        k = numpy.array(vis.frequency) / constants.c.to('m s^-1').value

        uvw = vis.uvw[..., numpy.newaxis] * k
        phasor = numpy.ones_like(vis.vis, dtype='complex')
        _, _, _, nchan, npol = vis.vis.shape
        for chan in range(nchan):
            phasor[:, :, :, chan, :] = simulate_point(uvw[..., chan], l, m)[..., numpy.newaxis]

        if inverse:
            newvis.data['vis'] *= phasor
        else:
            newvis.data['vis'] *= numpy.conj(phasor)
        
        # To rotate UVW, rotate into the global XYZ coordinate system and back. We have the option of
        # staying on the tangent plane or not. If we stay on the tangent then the raster will
        # join smoothly at the edges. If we change the tangent then we will have to reproject to get
        # the results on the same image, in which case overlaps or gaps are difficult to deal with.
        if not tangent:
            # UVW is shape [nants, nants, 3], we want [nants * nants, 3]
            nrows, nants, _, _ = vis.uvw.shape
            uvw_linear = vis.uvw.reshape([nrows * nants * nants, 3])
            if inverse:
                xyz = uvw_to_xyz(uvw_linear, ha=-newvis.phasecentre.ra.rad, dec=newvis.phasecentre.dec.rad)
                uvw_linear = \
                    xyz_to_uvw(xyz, ha=-newphasecentre.ra.rad, dec=newphasecentre.dec.rad)[...]
            else:
                # This is the original (non-inverse) code
                xyz = uvw_to_xyz(uvw_linear, ha=-newvis.phasecentre.ra.rad, dec=newvis.phasecentre.dec.rad)
                uvw_linear = \
                    xyz_to_uvw(xyz, ha=-newphasecentre.ra.rad, dec=newphasecentre.dec.rad)[...]
            newvis.phasecentre = newphasecentre
            newvis.data['uvw'][...] = uvw_linear.reshape([nrows, nants, nants, 3])
        return newvis
    else:
        raise ValueError("vis argument neither Visibility or BlockVisibility")

    Phase rotate from the current phase centre to a new phase centre

    If tangent is False the uvw are recomputed and the visibility phasecentre is updated.
    Otherwise only the visibility phases are adjusted

    :param vis: Visibility to be rotated
    :param newphasecentre:
    :param tangent: Stay on the same tangent plane? (True)
    :param inverse: Actually do the opposite
    :return: Visibility
    
Phase rotate from the current phase centre to a new phase centre
If tangent is False the uvw are recomputed and the visibility phasecentre is updated.
Otherwise only the visibility phases are adjusted
Phase rotate from the current phase centre to a new phase centre If tangent is False the uvw are recomputed and the visibility phasecentre is updated . Otherwise only the visibility phases are adjusted
def phaserotate_visibility(vis: Visibility, newphasecentre: SkyCoord, tangent=True, inverse=False) -> Visibility:
    l, m, n = skycoord_to_lmn(newphasecentre, vis.phasecentre)
    if numpy.abs(n) < 1e-15:
        return vis
    newvis = copy_visibility(vis)
    if isinstance(vis, Visibility):
        phasor = simulate_point(newvis.uvw, l, m)
        if len(newvis.vis.shape) > len(phasor.shape):
            phasor = phasor[:, numpy.newaxis]
        if inverse:
            newvis.data['vis'] *= phasor
        else:
            newvis.data['vis'] *= numpy.conj(phasor)
        if not tangent:
            if inverse:
                xyz = uvw_to_xyz(vis.data['uvw'], ha=-newvis.phasecentre.ra.rad, dec=newvis.phasecentre.dec.rad)
                newvis.data['uvw'][...] = \
                    xyz_to_uvw(xyz, ha=-newphasecentre.ra.rad, dec=newphasecentre.dec.rad)[...]
            else:
                xyz = uvw_to_xyz(newvis.data['uvw'], ha=-newvis.phasecentre.ra.rad, dec=newvis.phasecentre.dec.rad)
                newvis.data['uvw'][...] = xyz_to_uvw(xyz, ha=-newphasecentre.ra.rad, dec=newphasecentre.dec.rad)[
                    ...]
            newvis.phasecentre = newphasecentre
        return newvis
    elif isinstance(vis, BlockVisibility):
        k = numpy.array(vis.frequency) / constants.c.to('m s^-1').value
        uvw = vis.uvw[..., numpy.newaxis] * k
        phasor = numpy.ones_like(vis.vis, dtype='complex')
        _, _, _, nchan, npol = vis.vis.shape
        for chan in range(nchan):
            phasor[:, :, :, chan, :] = simulate_point(uvw[..., chan], l, m)[..., numpy.newaxis]
        if inverse:
            newvis.data['vis'] *= phasor
        else:
            newvis.data['vis'] *= numpy.conj(phasor)
        if not tangent:
            nrows, nants, _, _ = vis.uvw.shape
            uvw_linear = vis.uvw.reshape([nrows * nants * nants, 3])
            if inverse:
                xyz = uvw_to_xyz(uvw_linear, ha=-newvis.phasecentre.ra.rad, dec=newvis.phasecentre.dec.rad)
                uvw_linear = \
                    xyz_to_uvw(xyz, ha=-newphasecentre.ra.rad, dec=newphasecentre.dec.rad)[...]
            else:
                xyz = uvw_to_xyz(uvw_linear, ha=-newvis.phasecentre.ra.rad, dec=newvis.phasecentre.dec.rad)
                uvw_linear = \
                    xyz_to_uvw(xyz, ha=-newphasecentre.ra.rad, dec=newphasecentre.dec.rad)[...]
            newvis.phasecentre = newphasecentre
            newvis.data['uvw'][...] = uvw_linear.reshape([nrows, nants, nants, 3])
        return newvis
    else:
        raise ValueError("vis argument neither Visibility or BlockVisibility")
def phaserotate_visibility ( vis : Visibility , newphasecentre : SkyCoord , tangent = True , inverse = False ) -> Visibility : l , m , n = skycoord_to_lmn ( newphasecentre , vis . phasecentre ) if numpy . abs ( n ) < 1e-15 : return vis newvis = copy_visibility ( vis ) if isinstance ( vis , Visibility ) : phasor = simulate_point ( newvis . uvw , l , m ) if len ( newvis . vis . shape ) > len ( phasor . shape ) : phasor = phasor [ : , numpy . newaxis ] if inverse : newvis . data [ 'vis' ] *= phasor else : newvis . data [ 'vis' ] *= numpy . conj ( phasor ) if not tangent : if inverse : xyz = uvw_to_xyz ( vis . data [ 'uvw' ] , ha = - newvis . phasecentre . ra . rad , dec = newvis . phasecentre . dec . rad ) newvis . data [ 'uvw' ] [ ... ] = xyz_to_uvw ( xyz , ha = - newphasecentre . ra . rad , dec = newphasecentre . dec . rad ) [ ... ] else : xyz = uvw_to_xyz ( newvis . data [ 'uvw' ] , ha = - newvis . phasecentre . ra . rad , dec = newvis . phasecentre . dec . rad ) newvis . data [ 'uvw' ] [ ... ] = xyz_to_uvw ( xyz , ha = - newphasecentre . ra . rad , dec = newphasecentre . dec . rad ) [ ... ] newvis . phasecentre = newphasecentre return newvis elif isinstance ( vis , BlockVisibility ) : k = numpy . array ( vis . frequency ) / constants . c . to ( 'm s^-1' ) . value uvw = vis . uvw [ ... , numpy . newaxis ] * k phasor = numpy . ones_like ( vis . vis , dtype = 'complex' ) _ , _ , _ , nchan , npol = vis . vis . shape for chan in range ( nchan ) : phasor [ : , : , : , chan , : ] = simulate_point ( uvw [ ... , chan ] , l , m ) [ ... , numpy . newaxis ] if inverse : newvis . data [ 'vis' ] *= phasor else : newvis . data [ 'vis' ] *= numpy . conj ( phasor ) if not tangent : nrows , nants , _ , _ = vis . uvw . shape uvw_linear = vis . uvw . reshape ( [ nrows * nants * nants , 3 ] ) if inverse : xyz = uvw_to_xyz ( uvw_linear , ha = - newvis . phasecentre . ra . rad , dec = newvis . phasecentre . dec . rad ) uvw_linear = xyz_to_uvw ( xyz , ha = - newphasecentre . ra . rad , dec = newphasecentre . dec . rad ) [ ... ] else : xyz = uvw_to_xyz ( uvw_linear , ha = - newvis . phasecentre . ra . rad , dec = newvis . phasecentre . dec . rad ) uvw_linear = xyz_to_uvw ( xyz , ha = - newphasecentre . ra . rad , dec = newphasecentre . dec . rad ) [ ... ] newvis . phasecentre = newphasecentre newvis . data [ 'uvw' ] [ ... ] = uvw_linear . reshape ( [ nrows , nants , nants , 3 ] ) return newvis else : raise ValueError ( "vis argument neither Visibility or BlockVisibility" )
Phase rotate from the current phase centre to a new phase centre
If tangent is False the uvw are recomputed and the visibility phasecentre is updated.
Phase rotate from the current phase centre to a new phase centre If tangent is False the uvw are recomputed and the visibility phasecentre is updated .
"""
    Phase rotate from the current phase centre to a new phase centre

    If tangent is False the uvw are recomputed and the visibility phasecentre is updated.
    Otherwise only the visibility phases are adjusted

    :param vis: Visibility to be rotated
    :param newphasecentre:
    :param tangent: Stay on the same tangent plane? (True)
    :param inverse: Actually do the opposite
    :return: Visibility
    """ # No significant change? # Make a new copy # To rotate UVW, rotate into the global XYZ coordinate system and back. We have the option of # staying on the tangent plane or not. If we stay on the tangent then the raster will # join smoothly at the edges. If we change the tangent then we will have to reproject to get # the results on the same image, in which case overlaps or gaps are difficult to deal with. # This is the original (non-inverse) code # To rotate UVW, rotate into the global XYZ coordinate system and back. We have the option of # staying on the tangent plane or not. If we stay on the tangent then the raster will # join smoothly at the edges. If we change the tangent then we will have to reproject to get # the results on the same image, in which case overlaps or gaps are difficult to deal with. # UVW is shape [nants, nants, 3], we want [nants * nants, 3] # This is the original (non-inverse) code
None
vis
Visibility
Visibility to be rotated
Visibility to be rotated
newphasecentre
SkyCoord
None
tangent
Stay on the same tangent plane. (True)
Stay on the same tangent plane . ( True )
inverse
Actually do the opposite
Actually do the opposite