---
title: 'HST_Notebooks: HST Data Reduction Pipeline'
url: https://www.emergentmind.com/topics/hst_notebooks-github-repository
type: topic
---

# HST_Notebooks: HST Data Reduction Pipeline

The HST_Notebooks GitHub repository, maintained by the Space Telescope Science Institute, provides a suite of Jupyter notebooks demonstrating methods for the reduction and analysis of astronomical datasets from the Hubble Space Telescope (HST). One of its prominent workflows, detailed in Alam et al. “Analyzing Exoplanet Transits Observed with the WFC3/UVIS G280 Grism” [2511.09694], implements a complete, modular reduction pipeline for time-series exoplanet transit observations with the WFC3/UVIS G280 grism. The notebook, available at https://github.com/spacetelescope/hst_notebooks/tree/main/notebooks/WFC3/uvis_g280_transit, illustrates every step necessary to derive normalized broadband and spectroscopic light curves suitable for planetary transmission spectroscopy.

## 1. Objectives and Repository Structure

The central objective of the G280 transit notebook is to present an end-to-end data reduction workflow, converting calibrated ("flt") HST/WFC3 exposures taken with the G280 grism into science-ready light curves. This supports limb-darkened transit fitting and planetary transmission spectrum analysis. The structure of the example directory under `notebooks/WFC3/uvis_g280_transit/` highlights the modularity:

| File/Directory                 | Contents                                                                                  |
|-------------------------------|------------------------------------------------------------------------------------------|
| requirements.txt               | List of pinned Python dependencies (astroquery, numpy, scipy, astropy, matplotlib, etc.) |
| g280_transit_tools.py          | Modular helper routines for each processing stage                                        |
| G280_Exoplanet_Transits.ipynb  | The main tutorial and workflow notebook                                                  |

The repository is organized to facilitate both didactic review and modular re-use in research pipelines.

## 2. Computational Environment and Data Acquisition

Environment preparation is achieved by cloning the repository and installing all required Python packages via the provided `requirements.txt`. Dependencies include, but are not limited to, `astroquery`, `numpy`, `scipy`, `astropy`, `matplotlib`, `GRISMCONF`, and `wfc3tools`. Data retrieval leverages Astroquery for seamless, programmatic access to HST/MAST, specifically downloading G280-calibrated (`FLT`) files for targets such as HAT-P-41b.

Example setup:
```shell
git clone https://github.com/spacetelescope/hst_notebooks.git
cd hst_notebooks/notebooks/WFC3/uvis_g280_transit
pip install -r requirements.txt
```

The downloaded files populate a local `data/flt/` directory, with subsequent processing outputs organized under `data/flt_clean/` (post background/cosmic-ray cleaning) and `data/flt_full/` (full-frame embedded images). The workflow requires users to also acquire G280 sky frames for both UVIS1 & UVIS2 detectors from the STScI grism-resources site.

## 3. Data Reduction Methodology: Preprocessing and Cleaning

This workflow emphasizes accurate photometric recovery and outlier mitigation through several preprocessing steps.

### Background Subtraction
Rather than utilizing local histogram-based approaches, the pipeline applies a median-stacked, source-masked G280 sky image, scaled to the exposure’s median flux. For each exposure $D_i$:
- Compute $M_i = \mathrm{median}(D_i)$.
- Compute scaled sky frame $S_i = S \times (M_i / \mathrm{median}(S))$ where $S$ is the atlas sky image.
- Subtract: $D_i^\mathrm{bkg} = D_i - S_i$.

The use of this atlas approach is intended to provide superior precision over local pixel-based modeling.

### Cosmic Ray Correction
Cosmic ray (CR) correction is implemented as a two-stage process:
- **Temporal Correction:** For each pixel, if $|D_i^\mathrm{bkg}(x, y) - \mathrm{median}_t[D^\mathrm{bkg}(x, y)]| > 4 \sigma_\mathrm{pixel}$, replace with the cube median at that position.
- **Spatial Correction:** For individual frames, apply a $5 \times 5$ median filter, replacing any pixel deviating by $>4\sigma$ from its local neighborhood.

Both steps yield cleaned science frames and Boolean masks indicating all pixel replacements.

## 4. Astrometric Alignment and Spectral Trace Analysis

