processing_library/image/operations.py
def pad_image(im: Image, shape):
    """Pad an image to desired shape
    
    The wcs crpix is adjusted appropriately
    
    :param im:
    :param shape:
    :return:
    """
    if im.shape == shape:
        return im
    else:
        newwcs = copy.deepcopy(im.wcs)
        newwcs.wcs.crpix[0] = im.wcs.wcs.crpix[0] + shape[3] // 2 - im.shape[3] // 2
        newwcs.wcs.crpix[1] = im.wcs.wcs.crpix[1] + shape[2] // 2 - im.shape[2] // 2
        
        for axis, _ in enumerate(im.shape):
            if shape[axis] < im.shape[axis]:
                raise ValueError("Padded shape %s is smaller than input shape %s" % (shape, im.shape))
        
        newdata = numpy.zeros(shape, dtype=im.data.dtype)
        ystart = shape[2] // 2 - im.shape[2] // 2
        yend = ystart + im.shape[2]
        xstart = shape[3] // 2 - im.shape[3] // 2
        xend = xstart + im.shape[3]
        newdata[..., ystart:yend, xstart:xend] = im.data[...]
        return create_image_from_array(newdata, newwcs, polarisation_frame=im.polarisation_frame)
Pad an image to desired shape
    
    The wcs crpix is adjusted appropriately
    
    :param im:
    :param shape:
    :return:
    
Pad an image to desired shape
The wcs crpix is adjusted appropriately
Pad an image to desired shape The wcs crpix is adjusted appropriately
def pad_image(im: Image, shape):
    if im.shape == shape:
        return im
    else:
        newwcs = copy.deepcopy(im.wcs)
        newwcs.wcs.crpix[0] = im.wcs.wcs.crpix[0] + shape[3] // 2 - im.shape[3] // 2
        newwcs.wcs.crpix[1] = im.wcs.wcs.crpix[1] + shape[2] // 2 - im.shape[2] // 2
        for axis, _ in enumerate(im.shape):
            if shape[axis] < im.shape[axis]:
                raise ValueError("Padded shape %s is smaller than input shape %s" % (shape, im.shape))
        newdata = numpy.zeros(shape, dtype=im.data.dtype)
        ystart = shape[2] // 2 - im.shape[2] // 2
        yend = ystart + im.shape[2]
        xstart = shape[3] // 2 - im.shape[3] // 2
        xend = xstart + im.shape[3]
        newdata[..., ystart:yend, xstart:xend] = im.data[...]
        return create_image_from_array(newdata, newwcs, polarisation_frame=im.polarisation_frame)
def pad_image ( im : Image , shape ) : if im . shape == shape : return im else : newwcs = copy . deepcopy ( im . wcs ) newwcs . wcs . crpix [ 0 ] = im . wcs . wcs . crpix [ 0 ] + shape [ 3 ] // 2 - im . shape [ 3 ] // 2 newwcs . wcs . crpix [ 1 ] = im . wcs . wcs . crpix [ 1 ] + shape [ 2 ] // 2 - im . shape [ 2 ] // 2 for axis , _ in enumerate ( im . shape ) : if shape [ axis ] < im . shape [ axis ] : raise ValueError ( "Padded shape %s is smaller than input shape %s" % ( shape , im . shape ) ) newdata = numpy . zeros ( shape , dtype = im . data . dtype ) ystart = shape [ 2 ] // 2 - im . shape [ 2 ] // 2 yend = ystart + im . shape [ 2 ] xstart = shape [ 3 ] // 2 - im . shape [ 3 ] // 2 xend = xstart + im . shape [ 3 ] newdata [ ... , ystart : yend , xstart : xend ] = im . data [ ... ] return create_image_from_array ( newdata , newwcs , polarisation_frame = im . polarisation_frame )
Pad an image to desired shape
The wcs crpix is adjusted appropriately
Pad an image to desired shape The wcs crpix is adjusted appropriately
"""Pad an image to desired shape
    
    The wcs crpix is adjusted appropriately
    
    :param im:
    :param shape:
    :return:
    """
None
im
Image
None
shape
None