def map2alm(maps, lmax=None, mmax=None, iter=3, pol=True, use_weights=False, regression=True, datapath=None): """Computes the alm of an Healpix map. Parameters ---------- maps : array-like, shape (Npix,) or (n, Npix) The input map or a list of n input maps. lmax : int, scalar, optional Maximum l of the power spectrum. Default: 3*nside-1 mmax : int, scalar, optional Maximum m of the alm. Default: lmax iter : int, scalar, optional Number of iteration (default: 3) pol : bool, optional If True, assumes input maps are TQU. Output will be TEB alm's. (input must be 1 or 3 maps) If False, apply spin 0 harmonic transform to each map. (input can be any number of maps) If there is only one input map, it has no effect. Default: True. use_weights: bool, scalar, optional If True, use the ring weighting. Default: False. regression: bool, scalar, optional If True, subtract map average before computing alm. Default: True. datapath : None or str, optional If given, the directory where to find the weights data. Returns ------- alms : array or tuple of array alm or a tuple of 3 alm (almT, almE, almB) if polarized input. Notes ----- The pixels which have the special `UNSEEN` value are replaced by zeros before spherical harmonic transform. They are converted back to `UNSEEN` value, so that the input maps are not modified. Each map have its own, independent mask. """ info = maptype(maps) if info < 0: raise TypeError("Input must be a map or a sequence of maps") if pol or info in (0, 1): alms = _sphtools.map2alm( maps, niter=iter, regression=regression, datapath=datapath, use_weights=use_weights, lmax=lmax, mmax=mmax ) else: # info >= 2 and pol is False : spin 0 spht for each map alms = [ _sphtools.map2alm( mm, niter=iter, regression=regression, datapath=datapath, use_weights=use_weights, lmax=lmax, mmax=mmax ) for mm in m ] return alms
def map2alm(maps, lmax = None, mmax = None, iter = 3, pol = True, use_weights = False, regression = True, datapath = None): """Computes the alm of an Healpix map. Parameters ---------- maps : array-like, shape (Npix,) or (n, Npix) The input map or a list of n input maps. lmax : int, scalar, optional Maximum l of the power spectrum. Default: 3*nside-1 mmax : int, scalar, optional Maximum m of the alm. Default: lmax iter : int, scalar, optional Number of iteration (default: 3) pol : bool, optional If True, assumes input maps are TQU. Output will be TEB alm's. (input must be 1 or 3 maps) If False, apply spin 0 harmonic transform to each map. (input can be any number of maps) If there is only one input map, it has no effect. Default: True. use_weights: bool, scalar, optional If True, use the ring weighting. Default: False. regression: bool, scalar, optional If True, subtract map average before computing alm. Default: True. datapath : None or str, optional If given, the directory where to find the weights data. Returns ------- alms : array or tuple of array alm or a tuple of 3 alm (almT, almE, almB) if polarized input. Notes ----- The pixels which have the special `UNSEEN` value are replaced by zeros before spherical harmonic transform. They are converted back to `UNSEEN` value, so that the input maps are not modified. Each map have its own, independent mask. """ info = maptype(maps) if info < 0: raise TypeError("Input must be a map or a sequence of maps") if pol or info in (0, 1): alms = _sphtools.map2alm(maps, niter = iter, regression = regression, datapath = datapath, use_weights = use_weights, lmax = lmax, mmax = mmax) else: # info >= 2 and pol is False : spin 0 spht for each map alms = [_sphtools.map2alm(mm, niter = iter, regression = regression, datapath = datapath, use_weights = use_weights, lmax = lmax, mmax = mmax) for mm in m] return alms
def smoothing( maps, fwhm=0.0, sigma=None, invert=False, pol=True, iter=3, lmax=None, mmax=None, use_weights=False, regression=True, datapath=None, ): """Smooth a map with a Gaussian symmetric beam. Parameters ---------- maps : array or sequence of 3 arrays Either an array representing one map, or a sequence of 3 arrays representing 3 maps, accepts masked arrays fwhm : float, optional The full width half max parameter of the Gaussian [in radians]. Default:0.0 sigma : float, optional The sigma of the Gaussian [in radians]. Override fwhm. invert : bool, optional If True, alms are divided by Gaussian beam function (un-smooth). Otherwise, alms are multiplied by Gaussian beam function (smooth). Default: False. pol : bool, optional If True, assumes input maps are TQU. Output will be TQU maps. (input must be 1 or 3 alms) If False, each map is assumed to be a spin 0 map and is treated independently (input can be any number of alms). If there is only one input map, it has no effect. Default: True. iter : int, scalar, optional Number of iteration (default: 3) lmax : int, scalar, optional Maximum l of the power spectrum. Default: 3*nside-1 mmax : int, scalar, optional Maximum m of the alm. Default: lmax use_weights: bool, scalar, optional If True, use the ring weighting. Default: False. regression: bool, scalar, optional If True, subtract map average before computing alm. Default: True. datapath : None or str, optional If given, the directory where to find the weights data. Returns ------- maps : array or list of 3 arrays The smoothed map(s) """ if not cb.is_seq(maps): raise TypeError("maps must be a sequence") # save the masks of inputs masks = pixelfunc.mask_bad(maps) if cb.is_seq_of_seq(maps): nside = pixelfunc.npix2nside(len(maps[0])) n_maps = len(maps) else: nside = pixelfunc.npix2nside(len(maps)) n_maps = 0 if pol or n_maps in (0, 1): # Treat the maps together (1 or 3 maps) alms = map2alm( maps, lmax=lmax, mmax=mmax, iter=iter, pol=pol, use_weights=use_weights, regression=regression, datapath=datapath, ) smoothalm(alms, fwhm=fwhm, sigma=sigma, invert=invert, inplace=True) output_map = alm2map(alms, nside, pixwin=False) else: # Treat each map independently (any number) output_map = [] for m, mask in zip(maps, masks): alm = map2alm(maps, iter=iter, pol=pol, use_weights=use_weights, regression=regression, datapath=datapath) smoothalm(alm, fwhm=fwhm, sigma=sigma, invert=invert, inplace=True) output_map.append(alm2map(alm, nside, pixwin=False)) if pixelfunc.maptype(output_map) == 0: output_map[masks.flatten()] = UNSEEN else: for m, mask in zip(output_map, masks): m[mask] = UNSEEN return output_map
def smoothing(maps, fwhm=0.0, sigma=None, invert=False, pol=True, iter=3, lmax=None, mmax=None, use_weights=False, regression=True, datapath=None): """Smooth a map with a Gaussian symmetric beam. Parameters ---------- maps : array or sequence of 3 arrays Either an array representing one map, or a sequence of 3 arrays representing 3 maps, accepts masked arrays fwhm : float, optional The full width half max parameter of the Gaussian [in radians]. Default:0.0 sigma : float, optional The sigma of the Gaussian [in radians]. Override fwhm. invert : bool, optional If True, alms are divided by Gaussian beam function (un-smooth). Otherwise, alms are multiplied by Gaussian beam function (smooth). Default: False. pol : bool, optional If True, assumes input maps are TQU. Output will be TQU maps. (input must be 1 or 3 alms) If False, each map is assumed to be a spin 0 map and is treated independently (input can be any number of alms). If there is only one input map, it has no effect. Default: True. iter : int, scalar, optional Number of iteration (default: 3) lmax : int, scalar, optional Maximum l of the power spectrum. Default: 3*nside-1 mmax : int, scalar, optional Maximum m of the alm. Default: lmax use_weights: bool, scalar, optional If True, use the ring weighting. Default: False. regression: bool, scalar, optional If True, subtract map average before computing alm. Default: True. datapath : None or str, optional If given, the directory where to find the weights data. Returns ------- maps : array or list of 3 arrays The smoothed map(s) """ if not cb.is_seq(maps): raise TypeError("maps must be a sequence") # save the masks of inputs masks = pixelfunc.mask_bad(maps) if cb.is_seq_of_seq(maps): nside = pixelfunc.npix2nside(len(maps[0])) n_maps = len(maps) else: nside = pixelfunc.npix2nside(len(maps)) n_maps = 0 if pol or n_maps in (0, 1): # Treat the maps together (1 or 3 maps) alms = map2alm(maps, lmax=lmax, mmax=mmax, iter=iter, pol=pol, use_weights=use_weights, regression=regression, datapath=datapath) smoothalm(alms, fwhm=fwhm, sigma=sigma, invert=invert, inplace=True) output_map = alm2map(alms, nside, pixwin=False) else: # Treat each map independently (any number) output_map = [] for m, mask in zip(maps, masks): alm = map2alm(maps, iter=iter, pol=pol, use_weights=use_weights, regression=regression, datapath=datapath) smoothalm(alm, fwhm=fwhm, sigma=sigma, invert=invert, inplace=True) output_map.append(alm2map(alm, nside, pixwin=False)) if pixelfunc.maptype(output_map) == 0: output_map[masks.flatten()] = UNSEEN else: for m, mask in zip(output_map, masks): m[mask] = UNSEEN return output_map