ioutils.wcs.FastTanSipWCS
ioutils.wcs.FastTanSipWCS(
hdr_dict,
parallel_threshold=PARALLEL_THRESHOLD_DEFAULT,
)Lightweight, Numba-optimized WCS implementation for tangent (TAN) projection with SIP distortion.
This class is designed as a replacement for astropy.wcs.WCS specifically for handling SPHEREx-like WCS headers where speed is critical. Initial purpose was when we have >>10^3 headers already extracted as dictionaries or other DB (parquet, SQL) and need fast WCS constructions and transformations (typical for modern survey data).
Assumptions & Limitations
If any of these assumptions are violated, results should not be trusted.
- Projection: Strictly supports
RA---TAN-SIP/DEC--TAN-SIP(gnomonic). - Units:
CRVALinputs are assumed to be in Degrees. - LONPOLE: Assumed to be 180.0 degrees (standard for TAN).
- SIP: Supports
A_ORDER,B_ORDER,AP_ORDER,BP_ORDERdistortions.- A/B matrices apply to relative pixel coordinates (u, v).
- AP/BP matrices apply to intermediate world coordinates (for inverse).
- Zero-padding optimization is used for SIP matrices.
- Origin:
all_pix2worldandall_world2pixtakeoriginargument (0-based or 1-based pixel indexing).- Internal kernels use 1-based (FITS standard) logic.
Performance
See bench_fast_wcs.py. Tested on MBP 14” [2024, macOS 15.2, M4Pro(8P+4E/G20c/N16c/48G)]:
- Construction from header dict: ~50x faster than Astropy WCS.
- Uses Numba-compiled kernels with Fused 2D Horner’s Scheme for SIP evaluation.
all_pix2world: several times faster than Astropy (10ms for 1M points).all_world2pix: several times faster than Astropy (300ms for 1M points; Slower than all_pix2world, as it uses a Newton-Raphson iterative solver for precision <0.001 pix).
Parameters
hdr_dict : dict-
Dictionary-like object containing WCS header keywords.
parallel_threshold : int, default = PARALLEL_THRESHOLD_DEFAULT-
Threshold for switching to parallel processing in batch transformations. For input arrays smaller than this size, a serial loop is used to avoid parallel overhead. Applies only to
all_pix2world.all_world2pixis always serial due to Newton-Raphson thread divergence. Default isPARALLEL_THRESHOLD_DEFAULT.
Methods
| Name | Description |
|---|---|
| all_pix2world | Convert pixel coordinates to world coordinates. |
| all_world2pix | Convert world coordinates to pixel coordinates. |
| to_astropy | Convert this FastTanSipWCS object to an astropy.wcs.WCS object. |
all_pix2world
ioutils.wcs.FastTanSipWCS.all_pix2world(x, y, origin)Convert pixel coordinates to world coordinates.
Parameters
x : array-like-
The pixel coordinates.
y : array-like-
The pixel coordinates.
origin : int-
The origin of the pixel coordinates (0 or 1).
Returns
: array-like-
The world coordinates (RA, Dec) corresponding to the input pixels.
Notes
Mimics the interface of astropy.wcs.WCS.all_pix2world.
all_world2pix
ioutils.wcs.FastTanSipWCS.all_world2pix(ra, dec, origin)Convert world coordinates to pixel coordinates.
Parameters
ra : array-like-
The world coordinates (RA, Dec).
dec : array-like-
The world coordinates (RA, Dec).
origin : int-
The origin of the pixel coordinates (0 or 1).
Returns
: array-like-
The pixel coordinates corresponding to the input world coordinates.
Notes
Mimics the interface of astropy.wcs.WCS.all_world2pix.
to_astropy
Convert this FastTanSipWCS object to an astropy.wcs.WCS object.
Returns
wcs : astropy.wcs.WCS-
The equivalent Astropy WCS object.