This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Specreduce is an Astropy coordinated package providing Python utilities for reducing and calibrating spectroscopic data. It offers modular, composable building blocks for spectral reduction workflows.
# Run all tests via tox
tox -e py314-test
# Run tests with coverage
pytest --pyargs specreduce docs --cov specreduce --cov-config=pyproject.toml
# Run a specific test file
pytest specreduce/tests/test_background.py -v
# Run tests with all optional dependencies
tox -e py314-test-alldeps-cov# Check code style
tox -e codestyle
# Direct flake8
flake8 specreduce --count --extend-ignore E203# Build HTML docs
cd docs && make html
# Or with sphinx directly
sphinx-build -b html docs docs/_build/htmlpip install -e ".[test,docs,all]"The reduction workflow follows a modular pipeline: Trace → Background → Extract → Wavelength Calibration → Flux Calibration
-
core.py: Base class
SpecreduceOperationand_ImageParserfor image format coercion. Handles Spectrum1D, CCDData, NDData, Quantity, and ndarray inputs. DefinesMaskingOptionenum and masking strategies. -
tracing.py: Trace determination classes
Trace: Base trace (center of image)FlatTrace: Constant position traceArrayTrace: Custom trace from arrayFitTrace: Fit trace to image features using peak detection (median, gaussian, centroid methods)
-
background.py:
Backgroundclass withtwo_sided()andone_sided()methods for background estimation. Supports multiple traces and custom aperture definitions. -
extract.py: 1D spectrum extraction
BoxcarExtract: Simple aperture extractionHorneExtract/OptimalExtract: Optimal extraction with spatial profile fitting and variance propagation
-
wavecal1d.py: Current wavelength calibration implementation using
WavelengthCalibration1D. Supports automated line matching, template matching, and produces GWCS-based WCS objects. -
wavelength_calibration.py: Legacy wavelength calibration (deprecated in v1.7.0, removal in v2.0)
-
fluxcal.py:
FluxCalibrationclass for flux calibration with magnitude-to-flux conversion and airmass extinction correction -
calibration_data.py: Spectrophotometric standards and line lists
-
utils/synth_data.py: Synthetic spectroscopic data generation for testing
-
compat.py: Compatibility layer for specutils v1.x and v2.x
- Image Format Flexibility: All operations accept multiple input formats via
_ImageParser - Masking Strategies: Seven masking options defined in
MaskingOptionenum - Astropy Integration: Uses Astropy models, units, and conventions throughout
- GWCS Support: Wavelength calibration produces proper WCS objects
- Python ≥3.11
- Core: numpy≥1.24, astropy≥5.3, scipy≥1.10, specutils≥1.9.1, matplotlib≥3.10, gwcs
- Optional: photutils≥1.0 (stellar profile fitting), synphot (synthetic photometry)
- Line length: 100 characters (flake8 and black)
- Black formatter targeting Python 3.11+
- Ignore E203 (whitespace before ':')