How to use the pixell.fft.ifft function in pixell

To help you get started, we’ve selected a few pixell examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simonsobs / pixell / pixell / enmap.py View on Github external
def ifft(emap, omap=None, nthread=0, normalize=True):
	"""Performs the 2d iFFT of the complex enmap given, and returns a pixel-space enmap."""
	res = samewcs(enfft.ifft(emap,omap,axes=[-2,-1],nthread=nthread, normalize=False), emap)
	if normalize: res /= np.prod(emap.shape[-2:])**0.5
	if normalize in ["phy","phys","physical"]: res /= emap.pixsize()**0.5
	return res
github simonsobs / pixell / pixell / enmap.py View on Github external
if method == "fft":
		omap  = zeros(oshape, owcs, map.dtype)
		fimap = enfft.fft(map, axes=(-2,-1))
		fomap = np.zeros(oshape, fimap.dtype)
		# copy over all 4 quadrants. This would have been a single operation if the
		# fourier center had been in the middle. This could be acieved using fftshift,
		# but that would require two extra full-array shifts
		cny, cnx = np.minimum(map.shape[-2:], oshape[-2:])
		hny, hnx = cny//2, cnx//2
		fomap[...,:hny,        :hnx       ] = fimap[...,:hny,        :hnx       ]
		fomap[...,:hny,        -(cnx-hnx):] = fimap[...,:hny,        -(cnx-hnx):]
		fomap[...,-(cny-hny):, :hnx       ] = fimap[...,-(cny-hny):, :hnx       ]
		fomap[...,-(cny-hny):, -(cnx-hnx):] = fimap[...,-(cny-hny):, -(cnx-hnx):]
		if np.any(off != 0):
			fomap[:] = enfft.shift(fomap, off, axes=(-2,-1), nofft=True)
		omap[:] = enfft.ifft(fomap, axes=(-2,-1)).real
		# Normalize
		omap /= map.shape[-2]*map.shape[-1]
	elif method == "spline":
		opix  = pixmap(oshape) - off[:,None,None]
		ipix  = opix * (np.array(map.shape[-2:],float)/oshape[-2:])[:,None,None]
		omap  = ndmap(map.at(ipix, unit="pix", mode=mode, order=order), owcs)
	else:
		raise ValueError("Invalid resample method '%s'" % method)
	return omap
github simonsobs / pixell / pixell / resample.py View on Github external
def resample_fft_simple(d, n, ngroup=100):
	"""Resample 2d numpy array d via fourier-reshaping along
	last axis."""
	nold = d.shape[1]
	if n == nold: return d
	res  = np.zeros([d.shape[0],n],dtype=d.dtype)
	dn   = n-nold
	for di in range(0, d.shape[0], ngroup):
		fd = fft.fft(d[di:di+ngroup])
		if n < nold:
			fd = np.concatenate([fd[:,:n//2],fd[:,n//2-dn:]],1)
		else:
			fd = np.concatenate([fd[:,:nold//2],np.zeros([len(fd),n-nold],fd.dtype),fd[:,nold//2:]],-1)
		res[di:di+ngroup] = fft.ifft(fd, normalize=True).real
	del fd
	res *= float(n)/nold
	return res
github simonsobs / pixell / pixell / enmap.py View on Github external
def _convolute_sym(a,b):
	sa = np.concatenate([a,a[:,-2:0:-1]],-1)
	sb = np.concatenate([b,b[:,-2:0:-1]],-1)
	fa = enfft.rfft(sa)
	fb = enfft.rfft(sb)
	sa = enfft.ifft(fa*fb,sa,normalize=True)
	return sa[:,:a.shape[-1]]