reduce_panic.py is a reduction script for PANIC near-infrared imaging data from the CAHA 2.2m telescope.
The pipeline works night by night and performs:
- Master dark construction, grouped by exposure time.
- Master flat construction, preferring sky flats and falling back to dome flats.
- Science-frame calibration with dark subtraction and flat-fielding.
- Sky subtraction using the rest of the dither sequence.
- Image registration and stacking for each
(OBJECT, FILTER)group. - Optional astrometric calibration of the final stack through Gaia.
The script expects a directory containing raw FITS files from one observing night. It groups files through the IMAGETYP header and groups science exposures by OBJECT and FILTER.
For each science group, the script creates and reuses intermediate products so repeated runs are fast:
masters/: master darks and flatscalib/<OBJECT>_<FILTER>/: calibrated science framessky/<OBJECT>_<FILTER>/: sky-subtracted framesaligned/<OBJECT>_<FILTER>/: aligned intermediate FITS filesstack_<OBJECT>_<FILTER>.fits: final stacked image
Each stage is cached. If an output already exists, that stage is skipped unless you explicitly redo the stacking stage.
The current alignment stage is image-based and uses a central registration box:
- a central square region is extracted from each sky-subtracted frame
- a correlation-friendly version of that region is built after background removal
- a coarse translation is estimated with phase correlation
- a local correlation refinement is then applied
- the final sub-pixel shift is written to the aligned intermediate FITS headers as
DYSHIFTandDXSHIFT
This makes it easy to inspect the aligned frames directly in DS9 or another FITS viewer before accepting the final stack.
python reduce_panic.py <night_dir> [--outdir <path>] [--sky-window <N>] \
[--register-box <pixels>] [--no-astrometry] \
[--redo-stack] [--realign-list <file>] \
[--exclude-list <file>] [--shift-override <file>]--outdir: choose the reduction output directory--register-box: size of the central square used for image registration--redo-stack: rerun alignment and stacking even if a stack already exists--exclude-list: text file listing frames to reject from the stack--shift-override: text file with manual(dy, dx)corrections for specific frames--no-astrometry: skip the Gaia astrometric solution
Run a normal reduction:
python reduce_panic.py 251208_PANIC --outdir 251208_PANIC/reducedRebuild only the stack after inspecting aligned frames:
python reduce_panic.py 251208_PANIC --outdir 251208_PANIC/reduced --redo-stackReject a set of bad frames and restack:
python reduce_panic.py 251208_PANIC --outdir 251208_PANIC/reduced \
--redo-stack --exclude-list reject.txtApply manual shifts and restack:
python reduce_panic.py 251208_PANIC --outdir 251208_PANIC/reduced \
--redo-stack --shift-override shift_fix.txtmanual_click_stack.py is a small standalone tool for difficult cases where the
automatic registration is not reliable enough.
It works on a directory of FITS images, typically a single sky-subtracted
<OBJECT>_<FILTER> group, and lets you:
- display each image one by one
- click the same reference source in every frame
- refine the click to a local centroid
- write aligned intermediate FITS files
- build a final sigma-clipped stack
Typical use:
python manual_click_stack.py 251206_PANIC/reduced/sky/SN2025abwp_HUseful options:
--exclude-list: skip specific images--view-half-size: control the zoomed display size around the clicked source--centroid-radius: control the centroiding radius--outdir: choose a different output directory
The manual outputs are written by default to:
<indir>/manual_stack/aligned/<indir>/manual_stack/manual_stack.fits<indir>/manual_stack/click_log.csv
The script relies on:
numpyastropyscipyphotutilsastroqueryfor the optional Gaia astrometry step
- The stack astrometry is solved after stacking; the registration step itself is image-based.
- Sky subtraction quality strongly affects the final stack. Residual source imprints in the sky frame can survive into the final image.
- The aligned intermediate FITS files are often the best place to visually validate the registration before deciding whether to exclude or manually shift any frame.