processing_components/imaging/ng.py
def invert_ng(bvis: BlockVisibility, model: Image, dopsf: bool = False, normalize: bool = True,
                  **kwargs) -> (Image, numpy.ndarray):
        """ Invert using nifty-gridder module
        
        https://gitlab.mpcdf.mpg.de/ift/nifty_gridder
    
        Use the image im as a template. Do PSF in a separate call.
    
        This is at the bottom of the layering i.e. all transforms are eventually expressed in terms
        of this function. . Any shifting needed is performed here.
    
        :param bvis: BlockVisibility to be inverted
        :param im: image template (not changed)
        :param normalize: Normalize by the sum of weights (True)
        :return: (resulting image, sum of the weights for each frequency and polarization)
    
        """
        
        assert isinstance(bvis, BlockVisibility), bvis

        im = copy_image(model)

        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", 0)
        
        sbvis = copy_visibility(bvis)
        sbvis = shift_vis_to_image(sbvis, im, tangent=True, inverse=False)

        vis = bvis.vis
        
        freq = sbvis.frequency  # frequency, Hz
        
        nrows, nants, _, vnchan, vnpol = vis.shape
        uvw = sbvis.uvw.reshape([nrows * nants * nants, 3])
        ms = vis.reshape([nrows * nants * nants, vnchan, vnpol])
        wgt = sbvis.imaging_weight.reshape([nrows * nants * nants, vnchan, vnpol])
        
        if dopsf:
            ms[...] = 1.0 + 0.0j
        
        if epsilon > 5.0e-6:
            ms = ms.astype("c8")
            wgt = wgt.astype("f4")
        
        # Find out the image size/resolution
        npixdirty = im.nwidth
        pixsize = numpy.abs(numpy.radians(im.wcs.wcs.cdelt[0]))
        
        fuvw = uvw.copy()
        # We need to flip the u and w axes.
        fuvw[:, 0] *= -1.0
        fuvw[:, 2] *= -1.0
        
        nchan, npol, ny, nx = im.shape
        im.data[...] = 0.0
        sumwt = numpy.zeros([nchan, npol])
        
        ms = convert_pol_frame(ms, bvis.polarisation_frame, im.polarisation_frame, polaxis=2)
        # There's a latent problem here with the weights.
        # wgt = numpy.real(convert_pol_frame(wgt, bvis.polarisation_frame, im.polarisation_frame, polaxis=2))

        # Set up the conversion from visibility channels to image channels
        vis_to_im = numpy.round(model.wcs.sub([4]).wcs_world2pix(freq, 0)[0]).astype('int')
        for vchan in range(vnchan):
            ichan = vis_to_im[vchan]
            for pol in range(npol):
                # Nifty gridder likes to receive contiguous arrays
                ms_1d = numpy.array([ms[row, vchan:vchan+1, pol] for row in range(nrows * nants * nants)], dtype='complex')
                ms_1d.reshape([ms_1d.shape[0], 1])
                wgt_1d = numpy.array([wgt[row, vchan:vchan+1, pol] for row in range(nrows * nants * nants)])
                wgt_1d.reshape([wgt_1d.shape[0], 1])
                dirty = ng.ms2dirty(
                    fuvw, freq[vchan:vchan+1], ms_1d, wgt_1d,
                    npixdirty, npixdirty, pixsize, pixsize, epsilon, do_wstacking=do_wstacking,
                    nthreads=nthreads, verbosity=verbosity)
                sumwt[ichan, pol] += numpy.sum(wgt[:, vchan, pol])
                im.data[ichan, pol] += dirty.T

        if normalize:
            im = normalize_sumwt(im, sumwt)


        return im, sumwt
 Invert using nifty-gridder module
        
        https://gitlab.mpcdf.mpg.de/ift/nifty_gridder
    
        Use the image im as a template. Do PSF in a separate call.
    
        This is at the bottom of the layering i.e. all transforms are eventually expressed in terms
        of this function. . Any shifting needed is performed here.
    
        :param bvis: BlockVisibility to be inverted
        :param im: image template (not changed)
        :param normalize: Normalize by the sum of weights (True)
        :return: (resulting image, sum of the weights for each frequency and polarization)
    
        


Use the image im as a template. Do PSF in a separate call.

This is at the bottom of the layering i.e. all transforms are eventually expressed in terms
of this function.
Use the image im as a template . Do PSF in a separate call . This is at the bottom of the layering i . e . all transforms are eventually expressed in terms of this function .
def invert_ng(bvis: BlockVisibility, model: Image, dopsf: bool = False, normalize: bool = True,
                  **kwargs) -> (Image, numpy.ndarray):
        assert isinstance(bvis, BlockVisibility), bvis
        im = copy_image(model)
        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", 0)
        sbvis = copy_visibility(bvis)
        sbvis = shift_vis_to_image(sbvis, im, tangent=True, inverse=False)
        vis = bvis.vis
        freq = sbvis.frequency  
        nrows, nants, _, vnchan, vnpol = vis.shape
        uvw = sbvis.uvw.reshape([nrows * nants * nants, 3])
        ms = vis.reshape([nrows * nants * nants, vnchan, vnpol])
        wgt = sbvis.imaging_weight.reshape([nrows * nants * nants, vnchan, vnpol])
        if dopsf:
            ms[...] = 1.0 + 0.0j
        if epsilon > 5.0e-6:
            ms = ms.astype("c8")
            wgt = wgt.astype("f4")
        npixdirty = im.nwidth
        pixsize = numpy.abs(numpy.radians(im.wcs.wcs.cdelt[0]))
        fuvw = uvw.copy()
        fuvw[:, 0] *= -1.0
        fuvw[:, 2] *= -1.0
        nchan, npol, ny, nx = im.shape
        im.data[...] = 0.0
        sumwt = numpy.zeros([nchan, npol])
        ms = convert_pol_frame(ms, bvis.polarisation_frame, im.polarisation_frame, polaxis=2)
        vis_to_im = numpy.round(model.wcs.sub([4]).wcs_world2pix(freq, 0)[0]).astype('int')
        for vchan in range(vnchan):
            ichan = vis_to_im[vchan]
            for pol in range(npol):
                ms_1d = numpy.array([ms[row, vchan:vchan+1, pol] for row in range(nrows * nants * nants)], dtype='complex')
                ms_1d.reshape([ms_1d.shape[0], 1])
                wgt_1d = numpy.array([wgt[row, vchan:vchan+1, pol] for row in range(nrows * nants * nants)])
                wgt_1d.reshape([wgt_1d.shape[0], 1])
                dirty = ng.ms2dirty(
                    fuvw, freq[vchan:vchan+1], ms_1d, wgt_1d,
                    npixdirty, npixdirty, pixsize, pixsize, epsilon, do_wstacking=do_wstacking,
                    nthreads=nthreads, verbosity=verbosity)
                sumwt[ichan, pol] += numpy.sum(wgt[:, vchan, pol])
                im.data[ichan, pol] += dirty.T
        if normalize:
            im = normalize_sumwt(im, sumwt)
        return im, sumwt
