Skip to content

jyshangguan/SAGAN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAGAN

Spectral Analysis of Galaxy and Active galactic Nuclei

SAGAN is a Python package for fitting astronomical spectra, specifically designed for AGN and galaxy spectra with complex emission and absorption line features.

SAGAN Logo

Key Features

  • Astropy Integration: All models inherit from Astropy's modeling framework
  • Multiple Fitting Methods: LSQ, MCMC (emcee), and nested sampling (dynesty)
  • Comprehensive Line Database: Built-in UV/optical emission lines
  • Template Support: Fe II and stellar population templates
  • Flexible Model Composition: Easily combine continuum, line, and template components

Documentation

Full documentation is available at: https://jyshangguan.github.io/SAGAN/

The documentation includes:

  • Installation instructions
  • Quick start tutorial with real SDSS data
  • API reference for all modules
  • Examples for continuum fitting, emission lines, absorption lines, and advanced techniques

Installation

Install from source:

git clone https://github.com/jyshangguan/SAGAN.git
cd SAGAN
pip install -e .

Claude Code Integration (Optional)

SAGAN includes a Claude Code skill that allows you to use SAGAN directly within Claude Code for interactive spectral fitting assistance.

To install the skill:

# From the SAGAN repository root
./install_skill.sh

This will:

  • Create a symlink from ~/.claude/skills/sagan to the skills/ directory
  • Enable SAGAN commands in Claude Code

To use the skill in Claude Code:

/skills
Use SAGAN to fit the spectrum

To uninstall:

rm ~/.claude/skills/sagan

Quick Example

import numpy as np
from astropy.modeling.models import Linear1D
from sagan import Line_Gaussian
from astropy.modeling.fitting import LevMarLSQFitter

# Load your spectrum
wave = np.linspace(6400, 6700, 1000)
flux = np.random.randn(len(wave)) * 0.1  # Your data here

# Define model: continuum + Hα line
continuum = Linear1D(slope=0.0, intercept=1.0)
halpha = Line_Gaussian(amplitude=5.0, dv=0, sigma=200, wavec=6563)
model = continuum + halpha

# Fit
fitter = LevMarLSQFitter()
fitted_model = fitter(model, wave, flux)

print(f"Hα amplitude: {fitted_model[1].amplitude.value:.3f}")

Example Notebooks

The example/ directory contains detailed notebooks demonstrating:

  • Continuum fitting with stellar templates
  • Emission line fitting for AGN
  • Absorption line and BAL fitting
  • Physical parameter estimation

Requirements

  • Python ≥ 3.9
  • numpy, scipy, matplotlib, astropy, pandas
  • emcee, dynesty (for Bayesian fitting)

License

MIT License - see LICENSE file for details

Links

About

Spectral Analysis of Galaxy and Active galactic Nuclei

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors