processing_library/image/operations.py
def convert_image_to_kernel(im: Image, oversampling, kernelwidth):
    """ Convert an image to a griddata kernel
    
    :param im: Image to be converted
    :param oversampling: Oversampling of Image spatially
    :param kernelwidth: Kernel width to be extracted
    :return: numpy.ndarray[nchan, npol, oversampling, oversampling, kernelwidth, kernelwidth]
    """
    naxis = len(im.shape)
    assert naxis == 4
    
    assert numpy.max(numpy.abs(im.data)) > 0.0, "Image is empty"
    
    nchan, npol, ny, nx = im.shape
    assert nx % oversampling == 0, "Oversampling must be even"
    assert ny % oversampling == 0, "Oversampling must be even"
    
    assert kernelwidth < nx and kernelwidth < ny, "Specified kernel width %d too large"
    
    assert im.wcs.wcs.ctype[0] == 'UU', 'Axis type %s inappropriate for construction of kernel' % im.wcs.wcs.ctype[0]
    assert im.wcs.wcs.ctype[1] == 'VV', 'Axis type %s inappropriate for construction of kernel' % im.wcs.wcs.ctype[1]
    newwcs = WCS(naxis=naxis + 2)
    for axis in range(2):
        newwcs.wcs.ctype[axis] = im.wcs.wcs.ctype[axis]
        newwcs.wcs.crpix[axis] = kernelwidth // 2
        newwcs.wcs.crval[axis] = 0.0
        newwcs.wcs.cdelt[axis] = im.wcs.wcs.cdelt[axis] * oversampling
        
        newwcs.wcs.ctype[axis + 2] = im.wcs.wcs.ctype[axis]
        newwcs.wcs.crpix[axis + 2] = oversampling // 2
        newwcs.wcs.crval[axis + 2] = 0.0
        newwcs.wcs.cdelt[axis + 2] = im.wcs.wcs.cdelt[axis]
        
        # Now do Stokes and Frequency
        newwcs.wcs.ctype[axis + 4] = im.wcs.wcs.ctype[axis + 2]
        newwcs.wcs.crpix[axis + 4] = im.wcs.wcs.crpix[axis + 2]
        newwcs.wcs.crval[axis + 4] = im.wcs.wcs.crval[axis + 2]
        newwcs.wcs.cdelt[axis + 4] = im.wcs.wcs.cdelt[axis + 2]
    
    newdata_shape = [nchan, npol, oversampling, oversampling, kernelwidth, kernelwidth]

    newdata = numpy.zeros(newdata_shape, dtype=im.data.dtype)
    
    assert oversampling * kernelwidth < ny
    assert oversampling * kernelwidth < nx
    
    ystart = ny // 2 - oversampling * kernelwidth // 2
    xstart = nx // 2 - oversampling * kernelwidth // 2
    yend = ny // 2 + oversampling * kernelwidth // 2
    xend = nx // 2 + oversampling * kernelwidth // 2
    for chan in range(nchan):
        for pol in range(npol):
            for y in range(oversampling):
                slicey = slice(yend + y, ystart + y, -oversampling)
                for x in range(oversampling):
                    slicex = slice(xend + x, xstart + x, -oversampling)
                    newdata[chan, pol, y, x, ...] = im.data[chan, pol, slicey, slicex]
    
    return create_image_from_array(newdata, newwcs, polarisation_frame=im.polarisation_frame)
 Convert an image to a griddata kernel
    
    :param im: Image to be converted
    :param oversampling: Oversampling of Image spatially
    :param kernelwidth: Kernel width to be extracted
    :return: numpy.ndarray[nchan, npol, oversampling, oversampling, kernelwidth, kernelwidth]
    
Convert an image to a griddata kernel
Convert an image to a griddata kernel
def convert_image_to_kernel(im: Image, oversampling, kernelwidth):
    naxis = len(im.shape)
    assert naxis == 4
    assert numpy.max(numpy.abs(im.data)) > 0.0, "Image is empty"
    nchan, npol, ny, nx = im.shape
    assert nx % oversampling == 0, "Oversampling must be even"
    assert ny % oversampling == 0, "Oversampling must be even"
    assert kernelwidth < nx and kernelwidth < ny, "Specified kernel width %d too large"
    assert im.wcs.wcs.ctype[0] == 'UU', 'Axis type %s inappropriate for construction of kernel' % im.wcs.wcs.ctype[0]
    assert im.wcs.wcs.ctype[1] == 'VV', 'Axis type %s inappropriate for construction of kernel' % im.wcs.wcs.ctype[1]
    newwcs = WCS(naxis=naxis + 2)
    for axis in range(2):
        newwcs.wcs.ctype[axis] = im.wcs.wcs.ctype[axis]
        newwcs.wcs.crpix[axis] = kernelwidth // 2
        newwcs.wcs.crval[axis] = 0.0
        newwcs.wcs.cdelt[axis] = im.wcs.wcs.cdelt[axis] * oversampling
        newwcs.wcs.ctype[axis + 2] = im.wcs.wcs.ctype[axis]
        newwcs.wcs.crpix[axis + 2] = oversampling // 2
        newwcs.wcs.crval[axis + 2] = 0.0
        newwcs.wcs.cdelt[axis + 2] = im.wcs.wcs.cdelt[axis]
        newwcs.wcs.ctype[axis + 4] = im.wcs.wcs.ctype[axis + 2]
        newwcs.wcs.crpix[axis + 4] = im.wcs.wcs.crpix[axis + 2]
        newwcs.wcs.crval[axis + 4] = im.wcs.wcs.crval[axis + 2]
        newwcs.wcs.cdelt[axis + 4] = im.wcs.wcs.cdelt[axis + 2]
    newdata_shape = [nchan, npol, oversampling, oversampling, kernelwidth, kernelwidth]
    newdata = numpy.zeros(newdata_shape, dtype=im.data.dtype)
    assert oversampling * kernelwidth < ny
    assert oversampling * kernelwidth < nx
    ystart = ny // 2 - oversampling * kernelwidth // 2
    xstart = nx // 2 - oversampling * kernelwidth // 2
    yend = ny // 2 + oversampling * kernelwidth // 2
    xend = nx // 2 + oversampling * kernelwidth // 2
    for chan in range(nchan):
        for pol in range(npol):
            for y in range(oversampling):
                slicey = slice(yend + y, ystart + y, -oversampling)
                for x in range(oversampling):
                    slicex = slice(xend + x, xstart + x, -oversampling)
                    newdata[chan, pol, y, x, ...] = im.data[chan, pol, slicey, slicex]
    return create_image_from_array(newdata, newwcs, polarisation_frame=im.polarisation_frame)
def convert_image_to_kernel ( im : Image , oversampling , kernelwidth ) : naxis = len ( im . shape ) assert naxis == 4 assert numpy . max ( numpy . abs ( im . data ) ) > 0.0 , "Image is empty" nchan , npol , ny , nx = im . shape assert nx % oversampling == 0 , "Oversampling must be even" assert ny % oversampling == 0 , "Oversampling must be even" assert kernelwidth < nx and kernelwidth < ny , "Specified kernel width %d too large" assert im . wcs . wcs . ctype [ 0 ] == 'UU' , 'Axis type %s inappropriate for construction of kernel' % im . wcs . wcs . ctype [ 0 ] assert im . wcs . wcs . ctype [ 1 ] == 'VV' , 'Axis type %s inappropriate for construction of kernel' % im . wcs . wcs . ctype [ 1 ] newwcs = WCS ( naxis = naxis + 2 ) for axis in range ( 2 ) : newwcs . wcs . ctype [ axis ] = im . wcs . wcs . ctype [ axis ] newwcs . wcs . crpix [ axis ] = kernelwidth // 2 newwcs . wcs . crval [ axis ] = 0.0 newwcs . wcs . cdelt [ axis ] = im . wcs . wcs . cdelt [ axis ] * oversampling newwcs . wcs . ctype [ axis + 2 ] = im . wcs . wcs . ctype [ axis ] newwcs . wcs . crpix [ axis + 2 ] = oversampling // 2 newwcs . wcs . crval [ axis + 2 ] = 0.0 newwcs . wcs . cdelt [ axis + 2 ] = im . wcs . wcs . cdelt [ axis ] newwcs . wcs . ctype [ axis + 4 ] = im . wcs . wcs . ctype [ axis + 2 ] newwcs . wcs . crpix [ axis + 4 ] = im . wcs . wcs . crpix [ axis + 2 ] newwcs . wcs . crval [ axis + 4 ] = im . wcs . wcs . crval [ axis + 2 ] newwcs . wcs . cdelt [ axis + 4 ] = im . wcs . wcs . cdelt [ axis + 2 ] newdata_shape = [ nchan , npol , oversampling , oversampling , kernelwidth , kernelwidth ] newdata = numpy . zeros ( newdata_shape , dtype = im . data . dtype ) assert oversampling * kernelwidth < ny assert oversampling * kernelwidth < nx ystart = ny // 2 - oversampling * kernelwidth // 2 xstart = nx // 2 - oversampling * kernelwidth // 2 yend = ny // 2 + oversampling * kernelwidth // 2 xend = nx // 2 + oversampling * kernelwidth // 2 for chan in range ( nchan ) : for pol in range ( npol ) : for y in range ( oversampling ) : slicey = slice ( yend + y , ystart + y , - oversampling ) for x in range ( oversampling ) : slicex = slice ( xend + x , xstart + x , - oversampling ) newdata [ chan , pol , y , x , ... ] = im . data [ chan , pol , slicey , slicex ] return create_image_from_array ( newdata , newwcs , polarisation_frame = im . polarisation_frame )
Convert an image to a griddata kernel
Convert an image to a griddata kernel
""" Convert an image to a griddata kernel
    
    :param im: Image to be converted
    :param oversampling: Oversampling of Image spatially
    :param kernelwidth: Kernel width to be extracted
    :return: numpy.ndarray[nchan, npol, oversampling, oversampling, kernelwidth, kernelwidth]
    """ # Now do Stokes and Frequency
numpy.ndarray[nchan, npol, oversampling, oversampling, kernelwidth, kernelwidth]
numpy . ndarray [ nchan npol oversampling oversampling kernelwidth kernelwidth ]
im
Image
Image to be converted
Image to be converted
oversampling
Oversampling of Image spatially
Oversampling of Image spatially
kernelwidth
Kernel width to be extracted
Kernel width to be extracted