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.

  1. Projection: Strictly supports RA---TAN-SIP / DEC--TAN-SIP (gnomonic).
  2. Units: CRVAL inputs are assumed to be in Degrees.
  3. LONPOLE: Assumed to be 180.0 degrees (standard for TAN).
  4. SIP: Supports A_ORDER, B_ORDER, AP_ORDER, BP_ORDER distortions.
    • 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.
  5. Origin: all_pix2world and all_world2pix take origin argument (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_world2pix is always serial due to Newton-Raphson thread divergence. Default is PARALLEL_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

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

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.