BADASS3
Bayesian AGN Decomposition Analysis for SDSS Spectra
Install / Use
/learn @remingtonsexton/BADASS3README

New in Version 10.2.0
- New line and configuration testing framework. See Line Testing and Options.
- Line component options. See Line Component Options.
- Improvements in autocorrelation calculations.
- W80 now a standard output parameter for all lines.
- Outputs line widths that are both corrected and uncorrected for input resolution
- BADASS now normalizes the spectrum internally for fitting purposes.
- Various improvements to global optimizer used in initial fit.
- Note: The algorithm used for scaling the noise to achieve a $\Chi_\nu^2=1$ was found to be numerically unstable and users should use
fit_stat='ML'instead.
Ridiculous acronyms are a long-running joke in astronomy, but here, spectral fitting ain't no joke!
BADASS is an open-source spectral analysis tool designed for detailed decomposition of Sloan Digital Sky Survey (SDSS) spectra, and specifically designed for the fitting of Type 1 ("broad line") Active Galactic Nuclei (AGN) in the optical. The fitting process utilizes the Bayesian affine-invariant Markov-Chain Monte Carlo sampler emcee for robust parameter and uncertainty estimation, as well as autocorrelation analysis to access parameter chain convergence. BADASS can fit the following spectral features:
- Stellar line-of-sight velocity distribution (LOSVD) using Penalized Pixel-Fitting (pPXF, Cappellari et al. (2017)) using templates from the Indo-U.S. Library of Coudé Feed Stellar Spectra (Valdes et al. (2004)) in the optical region 3460 Å - 9464 Å.
- Broad and Narrow FeII emission features using the FeII templates from Véron-Cetty et al. (2004) or Kovačević et al. (2010).
- UV iron template from Vestergaard and Wilkes (2001)
- Individual narrow, broad, and/or absorption line features.
- AGN power-law continuum and Balmer pseudo-continuum.
- "Blue-wing" outflow emission components found in narrow-line emission.
A more-detailed summary of BADASS, as well as a case-study of ionized gas outflows, is given in Sexton et al. (2021).
All spectral components can be turned off and on via the Jupyter Notebook interface, from which all fitting options can be easily changed to fit non-AGN-host galaxies (or even stars!). BADASS uses multiprocessing to fit multiple spectra simultaneously depending on your hardware configuration. The code was originally written in Python 2.7 to fit Keck Low-Resolution Imaging Spectrometer (LRIS) data (Sexton et al. (2019)), but because BADASS is open-source and not written in an expensive proprietary language, one can easily contribute to or modify the code to fit data from other instruments. Out of the box, BADASS fits SDSS spectra, MANGA IFU cube data, and examples are provided for fitting user-input spectra of any instrument.
Before getting started you should read the readme below.
Table of Contents
- Installation
- Usage
- Fitting Options
- MCMC Options
- Model Component Options
- Multiple Line Components
- Line Testing and Options
- Configuration Testing
- Line Component Options
- User Lines, Constraints, and Masks
- Combined Lines
- LOSVD Fitting Options (pPXF)
- Host Model Options
- Power Law Options
- Polynomial Options
- Optical FeII Options
- UV Iron Options
- Balmer Pseudo-Continuum Options
- Plotting Options
- Output Options
- The Main Function and Calling Sequence
- Output
- Examples & Tutorials
- How to...
- Known Issues
- Credits
- License
Installation
The easiest way to get started is to simply clone the repository.
As of the most recent version, the following packages are required (Python 3.8.12):
numpy 1.22.3pandas 1.4.2scipy 1.7.3matplotlib 3.7.1astropy 5.2.1astroquery 0.4.6emcee 3.1.4numexpr 2.8.4natsort 8.3.1psutil 5.9.4vorbin 3.1.5
spectres 2.2.0corner 2.2.1prettytable 3.6.0- Note:
ppxfwas integrated within the BADASS source code early on, and does not require installation. - Optional:
plotly 5.13.1(for interactive HTML plots)
The code is run entirely through the Jupyter Notebook interface, and is set up to run on the included spectrum files in the ".../examples/" folder. If one wants to fit multiple spectra consecutively, simply add folders for each spectrum to the folder. This is the recommended directory structure:

Simply create a folder containing the SDSS FITS format spectrum, and BADASS will generate a working folder for each fit titled "MCMC_output_#" inside each spectrum folder. BADASS automatically generates a new output folder if the same object is fit again (it does not delete previous fits).
Usage
Fitting Options
################################## Fit Options #################################
# Fitting Parameters
fit_options={
fit_options={
"fit_reg" : (4400,5500),# Fitting region; Note: Indo-US Library=(3460,9464)
"good_thresh": 0.0, # percentage of "good" pixels required in fig_reg for fit.
"mask_bad_pix": False, # mask pixels SDSS flagged as 'bad' (careful!)
"mask_emline" : False, # automatically mask lines for continuum fitting.
"mask_metal": False, # interpolate over metal absorption lines for high-z spectra
"fit_stat": "RCHI2", # fit statistic; ML = Max. Like. , OLS = Ordinary Least Squares, RCHI2 = reduced chi2
"n_basinhop": 15, # Number of consecutive basinhopping thresholds before solution achieved
"test_lines": False, # Perform line/configuration testing for multiple components
"max_like_niter": 10, # number of maximum likelihood iterations
"output_pars": False, # only output free parameters of fit and stop code (diagnostic)
"cosmology": {"H0":70.0, "Om0": 0.30}, # Flat Lam-CDM Cosmology
}
################################################################################
fit_reg: (tuple/list of length (2,); Default: (4400,5500))<br/>
the minimum and maximum desired fitting wavelength in angstroms, for example (4400,7000). This is passed to the determine_fit_reg() function to check if this region is valid and and which emission lines to fit.
good_thresh: (float [0.0,1.0]; Default: 0.0)<br/>
the cutoff for minimum fraction of "good" pixels (determined by SDSS) within the fitting range to allow for fitting of a given spectrum. If the spectrum has fewer good pixels than this value, BADASS skips over it and moves onto the next spectrum.
mask_bad_pix: (bool; Default: False)<br/>
Mask pixels which SDSS flagged as bad due to sky line subtraction or cosmic rays. Warning: if large portions of the fitting region are marked as bad pixels, this can cause BADASS to crash. One should only use this if only a few pixels are affected by contamination.
mask_emline: (bool; Default: False)<br/>
Mask any
