processing_components/griddata/kernels.py
def create_awterm_convolutionfunction(im, make_pb=None, nw=1, wstep=1e15, oversampling=8, support=6, use_aaf=True,
                                      maxsupport=512):
    """ Fill AW projection kernel into a GridData.

    :param im: Image template
    :param make_pb: Function to make the primary beam model image (hint: use a partial)
    :param nw: Number of w planes
    :param wstep: Step in w (wavelengths)
    :param oversampling: Oversampling of the convolution function in uv space
    :return: griddata correction Image, griddata kernel as GridData
    """
    d2r = numpy.pi / 180.0
    
    # We only need the griddata correction function for the PSWF so we make
    # it for the shape of the image
    nchan, npol, ony, onx = im.data.shape
    
    assert isinstance(im, Image)
    # Calculate the template convolution kernel.
    cf = create_convolutionfunction_from_image(im, oversampling=oversampling, support=support)
    
    cf_shape = list(cf.data.shape)
    cf_shape[2] = nw
    cf.data = numpy.zeros(cf_shape).astype('complex')
    
    cf.grid_wcs.wcs.crpix[4] = nw // 2 + 1.0
    cf.grid_wcs.wcs.cdelt[4] = wstep
    cf.grid_wcs.wcs.ctype[4] = 'WW'
    if numpy.abs(wstep) > 0.0:
        w_list = cf.grid_wcs.sub([5]).wcs_pix2world(range(nw), 0)[0]
    else:
        w_list = [0.0]
        
    assert isinstance(oversampling, int)
    assert oversampling > 0

    nx = max(maxsupport, 2 * oversampling * support)
    ny = max(maxsupport, 2 * oversampling * support)
    
    qnx = nx // oversampling
    qny = ny // oversampling

    cf.data[...] = 0.0

    subim = copy_image(im)
    ccell = onx * numpy.abs(d2r * subim.wcs.wcs.cdelt[0]) / qnx

    subim.data = numpy.zeros([nchan, npol, qny, qnx])
    subim.wcs.wcs.cdelt[0] = -ccell / d2r
    subim.wcs.wcs.cdelt[1] = +ccell / d2r
    subim.wcs.wcs.crpix[0] = qnx // 2 + 1.0
    subim.wcs.wcs.crpix[1] = qny // 2 + 1.0

    if use_aaf:
        this_pswf_gcf, _ = create_pswf_convolutionfunction(subim, oversampling=1, support=6)
        norm = 1.0 / this_pswf_gcf.data
    else:
        norm = 1.0
    
    if make_pb is not None:
        pb = make_pb(subim)
        rpb, footprint = reproject_image(pb, subim.wcs, shape=subim.shape)
        rpb.data[footprint.data < 1e-6] = 0.0
        norm *= rpb.data
    
    # We might need to work with a larger image
    padded_shape = [nchan, npol, ny, nx]
    thisplane = copy_image(subim)
    thisplane.data = numpy.zeros(thisplane.shape, dtype='complex')
    for z, w in enumerate(w_list):
        thisplane.data[...] = 0.0 + 0.0j
        thisplane = create_w_term_like(thisplane, w, dopol=True)
        thisplane.data *= norm
        paddedplane = pad_image(thisplane, padded_shape)
        paddedplane = fft_image(paddedplane)
        
        ycen, xcen = ny // 2, nx // 2
        for y in range(oversampling):
            ybeg = y + ycen + (support * oversampling) // 2 - oversampling // 2
            yend = y + ycen - (support * oversampling) // 2 - oversampling // 2
            # vv = range(ybeg, yend, -oversampling)
            for x in range(oversampling):
                xbeg = x + xcen + (support * oversampling) // 2 - oversampling // 2
                xend = x + xcen - (support * oversampling) // 2 - oversampling // 2

                # uu = range(xbeg, xend, -oversampling)
                cf.data[..., z, y, x, :, :] = paddedplane.data[..., ybeg:yend:-oversampling, xbeg:xend:-oversampling]
                # for chan in range(nchan):
                #     for pol in range(npol):
                #         cf.data[chan, pol, z, y, x, :, :] = paddedplane.data[chan, pol, :, :][vv, :][:, uu]

    cf.data /= numpy.sum(numpy.real(cf.data[0, 0, nw // 2, oversampling // 2, oversampling // 2, :, :]))
    cf.data = numpy.conjugate(cf.data)
    
    if use_aaf:
        pswf_gcf, _ = create_pswf_convolutionfunction(im, oversampling=1, support=6)
    else:
        pswf_gcf = create_empty_image_like(im)
        pswf_gcf.data[...] = 1.0
    
    return pswf_gcf, cf
 Fill AW projection kernel into a GridData.

    :param im: Image template
    :param make_pb: Function to make the primary beam model image (hint: use a partial)
    :param nw: Number of w planes
    :param wstep: Step in w (wavelengths)
    :param oversampling: Oversampling of the convolution function in uv space
    :return: griddata correction Image, griddata kernel as GridData
    
Fill AW projection kernel into a GridData.
Fill AW projection kernel into a GridData .
def create_awterm_convolutionfunction(im, make_pb=None, nw=1, wstep=1e15, oversampling=8, support=6, use_aaf=True,
                                      maxsupport=512):
    d2r = numpy.pi / 180.0
    nchan, npol, ony, onx = im.data.shape
    assert isinstance(im, Image)
    cf = create_convolutionfunction_from_image(im, oversampling=oversampling, support=support)
    cf_shape = list(cf.data.shape)
    cf_shape[2] = nw
    cf.data = numpy.zeros(cf_shape).astype('complex')
    cf.grid_wcs.wcs.crpix[4] = nw // 2 + 1.0
    cf.grid_wcs.wcs.cdelt[4] = wstep
    cf.grid_wcs.wcs.ctype[4] = 'WW'
    if numpy.abs(wstep) > 0.0:
        w_list = cf.grid_wcs.sub([5]).wcs_pix2world(range(nw), 0)[0]
    else:
        w_list = [0.0]
    assert isinstance(oversampling, int)
    assert oversampling > 0
    nx = max(maxsupport, 2 * oversampling * support)
    ny = max(maxsupport, 2 * oversampling * support)
    qnx = nx // oversampling
    qny = ny // oversampling
    cf.data[...] = 0.0
    subim = copy_image(im)
    ccell = onx * numpy.abs(d2r * subim.wcs.wcs.cdelt[0]) / qnx
    subim.data = numpy.zeros([nchan, npol, qny, qnx])
    subim.wcs.wcs.cdelt[0] = -ccell / d2r
    subim.wcs.wcs.cdelt[1] = +ccell / d2r
    subim.wcs.wcs.crpix[0] = qnx // 2 + 1.0
    subim.wcs.wcs.crpix[1] = qny // 2 + 1.0
    if use_aaf:
        this_pswf_gcf, _ = create_pswf_convolutionfunction(subim, oversampling=1, support=6)
        norm = 1.0 / this_pswf_gcf.data
    else:
        norm = 1.0
    if make_pb is not None:
        pb = make_pb(subim)
        rpb, footprint = reproject_image(pb, subim.wcs, shape=subim.shape)
        rpb.data[footprint.data < 1e-6] = 0.0
        norm *= rpb.data
    padded_shape = [nchan, npol, ny, nx]
    thisplane = copy_image(subim)
    thisplane.data = numpy.zeros(thisplane.shape, dtype='complex')
    for z, w in enumerate(w_list):
        thisplane.data[...] = 0.0 + 0.0j
        thisplane = create_w_term_like(thisplane, w, dopol=True)
        thisplane.data *= norm
        paddedplane = pad_image(thisplane, padded_shape)
        paddedplane = fft_image(paddedplane)
        ycen, xcen = ny // 2, nx // 2
        for y in range(oversampling):
            ybeg = y + ycen + (support * oversampling) // 2 - oversampling // 2
            yend = y + ycen - (support * oversampling) // 2 - oversampling // 2
            for x in range(oversampling):
                xbeg = x + xcen + (support * oversampling) // 2 - oversampling // 2
                xend = x + xcen - (support * oversampling) // 2 - oversampling // 2
                cf.data[..., z, y, x, :, :] = paddedplane.data[..., ybeg:yend:-oversampling, xbeg:xend:-oversampling]
    cf.data /= numpy.sum(numpy.real(cf.data[0, 0, nw // 2, oversampling // 2, oversampling // 2, :, :]))
    cf.data = numpy.conjugate(cf.data)
    if use_aaf:
        pswf_gcf, _ = create_pswf_convolutionfunction(im, oversampling=1, support=6)
    else:
        pswf_gcf = create_empty_image_like(im)
        pswf_gcf.data[...] = 1.0
    return pswf_gcf, cf
def create_awterm_convolutionfunction ( im , make_pb = None , nw = 1 , wstep = 1e15 , oversampling = 8 , support = 6 , use_aaf = True , maxsupport = 512 ) : d2r = numpy . pi / 180.0 nchan , npol , ony , onx = im . data . shape assert isinstance ( im , Image ) cf = create_convolutionfunction_from_image ( im , oversampling = oversampling , support = support ) cf_shape = list ( cf . data . shape ) cf_shape [ 2 ] = nw cf . data = numpy . zeros ( cf_shape ) . astype ( 'complex' ) cf . grid_wcs . wcs . crpix [ 4 ] = nw // 2 + 1.0 cf . grid_wcs . wcs . cdelt [ 4 ] = wstep cf . grid_wcs . wcs . ctype [ 4 ] = 'WW' if numpy . abs ( wstep ) > 0.0 : w_list = cf . grid_wcs . sub ( [ 5 ] ) . wcs_pix2world ( range ( nw ) , 0 ) [ 0 ] else : w_list = [ 0.0 ] assert isinstance ( oversampling , int ) assert oversampling > 0 nx = max ( maxsupport , 2 * oversampling * support ) ny = max ( maxsupport , 2 * oversampling * support ) qnx = nx // oversampling qny = ny // oversampling cf . data [ ... ] = 0.0 subim = copy_image ( im ) ccell = onx * numpy . abs ( d2r * subim . wcs . wcs . cdelt [ 0 ] ) / qnx subim . data = numpy . zeros ( [ nchan , npol , qny , qnx ] ) subim . wcs . wcs . cdelt [ 0 ] = - ccell / d2r subim . wcs . wcs . cdelt [ 1 ] = + ccell / d2r subim . wcs . wcs . crpix [ 0 ] = qnx // 2 + 1.0 subim . wcs . wcs . crpix [ 1 ] = qny // 2 + 1.0 if use_aaf : this_pswf_gcf , _ = create_pswf_convolutionfunction ( subim , oversampling = 1 , support = 6 ) norm = 1.0 / this_pswf_gcf . data else : norm = 1.0 if make_pb is not None : pb = make_pb ( subim ) rpb , footprint = reproject_image ( pb , subim . wcs , shape = subim . shape ) rpb . data [ footprint . data < 1e-6 ] = 0.0 norm *= rpb . data padded_shape = [ nchan , npol , ny , nx ] thisplane = copy_image ( subim ) thisplane . data = numpy . zeros ( thisplane . shape , dtype = 'complex' ) for z , w in enumerate ( w_list ) : thisplane . data [ ... ] = 0.0 + 0.0j thisplane = create_w_term_like ( thisplane , w , dopol = True ) thisplane . data *= norm paddedplane = pad_image ( thisplane , padded_shape ) paddedplane = fft_image ( paddedplane ) ycen , xcen = ny // 2 , nx // 2 for y in range ( oversampling ) : ybeg = y + ycen + ( support * oversampling ) // 2 - oversampling // 2 yend = y + ycen - ( support * oversampling ) // 2 - oversampling // 2 for x in range ( oversampling ) : xbeg = x + xcen + ( support * oversampling ) // 2 - oversampling // 2 xend = x + xcen - ( support * oversampling ) // 2 - oversampling // 2 cf . data [ ... , z , y , x , : , : ] = paddedplane . data [ ... , ybeg : yend : - oversampling , xbeg : xend : - oversampling ] cf . data /= numpy . sum ( numpy . real ( cf . data [ 0 , 0 , nw // 2 , oversampling // 2 , oversampling // 2 , : , : ] ) ) cf . data = numpy . conjugate ( cf . data ) if use_aaf : pswf_gcf , _ = create_pswf_convolutionfunction ( im , oversampling = 1 , support = 6 ) else : pswf_gcf = create_empty_image_like ( im ) pswf_gcf . data [ ... ] = 1.0 return pswf_gcf , cf
Fill AW projection kernel into a GridData.
Fill AW projection kernel into a GridData .
""" Fill AW projection kernel into a GridData.

    :param im: Image template
    :param make_pb: Function to make the primary beam model image (hint: use a partial)
    :param nw: Number of w planes
    :param wstep: Step in w (wavelengths)
    :param oversampling: Oversampling of the convolution function in uv space
    :return: griddata correction Image, griddata kernel as GridData
    """ # We only need the griddata correction function for the PSWF so we make # it for the shape of the image # Calculate the template convolution kernel. # We might need to work with a larger image # vv = range(ybeg, yend, -oversampling) # uu = range(xbeg, xend, -oversampling) # for chan in range(nchan): #     for pol in range(npol): #         cf.data[chan, pol, z, y, x, :, :] = paddedplane.data[chan, pol, :, :][vv, :][:, uu]
griddata correction Image, griddata kernel as GridData
griddata correction Image griddata kernel as GridData
im
None
make_pb
Function to make the primary beam model image (hint: use a partial)
Function to make the primary beam model image ( hint : use a partial )
nw
Number of w planes
Number of w planes
wstep
Step in w (wavelengths)
Step in w ( wavelengths )
oversampling
Oversampling of the convolution function in uv space
Oversampling of the convolution function in uv space
support
use_aaf
maxsupport