def invert_ng ( bvis : BlockVisibility , model : Image , dopsf : bool = False , normalize : bool = True , ** kwargs ) -> ( Image , numpy . ndarray ) : assert isinstance ( bvis , BlockVisibility ) , bvis im = copy_image ( model ) 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" , 0 ) sbvis = copy_visibility ( bvis ) sbvis = shift_vis_to_image ( sbvis , im , tangent = True , inverse = False ) vis = bvis . vis freq = sbvis . frequency nrows , nants , _ , vnchan , vnpol = vis . shape uvw = sbvis . uvw . reshape ( [ nrows * nants * nants , 3 ] ) ms = vis . reshape ( [ nrows * nants * nants , vnchan , vnpol ] ) wgt = sbvis . imaging_weight . reshape ( [ nrows * nants * nants , vnchan , vnpol ] ) if dopsf : ms [ ... ] = 1.0 + 0.0j if epsilon > 5.0e-6 : ms = ms . astype ( "c8" ) wgt = wgt . astype ( "f4" ) npixdirty = im . nwidth pixsize = numpy . abs ( numpy . radians ( im . wcs . wcs . cdelt [ 0 ] ) ) fuvw = uvw . copy ( ) fuvw [ : , 0 ] *= - 1.0 fuvw [ : , 2 ] *= - 1.0 nchan , npol , ny , nx = im . shape im . data [ ... ] = 0.0 sumwt = numpy . zeros ( [ nchan , npol ] ) ms = convert_pol_frame ( ms , bvis . polarisation_frame , im . polarisation_frame , polaxis = 2 ) vis_to_im = numpy . round ( model . wcs . sub ( [ 4 ] ) . wcs_world2pix ( freq , 0 ) [ 0 ] ) . astype ( 'int' ) for vchan in range ( vnchan ) : ichan = vis_to_im [ vchan ] for pol in range ( npol ) : ms_1d = numpy . array ( [ ms [ row , vchan : vchan + 1 , pol ] for row in range ( nrows * nants * nants ) ] , dtype = 'complex' ) ms_1d . reshape ( [ ms_1d . shape [ 0 ] , 1 ] ) wgt_1d = numpy . array ( [ wgt [ row , vchan : vchan + 1 , pol ] for row in range ( nrows * nants * nants ) ] ) wgt_1d . reshape ( [ wgt_1d . shape [ 0 ] , 1 ] ) dirty = ng . ms2dirty ( fuvw , freq [ vchan : vchan + 1 ] , ms_1d , wgt_1d , npixdirty , npixdirty , pixsize , pixsize , epsilon , do_wstacking = do_wstacking , nthreads = nthreads , verbosity = verbosity ) sumwt [ ichan , pol ] += numpy . sum ( wgt [ : , vchan , pol ] ) im . data [ ichan , pol ] += dirty . T if normalize : im = normalize_sumwt ( im , sumwt ) return im , sumwt
Invert using nifty-gridder module
https://gitlab.mpcdf.mpg.de/ift/nifty_gridder
Invert using nifty - gridder module https : // gitlab . mpcdf . mpg . de / ift / nifty_gridder
""" Invert using nifty-gridder module
        
        https://gitlab.mpcdf.mpg.de/ift/nifty_gridder
    
        Use the image im as a template. Do PSF in a separate call.
    
        This is at the bottom of the layering i.e. all transforms are eventually expressed in terms
        of this function. . Any shifting needed is performed here.
    
        :param bvis: BlockVisibility to be inverted
        :param im: image template (not changed)
        :param normalize: Normalize by the sum of weights (True)
        :return: (resulting image, sum of the weights for each frequency and polarization)
    
        """ # frequency, Hz # Find out the image size/resolution # We need to flip the u and w axes. # There's a latent problem here with the weights. # wgt = numpy.real(convert_pol_frame(wgt, bvis.polarisation_frame, im.polarisation_frame, polaxis=2)) # Set up the conversion from visibility channels to image channels # Nifty gridder likes to receive contiguous arrays
(resulting image, sum of the weights for each frequency and polarization)
( resulting image sum of the weights for each frequency and polarization )
bvis
BlockVisibility
BlockVisibility to be inverted
BlockVisibility to be inverted
model
Image
dopsf
bool
normalize
bool
Normalize by the sum of weights (True)
Normalize by the sum of weights ( True )
im
image template (not changed)
image template ( not changed )