processing_components/imaging/ng.py
def predict_ng(bvis: Union[BlockVisibility, Visibility], model: Image, **kwargs) -> \
            Union[BlockVisibility, Visibility]:
        """ Predict using convolutional degridding.
        
        Nifty-gridder version. https://gitlab.mpcdf.mpg.de/ift/nifty_gridder
    
        :param bvis: BlockVisibility to be predicted
        :param model: model image
        :return: resulting BlockVisibility (in place works)
        """

        assert isinstance(bvis, BlockVisibility), bvis
        

        if model is None:
            return bvis
        
        nthreads = get_parameter(kwargs, "threads", 4)
        epsilon = get_parameter(kwargs, "epsilon", 1e-12)
        do_wstacking = get_parameter(kwargs, "do_wstacking", True)
        verbosity = get_parameter(kwargs, "verbosity", 2)
        
        newbvis = copy_visibility(bvis, zero=True)
        
        # Extracting data from BlockVisibility
        freq = bvis.frequency  # frequency, Hz
        nrows, nants, _, vnchan, vnpol = bvis.vis.shape
        
        uvw = newbvis.data['uvw'].reshape([nrows * nants * nants, 3])
        vis = newbvis.data['vis'].reshape([nrows * nants * nants, vnchan, vnpol])
        
        vis[...] = 0.0 + 0.0j  # Make all vis data equal to 0 +0j
        
        # Get the image properties
        m_nchan, m_npol, ny, nx = model.data.shape
        # Check if the number of frequency channels matches in bvis and a model
        #        assert (m_nchan == v_nchan)
        assert (m_npol == vnpol)
        
        fuvw = uvw.copy()
        # We need to flip the u and w axes. The flip in w is equivalent to the conjugation of the
        # convolution function grid_visibility to griddata
        fuvw[:, 0] *= -1.0
        fuvw[:, 2] *= -1.0
        
        # Find out the image size/resolution
        pixsize = numpy.abs(numpy.radians(model.wcs.wcs.cdelt[0]))
        
        # Make de-gridding over a frequency range and pol fields
        vis_to_im = numpy.round(model.wcs.sub([4]).wcs_world2pix(freq, 0)[0]).astype('int')
        for vchan in range(vnchan):
            imchan = vis_to_im[vchan]
            for vpol in range(vnpol):
                vis[..., vchan, vpol] = ng.dirty2ms(fuvw.astype(numpy.float64),
                                    freq[vchan:vchan + 1].astype(numpy.float64),
                                    model.data[imchan, vpol, :, :].T.astype(numpy.float64),
                                    pixsize_x=pixsize,
                                    pixsize_y=pixsize,
                                    epsilon=epsilon,
                                    do_wstacking=do_wstacking,
                                    nthreads=nthreads,
                                    verbosity=verbosity)[:,0]
        
        vis = convert_pol_frame(vis, model.polarisation_frame, bvis.polarisation_frame, polaxis=2)
        newbvis.data['vis'] = vis.reshape([nrows, nants, nants, vnchan, vnpol])

        # Now we can shift the visibility from the image frame to the original visibility frame
        return shift_vis_to_image(newbvis, model, tangent=True, inverse=True)
 Predict using convolutional degridding.
        
        Nifty-gridder version. https://gitlab.mpcdf.mpg.de/ift/nifty_gridder
    
        :param bvis: BlockVisibility to be predicted
        :param model: model image
        :return: resulting BlockVisibility (in place works)
        
Predict using convolutional degridding.
Nifty-gridder version.
Predict using convolutional degridding . Nifty - gridder version .
def predict_ng(bvis: Union[BlockVisibility, Visibility], model: Image, **kwargs) -> \
            Union[BlockVisibility, Visibility]:
        assert isinstance(bvis, BlockVisibility), bvis
        if model is None:
            return bvis
        nthreads = get_parameter(kwargs, "threads", 4)
        epsilon = get_parameter(kwargs, "epsilon", 1e-12)
        do_wstacking = get_parameter(kwargs, "do_wstacking", True)
        verbosity = get_parameter(kwargs, "verbosity", 2)
        newbvis = copy_visibility(bvis, zero=True)
        freq = bvis.frequency  
        nrows, nants, _, vnchan, vnpol = bvis.vis.shape
        uvw = newbvis.data['uvw'].reshape([nrows * nants * nants, 3])
        vis = newbvis.data['vis'].reshape([nrows * nants * nants, vnchan, vnpol])
        vis[...] = 0.0 + 0.0j  
        m_nchan, m_npol, ny, nx = model.data.shape
        assert (m_npol == vnpol)
        fuvw = uvw.copy()
        fuvw[:, 0] *= -1.0
        fuvw[:, 2] *= -1.0
        pixsize = numpy.abs(numpy.radians(model.wcs.wcs.cdelt[0]))
        vis_to_im = numpy.round(model.wcs.sub([4]).wcs_world2pix(freq, 0)[0]).astype('int')
        for vchan in range(vnchan):
            imchan = vis_to_im[vchan]
            for vpol in range(vnpol):
                vis[..., vchan, vpol] = ng.dirty2ms(fuvw.astype(numpy.float64),
                                    freq[vchan:vchan + 1].astype(numpy.float64),
                                    model.data[imchan, vpol, :, :].T.astype(numpy.float64),
                                    pixsize_x=pixsize,
                                    pixsize_y=pixsize,
                                    epsilon=epsilon,
                                    do_wstacking=do_wstacking,
                                    nthreads=nthreads,
                                    verbosity=verbosity)[:,0]
        vis = convert_pol_frame(vis, model.polarisation_frame, bvis.polarisation_frame, polaxis=2)
        newbvis.data['vis'] = vis.reshape([nrows, nants, nants, vnchan, vnpol])
        return shift_vis_to_image(newbvis, model, tangent=True, inverse=True)
