Skip to main content

Subtract wisp artifacts in JWST NIRCam images with the non-negative matrix factorization (NMF) algorithm

Project description

Purpose

This package subtracts wisps from JWST/NIRCam images using data-driven, multi-component wisp templates.

Wisps are scattered light artifacts in JWST NIRCam images. They usually appear in the same locations on NIRCam detectors with mild morphological variation between observations. Wisps are a significant source of contamination for objects fainter than 25 AB mag.

We construct detector- and filter-specific wisp templates using the Non-negative Matrix Factorization (NMF) algorithm, based on extensive NIRCam data from JADES and other programs. This algorithm efficiently extracts wisp morphology and its principal modes of variations. The NMF-derived templates yield substantial improvement in wisp subtraction compared to existing single-template approaches

Implementation

Wisp subtraction should be applied at Stage 2 of the JWST data reduction pipeline. For a single NIRCam detector, the runtime is about 0.4 seconds per exposure on one CPU core of an Apple M4 Pro. The runtime is 2 seconds when performing joint fitting with 1/f noise.

The main interface is the fit_wisp function in nmfwisp.py, which returns the best-fit wisp model and its uncertainty. The package distributes the template library directly as package data, so users can run with the default bundled templates immediately after installation.

The bundled templates make the package relatively large (compressed templates are about 80 MB).

The developer directory contains code used to build the wisp template library.

Installation

Install from PyPI:

pip install nmfwisp

For development install from source:

git clone https://github.com/zihaowu-astro/NMFwisp.git
cd NMFwisp
pip install -e .

Example

from astropy.io import fits
import matplotlib.pyplot as plt
import numpy as np

filter_name = 'F150W'
detector_name = 'nrcb4'

# Example file
filename = './data/jw01286001001_07201_00003_nrcb4_rate.fits'
maskfile = './data/jw01286001001_07201_00003_nrcb4_cal_bkgsub_tweak_smask-full.fits'

data = fits.open(filename)['SCI'].data
err  = fits.open(filename)['ERR'].data
mask = fits.open(maskfile)[0].data

# Fit wisps
from nmfwisp import fit_wisp
wisp, wisp_e = fit_wisp(
    data, err, mask,
    detector_name=detector_name,
    filter_name=filter_name,
    correct_1f=False
)

To use a custom template library path instead of bundled templates:

wisp, wisp_e = fit_wisp(
    data, err, mask,
    wisp_path='/path/to/templates',
    detector_name=detector_name,
    filter_name=filter_name,
    correct_1f=False
)

Visualization of the wisp subtraction result:

data0 = np.nan_to_num(data, nan=0.0) # remove nan values
fig, ax = plt.subplots(1, 3, figsize=(10, 4))
vmin, vmax = np.nanpercentile(data, 5), np.nanpercentile(data, 95)
ax[0].imshow(data0, origin='lower', vmin=vmin, vmax=vmax)
ax[0].set_title('Data')
ax[1].imshow(data0 - wisp, origin='lower', vmin=vmin, vmax=vmax)
ax[1].set_title('Data - WISP')
ax[2].imshow(wisp, origin='lower', vmin=0, vmax=np.nanpercentile(wisp, 99))
ax[2].set_title('WISP')
for a in ax:
    a.axis('off')
plt.tight_layout()
plt.show()

Wisp Morphology

Demonstration of wisp morphology in all affected NIRCam detectors in the F150W band

Citation

If you use this code, please reference this paper:

@ARTICLE{2026arXiv260115958W,
       author = {{Wu}, Zihao and {Johnson}, Benjamin D. and {Eisenstein}, Daniel J. and {Cargile}, Phillip and {Hainline}, Kevin and {Hausen}, Ryan and {Rinaldi}, Pierluigi and {Robertson}, Brant E. and {Tacchella}, Sandro and {Williams}, Christina C. and {Willmer}, Christopher N.~A.},
        title = "{JWST Advanced Deep Extragalactic Survey (JADES) Data Release 5: Wisp Subtraction with the Non-negative Matrix Factorization Algorithm}",
      journal = {arXiv e-prints},
     keywords = {Instrumentation and Methods for Astrophysics, Astrophysics of Galaxies},
         year = 2026,
        month = jan,
          eid = {arXiv:2601.15958},
        pages = {arXiv:2601.15958},
          doi = {10.48550/arXiv.2601.15958},
archivePrefix = {arXiv},
       eprint = {2601.15958},
 primaryClass = {astro-ph.IM},
       adsurl = {https://ui.adsabs.harvard.edu/abs/2026arXiv260115958W},
      adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nmfwisp-1.1.0.tar.gz (91.7 MB view details)

Uploaded Source

File details

Details for the file nmfwisp-1.1.0.tar.gz.

File metadata

  • Download URL: nmfwisp-1.1.0.tar.gz
  • Upload date:
  • Size: 91.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nmfwisp-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3a49378ce1f3e8d51ae900c1139a20d66189a9695a8d68de180909ac210ab913
MD5 c2fad41a7046c5b8bdf84268d89e9282
BLAKE2b-256 120a12158408fbdb658c7c5635060f7b351444a1160c785724c7258db270fc0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nmfwisp-1.1.0.tar.gz:

Publisher: publish-to-pypi.yml on zihaowu-astro/NMFwisp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page