processing_components/image/deconvolution.py
def restore_cube(model: Image, psf: Image, residual=None, **kwargs) -> Image:
    """ Restore the model image to the residuals

    :params psf: Input PSF
    :return: restored image

    """
    assert isinstance(model, Image), model
    assert isinstance(psf, Image), psf
    assert residual is None or isinstance(residual, Image), residual
    
    restored = copy_image(model)
    
    npixel = psf.data.shape[3]
    sl = slice(npixel // 2 - 7, npixel // 2 + 8)
    
    size = get_parameter(kwargs, "psfwidth", None)
    
    if size is None:
        # isotropic at the moment!
        from scipy.optimize import minpack
        try:
            fit = fit_2dgaussian(psf.data[0, 0, sl, sl])
            if fit.x_stddev <= 0.0 or fit.y_stddev <= 0.0:
                log.debug('restore_cube: error in fitting to psf, using 1 pixel stddev')
                size = 1.0
            else:
                size = max(fit.x_stddev, fit.y_stddev)
                log.debug('restore_cube: psfwidth = %s' % (size))
        except minpack.error as err:
            log.debug('restore_cube: minpack error, using 1 pixel stddev')
            size = 1.0
        except ValueError as err:
            log.debug('restore_cube: warning in fit to psf, using 1 pixel stddev')
            size = 1.0
    else:
        log.debug('restore_cube: Using specified psfwidth = %s' % (size))

    # By convention, we normalise the peak not the integral so this is the volume of the Gaussian
    norm = 2.0 * numpy.pi * size ** 2
    gk = Gaussian2DKernel(size)
    for chan in range(model.shape[0]):
        for pol in range(model.shape[1]):
            restored.data[chan, pol, :, :] = norm * convolve_fft(model.data[chan, pol, :, :], gk,
                                                                 normalize_kernel=False, allow_huge=True)
    if residual is not None:
        restored.data += residual.data
    return restored
 Restore the model image to the residuals

    :params psf: Input PSF
    :return: restored image

    
Restore the model image to the residuals
Restore the model image to the residuals
def restore_cube(model: Image, psf: Image, residual=None, **kwargs) -> Image:
    assert isinstance(model, Image), model
    assert isinstance(psf, Image), psf
    assert residual is None or isinstance(residual, Image), residual
    restored = copy_image(model)
    npixel = psf.data.shape[3]
    sl = slice(npixel // 2 - 7, npixel // 2 + 8)
    size = get_parameter(kwargs, "psfwidth", None)
    if size is None:
        from scipy.optimize import minpack
        try:
            fit = fit_2dgaussian(psf.data[0, 0, sl, sl])
            if fit.x_stddev <= 0.0 or fit.y_stddev <= 0.0:
                log.debug('restore_cube: error in fitting to psf, using 1 pixel stddev')
                size = 1.0
            else:
                size = max(fit.x_stddev, fit.y_stddev)
                log.debug('restore_cube: psfwidth = %s' % (size))
        except minpack.error as err:
            log.debug('restore_cube: minpack error, using 1 pixel stddev')
            size = 1.0
        except ValueError as err:
            log.debug('restore_cube: warning in fit to psf, using 1 pixel stddev')
            size = 1.0
    else:
        log.debug('restore_cube: Using specified psfwidth = %s' % (size))
    norm = 2.0 * numpy.pi * size ** 2
    gk = Gaussian2DKernel(size)
    for chan in range(model.shape[0]):
        for pol in range(model.shape[1]):
            restored.data[chan, pol, :, :] = norm * convolve_fft(model.data[chan, pol, :, :], gk,
                                                                 normalize_kernel=False, allow_huge=True)
    if residual is not None:
        restored.data += residual.data
    return restored
def restore_cube ( model : Image , psf : Image , residual = None , ** kwargs ) -> Image : assert isinstance ( model , Image ) , model assert isinstance ( psf , Image ) , psf assert residual is None or isinstance ( residual , Image ) , residual restored = copy_image ( model ) npixel = psf . data . shape [ 3 ] sl = slice ( npixel // 2 - 7 , npixel // 2 + 8 ) size = get_parameter ( kwargs , "psfwidth" , None ) if size is None : from scipy . optimize import minpack try : fit = fit_2dgaussian ( psf . data [ 0 , 0 , sl , sl ] ) if fit . x_stddev <= 0.0 or fit . y_stddev <= 0.0 : log . debug ( 'restore_cube: error in fitting to psf, using 1 pixel stddev' ) size = 1.0 else : size = max ( fit . x_stddev , fit . y_stddev ) log . debug ( 'restore_cube: psfwidth = %s' % ( size ) ) except minpack . error as err : log . debug ( 'restore_cube: minpack error, using 1 pixel stddev' ) size = 1.0 except ValueError as err : log . debug ( 'restore_cube: warning in fit to psf, using 1 pixel stddev' ) size = 1.0 else : log . debug ( 'restore_cube: Using specified psfwidth = %s' % ( size ) ) norm = 2.0 * numpy . pi * size ** 2 gk = Gaussian2DKernel ( size ) for chan in range ( model . shape [ 0 ] ) : for pol in range ( model . shape [ 1 ] ) : restored . data [ chan , pol , : , : ] = norm * convolve_fft ( model . data [ chan , pol , : , : ] , gk , normalize_kernel = False , allow_huge = True ) if residual is not None : restored . data += residual . data return restored
Restore the model image to the residuals
Restore the model image to the residuals
""" Restore the model image to the residuals

    :params psf: Input PSF
    :return: restored image

    """ # isotropic at the moment! # By convention, we normalise the peak not the integral so this is the volume of the Gaussian
None
model
Image
psf
Image
residual
params
None