raccoon: A Python package for removing wiggle artifacts in the JWST NIRSpec integral field spectroscopy
Anowar J. Shajib · 2025
Read raccoon: A Python package for removing wiggle artifacts in the JWST NIRSpec integral field spectroscopy by Anowar J. Shajib (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2507-13341.txt.
Introduction
Anowar Shajib releases a software tool that cleans wiggles from space telescope spectra in this 2025 paper. The James Webb telescope's near-infrared spectrograph builds 3D data cubes from raw frames. Resampling leaves ripple artifacts, nicknamed wiggles, in each pixel's spectrum. The standard pipeline does not remove them.
The package, named raccoon, models the ripples as a chirp pattern laid over template spectra. It fits the model across the full wavelength range of the original data. Subtracting the fit restores clean spectra while carrying the uncertainties along. Shajib aims the tool at fine spatial studies that the wiggles would otherwise spoil.
Catalog record
| CREATOR | Anowar J. Shajib |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 9 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2507-13341
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
raccoon: A Python package for removing wiggle artifacts in the JWST NIRSpec integral field spectroscopy Anowar J. Shajib Abstract † † margin: DOI: \Url@FormatString Software • Review • Repository • Archive Editor: Pending Editor Reviewers: • @Pending Reviewers Submitted: N/A Published: N/A License Authors of papers retain copyright and release the work under a Creative Commons Attribution 4.0 International License ( CC BY 4.0 ). Summary raccoon is a Python package for removing resampling noise – commonly referred to as “wiggles” – from spaxel-level spectra in datacubes obtained from the JWST Near Infrared Spectrograph’s (NIRSpec) integral field spectroscopy (IFS) mode. These wiggles arise as artifacts during resampling of the 2D raw data into 3D datacubes, due to the point spread function (PSF) being undersampled. The standard JWST data reduction pipeline does not correct for this noise. The wiggle artifacts can significantly degrade the scientific usability of the data, particularly at the spaxel level, undermining the exquisite spatial resolution of NIRSpec. raccoon provides an empirical correction by modeling and removing these artifacts, thereby restoring the fidelity of the extracted spectra. raccoon forward-models the wiggles as a chirp function impacting one or more template spectra that are directly fit to the original data across the entire wavelength range. The best-fit wiggle model is then used to clean the data while propagating the associated uncertainties. Statement of need The JWST NIRSpec’s IFS mode ( Böker et al., 2023 ) enables spatially resolved infrared spectroscopy of astronomical sources with an unprecedented combination of signal-to-noise ratio, redshift coverage, and spatial resolution. However, it suffers from heavy undersampling of the point-spread function, leading to resampling noise that manifests as low-frequency sinusoidal artifacts known as “wiggles.” These artifacts can significantly distort the overall spectral shape, bias line measurements, and compromise kinematic analyses at the single-spaxel level, thereby limiting the scientific potential of the NIRSpec IFU data. raccoon provides a user-friendly, robust, and computationally efficient solution to identify and remove these artifacts, enabling precise studies of galaxy kinematics and early-Universe phenomena that would otherwise be hindered by the presence of wiggles. raccoon has already been used in scientific publications to facilitate robust measurements of stellar kinematics from JWST NIRSpec spectra ( TDCOSMO Collaboration, 2025 ; Shajib et al., 2025 ). Functionality Since the wiggles in the single-spaxel spectra in the reduced JWST NIRSpec datacube are artifacts or resampling noise arising due to undersampling the PSF, dithering can, in principle, mitigate the issue of PSF undersampling and thus the wiggles. However, the commonly adopted 4-point dither pattern is still insufficient to recover the optimal sampling and completely eliminate the wiggles in the rectified datacube ( Law et al., 2023 ). The wiggles are washed out in the spectra summed from multiple spaxels within a sufficiently large aperture (illustrated in Figure 1 ). This provides a basis for making an empirical correction for the wiggles by comparing the single-spaxel spectrum to the one summed within an aperture around it. This principle was also used by previous corrective algorithms, such as in Perna et al. (2023) and in the Python routine WICKED ( Dumont et al., 2025 ). Figure 1: Illustration of the wiggles in the single-spaxel spectrum (blue), which is a manifestation of the resampling noise in the standard-pipeline-reduced datacube due to PSF undersampling. The red spectrum shows the aperture-summed spectrum within a 4-spaxel radius, normalized to match its maximum to that of the single-spaxel one. The illustrated data are of an active galactic nucleus (AGN) from Perna et al. (2023). In raccoon , the wiggle is modeled as a sinusoidal chirp function W(\lambda)=1+A(\lambda)\left[\sin\phi(\lambda)+a_{1}\sin^{2}\phi(\lambda)+a_{2}\sin(3\phi(\lambda))\right], where A(\lambda) is the wavelength-dependent amplitude and \phi(\lambda)=\lambda\,k(\lambda)+\phi_{0} is the phase that depends on a wavelength-dependent wavenumber k(\lambda) . The wiggle’s peaks and troughs can be asymmetrically and symmetrically sharpened (or de-sharpened) by varying the a_{1} and a_{2} parameters, respectively. Given this parametrization for the wiggle, a single-spaxel spectrum D(\lambda) is modeled with M(\lambda)=W(\lambda)\,T(\lambda), where T(\lambda) is a template for the correct spectrum devoid of the wiggles. In raccoon , this template is constructed based on the circular-aperture-summed spectrum C(\lambda) . The template can also optionally include a spectrum S(\lambda) summed from a shell or annulus centered on the corresponding spaxel, following Dumont et al. (2025) . Including the shell-summed spectrum in the template can account for changes in the line shape between the single-spaxel spectrum and the aperture-summed one, for example, in the case of lines broadened by stellar kinematics that can vary across the galaxy ( Dumont et al., 2025 ). The aperture radius and the inner and outer radii of the shell are to be adjusted by the user, as the appropriate values can depend on the source morphology and the astronomical scene. The template is constructed as T(\lambda)=c_{1}\,C(\lambda)+c_{2}\,S(\lambda)+c_{3}\,\lambda^{b}+\sum_{n=0}^{N}p_{n}\,\lambda^{n}, where c_{1},c_{2},c_{3},p_{0},\dots,p_{N} are linear coefficients. Here, the power-law plus polynomial term (i.e., c_{3}\,\lambda^{b}+\sum_{n=0}^{N}p_{n}\,\lambda^{n} ) on the right-hand side models the difference in the continuum between the single-spaxel spectrum and c_{1}\,C(\lambda)+c_{2}\,S(\lambda) . The functions A(\lambda) and k(\lambda) are modeled with B-splines, with the number of knots adjustable by the user. raccoon provides functionality for the user to determine the appropriate number of knots using model selection criteria based on the Bayesian information criterion (BIC) or the minimum a posteriori chi-square metric ( \chi^{2}_{\rm MAP} ). The best-fit values for the linear coefficients (i.e., c_{1},c_{2},c_{3},p_{0},\dots,p_{N} ) and non-linear parameters (i.e., a_{1} , a_{2} , b , and the coefficients of the B-spline basis functions) are determined by minimizing \chi^{2}=\sum_{i}\frac{(D_{i}-M_{i})^{2}}{\sigma_{i}^{2}}, where the index i runs across the wavelength pixels and \sigma_{i} is the associated noise level. Figure 2 illustrates an example of the fitted model to a given spectrum (of an AGN). In this example, raccoon ’s robust performance is demonstrated in fitting the given spectrum while modeling the wiggle signal ( Figure 3 ). The user can mask out regions of the spectrum that have strong features potentially impacting the quality of the fit, or optionally adopt outlier rejection in the fit using the false discovery rate method ( Benjamini & Hochberg, 1995 ) or sigma-clipping. Figure 2: Modeling of the full spectrum (blue in the top panel) based on the template spectra and the wiggles impacting it. The illustrated spectrum is the same one from Figure 1 . The best-fit model is shown in orange and the wiggle-corrected spectrum is shown in black. The bottom panel illustrates the residuals (green) between the original data and the best-fit model. Figure 3: Illustration of the extracted and modeled wiggle signal. The illustrated data points represent D(\lambda)/M(\lambda) based on the best-fit M(\lambda) , and the orange line illustrates the best-fit wiggle model W(\lambda) . The grey points are rejected outliers using the false discovery rate method, and the blue points mark the wavelengths where the data were fit to the model. raccoon enables users to efficiently process multiple spaxels in a datacube, either across the entire field or within a specified spatial region. A user-defined detection threshold for the wiggle signal can be set, ensuring that corrections are only applied to spectra where significant wiggles are present. raccoon offers several advantages over previously available scripts and routines. Earlier tools ( Perna et al., 2023 ; Dumont et al., 2025 ) extract the wiggle signal by subtracting the single-spaxel