GalSpec: Galaxy Spectrum Fitting#
GalSpec is a Python package for fitting astronomical spectra, specifically designed for AGN and galaxy spectra with complex emission and absorption line features.
Key Features#
Astropy Integration: All models inherit from Astropy’s modeling framework, ensuring compatibility with standard astronomical tools
Multiple Fitting Methods: Support for least-squares, MCMC (emcee), and nested sampling (dynesty; under development) algorithms
Comprehensive Line Database: Built-in database of UV/optical emission lines for AGN and galaxy analysis
Template Support: Iron (Fe II) templates and stellar population models included
Flexible Model Composition: Easily combine continuum, line, and template components
Professional Fitting: Parameter constraints, tying, and bounds for complex models
Sample Fitting From a File: one TOML describing the data, the model and the sampler, then fit one source or a whole sample with
python -m galspec.pipeline
Quick Start#
Install GalSpec from source:
git clone https://github.com/yourusername/galspec.git
cd galspec
pip install -e .
Fit a simple emission line:
import numpy as np
from astropy.modeling.models import Linear1D
from galspec import Line_Gaussian
from astropy.modeling.fitting import LevMarLSQFitter
# Load your spectrum data
wave = np.linspace(4000, 7000, 1000)
flux = np.random.randn(1000) * 0.1 # Your flux data here
# Create a model: continuum + emission line
continuum = Linear1D(slope=0.0, intercept=1.0)
line = Line_Gaussian(amplitude=1.0, dv=0, sigma=200, wavec=6563, name='Halpha')
model = continuum + line
# Fit the model
fitter = LevMarLSQFitter()
fitted_model = fitter(model, wave, flux)
Contents#
User Guide:
Examples:
- Example: fitting a strong AGN
- Example: measure the black hole and the host galaxy
- The answer, first
- 1. The spectrum
- 2. The continuum windows
- 3. The continuum model
- 4. sigma_* and the 5100 A luminosity
- 5. What the continuum posterior is, and is not
- 6. The narrow-line template, measured on [S II]
- 7. The H-alpha complex
- 8. H-beta and [O III]
- 9. The fluxes and the widths
- 10. The BPT diagram
- 11. The black hole and the host galaxy
- 12. What the numbers say against the reference fit
- 13. What to check before believing any of it
- 14. Saving the fit, and where to go next
Indices and tables#
Links#
GitHub Repository: yourusername/galspec
Issue Tracker: yourusername/galspec#issues
Documentation: https://yourusername.github.io/galspec/