healpix_analyse.fft_local#
Fast local 2-D FFTs for data sampled on HEALPix cells.
The HEALPix cell centres are projected onto a square gnomonic grid. The
geometry is computed once by LocalFFT; subsequent projections and
transforms use differentiable PyTorch scatter/gather operations.
The FFT itself is exactly invertible on the projected grid. The default HEALPix -> grid -> HEALPix round trip is approximate because it uses fast bilinear gridding in both directions.
Classes#
A reusable local flat-sky FFT for a set of NESTED HEALPix cells. |
Functions#
Module Contents#
- class healpix_analyse.fft_local.LocalFFT(cell_ids: ArrayLike, level: int, *, ellipsoid: str = 'sphere', max_patch_radius_deg: float = 10.0, pixel_size_rad: float | None = None, grid_size: int | None = None, norm: str = 'ortho', dtype: torch.dtype = torch.float32, device: str | torch.device | None = None)[source]#
Bases:
torch.nn.ModuleA reusable local flat-sky FFT for a set of NESTED HEALPix cells.
- Parameters:
cell_ids (
array-like,shape [N]) – Unique HEALPix cell identifiers in NESTED ordering.level (
int) – HEALPix level, withnside = 2**level.ellipsoid (
str, default"sphere") – Geometry passed tohealpix_geowhen locating cell centres.max_patch_radius_deg (
float, default10) – Maximum angular distance of a cell centre from the spherical patch centre. A single gnomonic plane is rejected above this radius.pixel_size_rad (
float, optional) – Grid spacing in gnomonic coordinates. The default is the square root of the HEALPix pixel area,sqrt(pi/3) / nside.grid_size (
int, optional) – Side of the square projected grid. By default, the smallest power of two that covers the patch with a one-pixel margin is used.norm (
{"forward", "backward", "ortho"}, default"ortho") – Normalisation passed totorch.fft.fft2()andifft2.dtype (
torch.dtype, defaulttorch.float32) – Real dtype used for geometry and real-valued input maps.device (
torch.deviceorstr, optional) – Device of the cached projection geometry. CUDA is selected when it is available, otherwise CPU.
Notes
The tangent frame is built from three-dimensional unit vectors, not from longitude/latitude differences. It is therefore well defined at both geographic poles and across the 0/360-degree meridian.
For torch inputs, gradients propagate through projection, FFT, IFFT and back-projection with respect to the data. The discrete HEALPix geometry is fixed and is not differentiable with respect to
cell_ids.- level#
- nside#
- ellipsoid = ''#
- max_patch_radius_deg#
- norm = 'ortho'#
- dtype = Ellipsis#
- cdtype = Ellipsis#
- n_cells#
- pixel_size_rad#
- grid_size = 0#
- grid_shape#
- centre_lon_deg#
- centre_lat_deg#
- patch_radius_deg#
- property device: torch.device#
Current device of the cached geometry buffers.
- property coverage_mask: torch.Tensor#
Boolean
[grid_size, grid_size]mask reached by input cells.
- property grid_density: torch.Tensor#
Accumulated interpolation weight on the projected square grid.
- project(data: ArrayLike) ArrayLike[source]#
Bilinearly scatter HEALPix values onto the cached square grid.
- unproject(grid: ArrayLike) ArrayLike[source]#
Bilinearly sample a projected grid at the HEALPix cell centres.
- fft(data: ArrayLike) ArrayLike[source]#
Project HEALPix data and compute its unshifted two-dimensional FFT.
- ifft(spectrum: ArrayLike, *, real_output: bool = True) ArrayLike[source]#
Compute the inverse FFT and sample it at the input HEALPix cells.
This is a fast approximate inverse of
fft(). Setreal_output=Falsewhen transforming genuinely complex-valued data.
- ps(spectrum: ArrayLike, *, n_bins: int | None = None, include_corners: bool = False) tuple[ArrayLike, ArrayLike][source]#
Compute a circularly averaged 1-D power spectrum from a 2-D FFT.
- Parameters:
spectrum (
numpy.ndarrayortorch.Tensor,shape [...,grid_size,grid_size]) – Unshifted Fourier coefficients, normally returned byfft().n_bins (
int, optional) – Number of equally spaced radial-frequency bins. The default isgrid_size // 2when excluding corners.include_corners (
bool, defaultFalse) – If False, stop at the axis Nyquist frequency so every annulus is fully contained in the Fourier grid. If True, include the corner modes up tosqrt(2)times the axis Nyquist frequency; outer annuli are then only partially sampled.
- Returns:
frequency (
numpy.ndarrayortorch.Tensor,shape [n_bins]) – Bin centres in cycles per gnomonic tangent unit. With the default grid spacing these are approximately cycles per radian.power (
numpy.ndarrayortorch.Tensor,shape [...,n_bins]) – Mean value ofabs(spectrum)**2in each circular annulus.
Notes
No additional FFT normalisation, mean removal, mask correction or apodization is applied. These choices belong to the spectral-analysis workflow and should be performed before calling this method when required.
- healpix_analyse.fft_local.fft(cell_ids: ArrayLike, level: int, data: ArrayLike, *, return_transform: bool = False, **transform_kwargs)[source]#
Build a
LocalFFTand compute a local 2-D FFT.Use
return_transform=Trueto return(spectrum, transform). Reusing that transform for IFFT and additional maps avoids rebuilding geometry.
- healpix_analyse.fft_local.ifft(spectrum: ArrayLike, transform: LocalFFT | None = None, *, cell_ids: ArrayLike | None = None, level: int | None = None, real_output: bool = True, **transform_kwargs) ArrayLike[source]#
Compute a local inverse FFT using cached or newly built geometry.
Prefer passing the
LocalFFTreturned byfft(). Alternatively provide bothcell_idsandlevelto rebuild the deterministic grid.
- healpix_analyse.fft_local.ps(spectrum: ArrayLike, transform: LocalFFT | None = None, *, pixel_size_rad: float | None = None, n_bins: int | None = None, include_corners: bool = False) tuple[ArrayLike, ArrayLike][source]#
Compute a circular 1-D power spectrum from a square unshifted 2-D FFT.
Pass a
LocalFFTto use its grid spacing and shape validation. For a standalone Fourier array, providepixel_size_rad; it defaults to 1, in which case frequencies are expressed in cycles per grid-spacing unit.