def predict_ng ( bvis : Union [ BlockVisibility , Visibility ] , model : Image , ** kwargs ) -> Union [ BlockVisibility , Visibility ] : assert isinstance ( bvis , BlockVisibility ) , bvis if model is None : return bvis nthreads = get_parameter ( kwargs , "threads" , 4 ) epsilon = get_parameter ( kwargs , "epsilon" , 1e-12 ) do_wstacking = get_parameter ( kwargs , "do_wstacking" , True ) verbosity = get_parameter ( kwargs , "verbosity" , 2 ) newbvis = copy_visibility ( bvis , zero = True ) freq = bvis . frequency nrows , nants , _ , vnchan , vnpol = bvis . vis . shape uvw = newbvis . data [ 'uvw' ] . reshape ( [ nrows * nants * nants , 3 ] ) vis = newbvis . data [ 'vis' ] . reshape ( [ nrows * nants * nants , vnchan , vnpol ] ) vis [ ... ] = 0.0 + 0.0j m_nchan , m_npol , ny , nx = model . data . shape assert ( m_npol == vnpol ) fuvw = uvw . copy ( ) fuvw [ : , 0 ] *= - 1.0 fuvw [ : , 2 ] *= - 1.0 pixsize = numpy . abs ( numpy . radians ( model . wcs . wcs . cdelt [ 0 ] ) ) vis_to_im = numpy . round ( model . wcs . sub ( [ 4 ] ) . wcs_world2pix ( freq , 0 ) [ 0 ] ) . astype ( 'int' ) for vchan in range ( vnchan ) : imchan = vis_to_im [ vchan ] for vpol in range ( vnpol ) : vis [ ... , vchan , vpol ] = ng . dirty2ms ( fuvw . astype ( numpy . float64 ) , freq [ vchan : vchan + 1 ] . astype ( numpy . float64 ) , model . data [ imchan , vpol , : , : ] . T . astype ( numpy . float64 ) , pixsize_x = pixsize , pixsize_y = pixsize , epsilon = epsilon , do_wstacking = do_wstacking , nthreads = nthreads , verbosity = verbosity ) [ : , 0 ] vis = convert_pol_frame ( vis , model . polarisation_frame , bvis . polarisation_frame , polaxis = 2 ) newbvis . data [ 'vis' ] = vis . reshape ( [ nrows , nants , nants , vnchan , vnpol ] ) return shift_vis_to_image ( newbvis , model , tangent = True , inverse = True )
Predict using convolutional degridding.
Predict using convolutional degridding .
""" Predict using convolutional degridding.
        
        Nifty-gridder version. https://gitlab.mpcdf.mpg.de/ift/nifty_gridder
    
        :param bvis: BlockVisibility to be predicted
        :param model: model image
        :return: resulting BlockVisibility (in place works)
        """ # Extracting data from BlockVisibility # frequency, Hz # Make all vis data equal to 0 +0j # Get the image properties # Check if the number of frequency channels matches in bvis and a model #        assert (m_nchan == v_nchan) # We need to flip the u and w axes. The flip in w is equivalent to the conjugation of the # convolution function grid_visibility to griddata # Find out the image size/resolution # Make de-gridding over a frequency range and pol fields # Now we can shift the visibility from the image frame to the original visibility frame
resulting BlockVisibility (in place works)
resulting BlockVisibility ( in place works )
bvis
Union[BlockVisibility, Visibility]
BlockVisibility to be predicted
BlockVisibility to be predicted
model
Image
None