The G280 grism data are acquired as subarray images, necessitating their embedding into full $4096 \times 2051$ UVIS2 detector frames (using header keywords NAXIS, LTV1, LTV2). This reconstitution enables robust trace and dispersion mapping.

Spectral trace fitting leverages polynomial coefficients supplied by the GRISMCONF reference (typically of the form $x(\lambda) = \sum_i a_i (\lambda - \lambda_\mathrm{ref})^i$, $y(\lambda) = \sum_j b_j (\lambda - \lambda_\mathrm{ref})^j$), yielding per-frame arrays of trace coordinates and wavelength solutions. The procedures produce both the pixel-wise trace and calibration arrays: $\text{trace}_x$, $\text{trace}_y$, $\lambda$ (wavelength per pixel), and a sensitivity array for count-to-flux conversion.

## 5. Spectral Extraction, Time-series Construction, and Light Curve Generation

### 1D Spectral Extraction
For each full-frame exposure and spectral order, a 1D spectrum is extracted by summing pixels along the cross-dispersion ($y$) direction, for each column $k$ lying on $x_\mathrm{trace}(k)$:
$$
F(\lambda_k) = \sum_{y = y_\mathrm{trace}(k) - \Delta y}^{y_\mathrm{trace}(k) + \Delta y} D^\mathrm{full}(x = k, y)
$$
where $\Delta y$ defines the half-aperture (e.g., $10$ pixels).

### Time-series and Light Curve Formation
Looping the extraction process over all cleaned images yields a 2D flux array indexed by time and wavelength. Broadband (“white-light”) light curves are formed by summing fluxes over a specified wavelength range and normalizing to the out-of-transit baseline:
$$
F_\mathrm{WLC}(t) = \sum_{\lambda_\mathrm{min}}^{\lambda_\mathrm{max}} F(\lambda, t)
$$
$$
F_\mathrm{norm}(t) = \frac{F_\mathrm{raw}(t)}{\langle F_\mathrm{raw} \rangle_\mathrm{oot}}
$$
Spectroscopic light curves result from repeating this operation in user-specified wavelength bins, producing a set of time series suitable for wavelength-resolved transit depth analysis.

## 6. Data Export, Integration with Public Tools, and Downstream Analysis

The notebook provides routines to export both broadband and spectroscopic light curves as CSV or ASCII tables:
```python
import numpy as np
np.savetxt('white_light_curve_+1.csv',
           np.column_stack([wlc_times, wlc_flux]),
           header='time_MJD,flux_norm')
```
These outputs are designed for immediate compatibility with widely used fitting environments:
- **PacMan:** ASCII tables of time, flux, and uncertainty per channel.
- **WFC3 pipeline:** Similarly-structured inputs.
- **Eureka!:** Dataframes or CSVs.

The notebook explicitly concludes at the delivery of normalized light curves. Users are encouraged to perform transit light curve fitting—e.g., extracting $R_p/R_\star$ in each wavelength bin—using packages appropriate to their modeling needs, such as those implementing the Mandel & Agol (2002) quadratic limb darkening formalism:
$$
F_\mathrm{model}(t; p, u_1, u_2) = 1 - \left(\frac{R_p}{R_\star}\right)^2 \delta(t, p) + \ldots
$$
where $p = R_p/R_\star$ and $\delta(t, p)$ gives the occulted area fraction.

Compilation of $p(\lambda)$ across wavelength bins forms the basis for deriving the planetary transmission spectrum.

## 7. Context, Adaptability, and Significance

The described pipeline is generalizable to any HST/WFC3 G280 time series where the source is observed in the 0th, $\pm$1st, and higher spectral orders. The modular design of `g280_transit_tools.py` enables adaptation to alternate targets, aperture definitions, and spectral orders. A plausible implication is that these scripts may serve as a template for extended analyses of UV-optical exoplanet atmospheres observed with HST/WFC3/UVIS G280, supporting rapid data reduction reproducibility and facilitating comparison with previous analyses.

The HST_Notebooks repository thus provides not only a canonical reduction solution but a model for open-access, reproducible, and extensible time-domain spectrophotometric workflows in exoplanetary astronomy.

Source: https://www.emergentmind.com/topics/hst_notebooks-github-repository