Spelunker: A quick-look Python pipeline for JWST NIRISS FGS Guide Star Data

The James Webb Space Telescope produces some of the highest sensitivity imaging of the cosmos across all instruments. One of them, the NIRISS Fine Guidance Sensor, provides guide star imaging with a passband of 0.6 to 5 microns through two separate channels, each with a 2.3' x 2.3' field of view (FOV) and a sampling rate of 64 ms$-$data that is taken in parallel and is thus available for every JWST observing program. While the onboard system uses guide stars to provide information to the attitude control system (ACS), which stabilizes the observatory, the astronomical community can also use the data products associated with these 64 ms cadence images as science products. Usages range from studying guide star photometry in search of transient phenomena to using these data to identify and investigate technical anomalies that might occur during scientific observations with the rest of the JWST instruments. Despite this wide range of possible usages, these data products are not straightforward to manipulate and analyze, and there is no publicly available package to download, investigate, and research guide star data. Spelunker is a Python library that was developed to enable access to these guide star data products and their analysis.

In addition, spelunker provides visualization and analysis tools to study these products in detail, including the incorporation of JWST engineering telemetry, which can be used to put the JWST FGS data products in context with other observatory variables that might help explain data patterns both in the primary science data products and in the JWST FGS data itself.The library also crossreferences, tracks and stores guide star metadata for the user.This metadata includes information such as the GAIA ID of the guide star, coordinates, and magnitudes, among others.This pipeline empowers users to study guide star data with applications like technical anomaly detection and time-domain astronomy at a high 64 ms cadence.Existing pipeline such as jwst provides the structure for calibrataing NIRISS/FGS, NIRSpec, NIRCam, and MIRI data, such as with JWST Datamodels.spelunker tools are engineered to explore FGS guide stars in two main categories: as a method to detect technical anomalies in JWST data, and as a pipeline to study time-domain astronomy with guide stars.

Statement of need
The James Webb Space Telescope (Gardner et al., 2023) produces some of the highest sensitivity imaging of the cosmos across all instruments.One of them, the NIRISS Fine Guidance Sensor (Doyon et al., 2012), provides guide star imaging with a passband of 0.6 to 5 microns through two separate channels, each with a 2.3 ′ × 2.3 ′ field of view (FOV) and a sampling rate of 64 ms-data that is taken in parallel and is thus available for every JWST observing program.While the onboard system uses guide stars to provide information to the attitude control system (ACS) which stabilizes the observatory, the astronomical community can also use the data products associated with these 64 ms cadence images as science products.Usages range from studying guide star photometry in search of transient phenomena to using these data to identify and investigate technical anomalies that might occur during scientific observations with the rest of the JWST instruments.Despite this wide range of possible usages, these data products are not straightforward to manipulate and analyze, and there is no publicly available package to download, investigate, and research guide star data.spelunker is a Python library that was developed to enable access to these guide star data products and their analysis.

Overview of Spelunker
spelunker allows anyone to download and utilize fine guidence guide star data from the JWST.Users can use the following lines of code to download GS-FG data into an object: spk = spelunker.load(pid=1534)spelunker uses astroquery and MAST (Marston et al., 2018) to find and download GS-FG FITS files.There are several functions that can manipulate and analyze guide star data: • gauss2d_fit A spatial Gaussian fit is applied to each of the frames loaded into the spk object.The Gaussian will fit the amplitude, pixel coordinates, pixel standard deviations, the model orientation, and the background offset.A diagram of Gaussian fitting parameters is shown in Figure 1.The Gaussian measurements are then stored in spk.gaussfit_results as an astropy table.Fitting spatial Gaussians to your guide star data can allow you to reveal technical anomalies that might be confused with science data from NIRISS or other JWST instruments and within the guide star flux time series (see Figure 2).The data has no significant features.Middle -The same time series after applying optimize_photometry to the guide star light curve.There are now prominent drops in the flux, which were previously unseen with the raw time series data.Bottom -Gaussian fitted x pixel coordinate and y pixel coordinate for each frame in this section of time series data.The guide star shifts around in this time series, highlighting the core function of the ACS.
• mnemonics Users can access JWST engineering telemetry and mnemonics using the mnemonics function.With a MAST API token, any mnemonic is accessible.High-gain antenna (HGA) movement and NIRISS filter wheel current are two examples of events that overplot science data to identify technical events on the telescope.Anomalies detection in guide star data or data from NIRISS, NIRCAM, NIRSpec, and MIRI is one of the primary capabilities of this function.Using mnemonics requires the additional installation of the jwstuser library.
• periodogram This function uses the Lomb-Scarle periodogram (Lomb, 1976;Scargle, 1982) to detect periodicities in guide star Gaussian fits.Periods in Gaussian fitted parameters like x and y pixel coordinates highlight systematics for an entire PID.
• optimize_photometry optimize_photometry extracts the highest SNR pixels to optimize raw guide star photometry loaded from spelunker.Figure 2 demonstrates that optimize_photometry reveals more information from guide star time series than that produced by the sum of counts in each frame.
With the mentioned tools, spelunker utilizes object oriented programming (OOP) to store handy variables and its outputs, for instance, 1D and 2D time series, guide star time arrays, and JWST data models.Running gauss2d_fit, periodogram, and mnemonics will store their outputs in accessible attributes.Useful properties of the guide star are stored in these attributes (for instance, guide star galactic coordinates, GAIA ID, and stellar magnitudes).
There are various plotting and visualization tools integrated into spelunker's workflow.One useful function is timeseries_binned_plot, which automatically plots a binned time series.The functions gauss2d_fit, periodogram, and mnemonics have matplotlib axes returned for straightforward plotting.Animations of spatial time series are another visualization tool covered under spelunker.Of course, users have the option to use the guide star data and results from attributes to generate plots.

Figure 1 :
Figure 1: There are seven parameters gauss2d_fit measures: amplitude (counts of the guide star), x pixel coordinate, y pixel coordinate, the x and y standard deviations, theta (orientation of the Gaussian model), and the offset (the background counts).This diagram visualizes what each parameter represents on the Gaussian model.

Figure 2 :
Figure 2: A snippet from the guide star time series from Cycle 1 GO Program ID 1803, observation 1 and visit 1. Top -The guide star time series of PID 1803 after loading it into spelunker using timeseries_binned_plot.The time series uses the sum of counts in each guide star fine guidance (GS-FG) frame.The data has no significant features.Middle -The same time series after applying optimize_photometry to the guide star light curve.There are now prominent drops in the flux, which were previously unseen with the raw time series data.Bottom -Gaussian fitted x pixel coordinate and y pixel coordinate for each frame in this section of time series data.The guide star shifts around in this time series, highlighting the core function of the ACS.