How remingtonsexton/badass3 works
Project Type and Purpose
• BADASS is an open-source Python library and command-line/Jupyter-Notebook tool for spectral analysis and decomposition of astronomical data (especially SDSS and IFU cubes).
• It reads spectral FITS files, applies continuum and line models, performs maximum-likelihood and MCMC fitting, and writes out best-fit spectra, parameter tables, and diagnostic plots.
High-Level Architecture Components
a. Data Layer
– Input Spectra (FITS or NumPy arrays) under example_spectra/ or user-supplied folders.
– Template Libraries under badass_data/ (stellar libraries, SSP templates, FeII/UV/balmer templates, neural network model).
b. Configuration Layer
– Notebook interface (example_notebooks/) and CLI script (badass.py).
– Options files (.py) or dictionaries in notebooks (fit_options, mcmc_options, etc.).
c. Core Engine
– badass.py: orchestrates data loading, model assembly, fit routines.
– Module packages:
· badass_utils/: input checking, IFU cube handling, test suite
· badass_tools/: helper routines for spectrum handling
· badass_data/neural_network: pre-trained ML models
d. Computational Services
– Optimization service: SciPy basinhopping, least-squares
– MCMC service: emcee sampler with autocorrelation checks
– Parallelization: multiprocessing for batch fits or cube spaxels
e. External Dependencies
– Astropy (FITS I/O, cosmology), NumPy/Pandas, SciPy, Matplotlib, emcee, pPXF, astroquery, spectres, corner, etc.
f. Output Layer
– FITS tables: par_table.fits, best_model_components.fits, noise and autocorr .npy
– Plots: best-fit spectra, chain histograms, interactive HTML (Plotly)
– Log files: text summaries of fit progress and results
Relationships and Data Flows
• User launches a Notebook or CLI command → config/options passed to core engine → engine loads input spectrum(s) and templates → engine constructs continuum+line models → optimization service finds ML solution → optionally MCMC service refines with emcee → results fed to output layer → FITS tables, plots, logs are written → user reviews via Notebook or viewers.
• For IFU cubes, engine distributes spaxel fits across CPU cores and aggregates outputs.
Architectural Patterns and Principles
• Modular design: separation of concerns between data I/O, fitting logic, utilities, and user interface.
• Plugin-style templates: broad range of spectral components can be turned on/off via config.
• Service-oriented tasks: distinct services for optimization, MCMC sampling, plotting.
• Parallel processing for scalability.
• Data-driven: heavy use of configuration dictionaries and template folders under badass_data/.
Elements
– Blue for data resources (template folders, input spectra)
– Green for core modules (scripts/packages)
– Orange for services (optimization, MCMC, parallelization)
– Gray for external libraries
– Purple for outputs (FITS, plots, logs)
• Related components (e.g., under “Core Engine” show badass_utils, badass_tools).
Detailed Capture of Essential Elements
• Notebook interface feeding into badass.py with config dictionaries.
• How multiprocessing forks tasks for multiple spectra or IFU spaxels.
• Where log files and FITS outputs are generated and saved.