def irfftn(a, axes=None, lastsize=0, inorm=0, nthreads=1): return fft.c2r(a, axes=axes, lastsize=lastsize, forward=False, inorm=inorm, nthreads=nthreads)
def _hessian(x, psfhat, padding, nthreads, unpad_x, unpad_y, lastsize): xhat = iFs(np.pad(x, padding, mode='constant'), axes=(1, 2)) xhat = r2c(xhat, axes=(1, 2), nthreads=nthreads, forward=True, inorm=0) xhat = c2r(xhat * psfhat, axes=(1, 2), forward=False, lastsize=lastsize, inorm=2, nthreads=nthreads) return Fs(xhat, axes=(1, 2))[:, unpad_x, unpad_y]
def convolveb(self, x): xhat = iFs(np.pad(x, self.paddingb, mode='constant'), axes=self.ax) xhat = r2c(xhat, axes=self.ax, nthreads=self.nthreads, forward=True, inorm=0) xhat = c2r(xhat * self.psfhatb, axes=self.ax, forward=False, lastsize=self.lastsizeb, inorm=2, nthreads=self.nthreads) return Fs(xhat, axes=self.ax)[:, self.unpad_xb, self.unpad_yb]
def convolve2gaussres(image, xx, yy, gaussparf, nthreads, gausspari=None, pfrac=0.5, norm_kernel=False): """ Convolves the image to a specified resolution. Parameters ---------- Image - (nband, nx, ny) array to convolve xx/yy - coordinates on the grid in the same units as gaussparf. gaussparf - tuple containing Gaussian parameters of desired resolution (emaj, emin, pa). gausspari - initial resolution . By default it is assumed that the image is a clean component image with no associated resolution. If beampari is specified, it must be a tuple containing gausspars for each imaging band in the same format. nthreads - number of threads to use for the FFT's. pfrac - padding used for the FFT based convolution. Will pad by pfrac/2 on both sides of image """ nband, nx, ny = image.shape padding, unpad_x, unpad_y = get_padding_info(nx, ny, pfrac) ax = (1, 2) # axes over which to perform fft lastsize = ny + np.sum(padding[-1]) gausskern = Gaussian2D(xx, yy, gaussparf, normalise=norm_kernel) gausskern = np.pad(gausskern[None], padding, mode='constant') gausskernhat = r2c(iFs(gausskern, axes=ax), axes=ax, forward=True, nthreads=nthreads, inorm=0) image = np.pad(image, padding, mode='constant') imhat = r2c(iFs(image, axes=ax), axes=ax, forward=True, nthreads=nthreads, inorm=0) # convolve to desired resolution if gausspari is None: imhat *= gausskernhat else: for i in range(nband): thiskern = Gaussian2D(xx, yy, gausspari[i], normalise=norm_kernel) thiskern = np.pad(thiskern[None], padding, mode='constant') thiskernhat = r2c(iFs(thiskern, axes=ax), axes=ax, forward=True, nthreads=nthreads, inorm=0) convkernhat = np.where(np.abs(thiskernhat)>0.0, gausskernhat/thiskernhat, 0.0) imhat[i] *= convkernhat[0] image = Fs(c2r(imhat, axes=ax, forward=False, lastsize=lastsize, inorm=2, nthreads=nthreads), axes=ax)[:, unpad_x, unpad_y] return image, gausskern[:, unpad_x, unpad_y]