def psf_convolution_new(self, unconvolved_image, subgrid_res=1, subsampling_size=5, psf_subgrid=True,
                            subgrid_conv_type='grid', conv_type='fft'):
        """

        :param unconvolved_image: 2d image with subsampled pixels with subgrid_res
        :param subgrid_res: subsampling resolution
        :param subsampling_size: size of the subsampling convolution in units of image pixels
        :param psf_subgrid: bool, if False, the convolution is performed on the pixel size of the data
        :param subgrid_conv_type: 'grid' or 'fft', using either scipy.convolve2d or scipy.signal.fftconvolve for
         convolution of subsampled kernel
        :param conv_type: 'grid' or 'fft', using either scipy.convolve2d or scipy.signal.fftconvolve for
         convolution of regular kernel
        :return: convolved 2d image in units of the pixels
        """
        unconvolved_image_resized = image_util.re_size(unconvolved_image, subgrid_res)
        if self.psf_type == 'NONE':
            image_conv_resized = unconvolved_image_resized
        elif self.psf_type == 'GAUSSIAN':
            if psf_subgrid is True:
                grid_scale = self._pixel_size / float(subgrid_res)
                sigma = self._sigma_gaussian/grid_scale
                image_conv = ndimage.filters.gaussian_filter(unconvolved_image, sigma, mode='nearest', truncate=self._truncation)
                image_conv_resized = image_util.re_size(image_conv, subgrid_res)
            else:
                sigma = self._sigma_gaussian / self._pixel_size
                image_conv_resized = ndimage.filters.gaussian_filter(unconvolved_image_resized, sigma, mode='nearest',
                                                             truncate=self._truncation)

        elif self.psf_type == 'PIXEL':
            kernel = self._kernel_pixel
            if subgrid_res > 1 and psf_subgrid is True:
                kernel_subgrid = self.subgrid_pixel_kernel(subgrid_res)
                kernel, kernel_subgrid = kernel_util.split_kernel(kernel, kernel_subgrid, subsampling_size, subgrid_res)
                if subgrid_conv_type == 'fft':
                    image_conv_subgrid = signal.fftconvolve(unconvolved_image, kernel_subgrid, mode='same')
                elif subgrid_conv_type == 'grid':
                    image_conv_subgrid = signal.convolve2d(unconvolved_image, kernel_subgrid, mode='same')
                else:
                    raise ValueError('subgrid_conv_type %s not valid!' % subgrid_conv_type)
                image_conv_resized_1 = image_util.re_size(image_conv_subgrid, subgrid_res)
                if conv_type == 'fft':
                    image_conv_resized_2 = signal.fftconvolve(unconvolved_image_resized, kernel, mode='same')
                elif conv_type == 'grid':
                    image_conv_resized_2 = signal.convolve2d(unconvolved_image_resized, kernel, mode='same')
                else:
                    raise ValueError('conv_type %s not valid!' % conv_type)
                image_conv_resized = image_conv_resized_1 + image_conv_resized_2
            else:
                image_conv_resized = signal.fftconvolve(unconvolved_image_resized, kernel, mode='same')
        else:
            raise ValueError('PSF type %s not valid!' % self.psf_type)
        return image_conv_resized
def psf_convolution_new ( self , unconvolved_image , subgrid_res = 1 , subsampling_size = 5 , psf_subgrid = True , subgrid_conv_type = 'grid' , conv_type = 'fft' ) : unconvolved_image_resized = image_util . re_size ( unconvolved_image , subgrid_res ) if self . psf_type == 'NONE' : image_conv_resized = unconvolved_image_resized elif self . psf_type == 'GAUSSIAN' : if psf_subgrid is True : grid_scale = self . _pixel_size / float ( subgrid_res ) sigma = self . _sigma_gaussian / grid_scale image_conv = ndimage . filters . gaussian_filter ( unconvolved_image , sigma , mode = 'nearest' , truncate = self . _truncation ) image_conv_resized = image_util . re_size ( image_conv , subgrid_res ) else : sigma = self . _sigma_gaussian / self . _pixel_size image_conv_resized = ndimage . filters . gaussian_filter ( unconvolved_image_resized , sigma , mode = 'nearest' , truncate = self . _truncation ) elif self . psf_type == 'PIXEL' : kernel = self . _kernel_pixel if subgrid_res > 1 and psf_subgrid is True : kernel_subgrid = self . subgrid_pixel_kernel ( subgrid_res ) kernel , kernel_subgrid = kernel_util . split_kernel ( kernel , kernel_subgrid , subsampling_size , subgrid_res ) if subgrid_conv_type == 'fft' : image_conv_subgrid = signal . fftconvolve ( unconvolved_image , kernel_subgrid , mode = 'same' ) elif subgrid_conv_type == 'grid' : image_conv_subgrid = signal . convolve2d ( unconvolved_image , kernel_subgrid , mode = 'same' ) else : raise ValueError ( 'subgrid_conv_type %s not valid!' % subgrid_conv_type ) image_conv_resized_1 = image_util . re_size ( image_conv_subgrid , subgrid_res ) if conv_type == 'fft' : image_conv_resized_2 = signal . fftconvolve ( unconvolved_image_resized , kernel , mode = 'same' ) elif conv_type == 'grid' : image_conv_resized_2 = signal . convolve2d ( unconvolved_image_resized , kernel , mode = 'same' ) else : raise ValueError ( 'conv_type %s not valid!' % conv_type ) image_conv_resized = image_conv_resized_1 + image_conv_resized_2 else : image_conv_resized = signal . fftconvolve ( unconvolved_image_resized , kernel , mode = 'same' ) else : raise ValueError ( 'PSF type %s not valid!' % self . psf_type ) return image_conv_resized
:param unconvolved_image: 2d image with subsampled pixels with subgrid_res
        :param subgrid_res: subsampling resolution
        :param subsampling_size: size of the subsampling convolution in units of image pixels
        :param psf_subgrid: bool, if False, the convolution is performed on the pixel size of the data
        :param subgrid_conv_type: 'grid' or 'fft', using either scipy.convolve2d or scipy.signal.fftconvolve for
         convolution of subsampled kernel
        :param conv_type: 'grid' or 'fft', using either scipy.convolve2d or scipy.signal.fftconvolve for
         convolution of regular kernel
        :return: convolved 2d image in units of the pixels