An interactive Python tool for plotting representative stellar spectra across different spectral types and metallicities! Perfect for astronomy education, research, and stellar classification studies.
- Features
- Installation
- Quick Start
- Usage
- Parameters
- Examples
- Data Sources
- Project Structure
- Contributing
- Citation
- License
- Acknowledgments
- Interactive Stellar Spectra Plotting: Generate and visualize synthetic stellar spectra with customizable parameters
- Wide Parameter Range:
- Effective temperatures: 3000K - 8000K
- Surface gravities: log(g) = 0.0 - 5.0 dex
- Metallicities: subsolar ([M/H]=-2.0), solar ([M/H]=0.0), and supersolar ([M/H]=0.5)
- Dual Spectra Display: View both normalized and unnormalized flux spectra
- Spectral Line Markers: Automatic labeling of important spectral features (Ca H/K, H-alpha, H-beta, Na D lines)
- Export Capabilities: Save high-resolution plots for publications and presentations
- Pre-computed Spectra: Fast loading from pre-synthesized MARCS/Korg models
pip install obafgkm
# Latest development version
pip install git+https://github.com/rocketxturtle/obafgkm
# Or clone and install locally
git clone https://github.com/rocketxturtle/obafgkm.git
cd obafgkm
pip install -e .
The package requires the following Python libraries:
numpy- Numerical computationspandas- Data manipulationastropy- Astronomical utilitiesmatplotlib- Plotting functionality
These will be automatically installed with the package.
# In the terminal
python
import obafgkm.prompt as p
p.run()
This will launch an interactive session where you can select stellar parameters and generate spectra.
The simplest way to use obafgkm is through the terminal:
python
import obafgkm.prompt as p
p.run()
After which ou'll be prompted to select:
- Effective temperature (3000, 4000, 5000, 6000, 7000, or 8000 K)
- Surface gravity (log(g): 0.0, 1.0, 2.0, 3.0, 4.0, or 5.0 dex)
- Metallicity ('subsolar', 'solar', or 'supersolar')
For more control, you can use the package by manually setting the Star object parameters:
import obafgkm.main as obafgkm
from obafgkm.plot import plotter
# Create a star object with specific parameters
star = obafgkm.Star(
effective_temperature=5000, # K
surface_gravity=4.0, # log(g) in dex
metallicity='solar' # or 'subsolar', 'supersolar'
)
# Generate spectra data
spectra_data = star.select_spectra()
# Plot the spectra (with optional save)
plotter(spectra_data, save=True) # Set save=False to just display
Access the raw spectral data for more detailed analysis:
import obafgkm.main as obafgkm
import matplotlib.pyplot as plt
star = obafgkm.Star(5000, 4.0, 'solar')
unnorm, norm, params, filename = star.select_spectra()
# unnorm and norm are numpy arrays with wavelength and flux columns
wavelength = norm[:, 0] # Wavelength in Angstroms
flux = norm[:, 1] # Normalized flux
# Create your own custom plot
plt.figure(figsize=(12, 6))
plt.plot(wavelength, flux)
plt.xlabel('Wavelength (ร
)')
plt.ylabel('Normalized Flux')
plt.title(f'Teff={params[0]}K, log(g)={params[1]}, [M/H]={params[2]}')
plt.show()
- Available values: 3000, 4000, 5000, 6000, 7000, 8000 K
- Covers spectral types from M to A stars
- Available values: 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 dex
- From supergiants (low log g) to main sequence/subdwarfs (high log g)
- subsolar: [M/H] = -2.0 (metal-poor)
- solar: [M/H] = 0.0 (solar abundance)
- supersolar: [M/H] = 0.5 (metal-rich)
import obafgkm.main as obafgkm
from obafgkm.plot import plotter
# Create a Sun-like star (G-type)
sun_like = obafgkm.Star(
effective_temperature=6000,
surface_gravity=4.0,
metallicity='solar'
)
plotter(sun_like.select_spectra(), save=True)
import obafgkm.main as obafgkm
from obafgkm.plot import plotter
# K-type giant star
red_giant = obafgkm.Star(
effective_temperature=4000,
surface_gravity=1.0,
metallicity='solar'
)
plotter(red_giant.select_spectra())
import obafgkm.main as obafgkm
from obafgkm.plot import plotter
# Metal-poor dwarf star
subdwarf = obafgkm.Star(
effective_temperature=5000,
surface_gravity=5.0,
metallicity='subsolar'
)
plotter(subdwarf.select_spectra())
obafgkm/
โโโ __init__.py # Package initialization and version info
โโโ main.py # Core Star class and spectra selection
โโโ plot.py # Plotting utilities and visualization
โโโ prompt.py # Interactive user interface
โโโ rcparams.txt # Matplotlib configuration settings
โโโ star_types.csv # Database of available stellar spectra
โโโ normalized_spectra/ # Pre-computed normalized flux spectra
โโโ unnormalized_spectra/ # Pre-computed unnormalized flux spectra
โโโ plots/ # Saved plot outputs (created on first save)
The spectral data in this package were synthesized from:
- Model Atmospheres: MARCS model atmospheres
- Spectral Synthesis: Korg spectral synthesis code
- Wavelength Range: Full optical coverage
- Resolution: High-resolution synthetic spectra
Note: Current temperature range is limited to 3000-8000 K. Future releases aim to expand this range to include O and B type stars (>8000 K) and cooler M dwarfs (<3000 K).
We welcome contributions! Please feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Extending temperature range beyond 3000-8000 K
- Adding more metallicity options
- Implementing additional spectral analysis tools
- Improving documentation and examples
- Adding unit tests
If you use obafgkm in your research, please cite (bibtex):
@misc{obafgkm,
author = {{Gozman, Katya}, {Sinha, Amaya}, {Schochet, Meir}, {Ramon, Lisha}},
title = {obafgkm: Interactive Stellar Spectra Plotting Tool},
year = {2025},
publisher = {Zenodo},
doi = {10.5281/zenodo.16762220},
url = {https://github.com/rocketxturtle/obafgkm}
}
This project is licensed under the MIT License - see the LICENSE file for details.
- Created at Code/Astro workshop
- Spectral synthesis using MARCS model atmospheres
- Synthetic spectra generated with Korg
- Special thanks to the astronomy community for feedback and testing
Found a bug or have a question? Please open an issue on our GitHub Issues page.
- Extend temperature range to include O/B stars (>8000 K)
- Add ultra-cool dwarfs (<3000 K)
- Implement spectral classification algorithms
- Add interactive Jupyter widget interface
- Include additional spectral line identification tools
- Support for custom wavelength ranges
- Integration with observational data formats
Happy stellar spectroscopy! ๐ญโจ
Remember: The universe is under no obligation to make sense to you, but these spectra might help!