Skip to content

A Python Wrapper for running the Brussels Automatic Code for Characterizing High accUracy Spectra (BACCHUS)

License

Notifications You must be signed in to change notification settings

rocketxturtle/PyBACCHUS

Repository files navigation

PyBACCHUS

DOI A rectangular badge, half black half purple containing the text made at Code Astro Python 3.10+

A Python Wrapper for running the Brussels Automatic Code for Characterizing High accUracy Spectra (BACCHUS (https://ui.adsabs.harvard.edu/abs/2016ascl.soft05004M/abstract)).

📖 Table of Contents

✨ Features & Quick Start

The purpose of this code is to allow interfacing with the native BACCHUS enivroment using Python. This is NOT a version of BACCHUS written in Python, it requires an existing BACCHUS installation to function.

There are three primary modules for this package: BACCHUS, Star, and Result.

BACCHUS

The BACCHUS class is instantiated by giving it the location of an existing BACCHUS installation. Once a BACCHUS object is created, it will be populated with the existing state of all the primary bacchus modules:

for a BACCHUS object bacchus


bacchus = BACCHUS('your path here!')

- bsyn.com --> bacchus.bsyn
- babsma.com --> bacchus.babsma
- stellar_parameters.tab --> bacchus.stellar_parameters
- init.com --> bacchus.init
- elements.wln --> bacchus.elements_wln
- eqwidt.com --> bacchus.eqwidt

as well as a linelists object that contains the paths to all available linelists. Each of these modules is accessible in a BACCHUS object as an attribute (e.g. init.com can be accessed by bacchus.init). This allows for editing each module in python, both through direct line-by-line editing, and a suite of preloaded methods (e.g. set_ncpu, set_linelist). MORE DOCUMENTATION COMING.

Once the configuration of BACCHUS is set up to your liking, you can write it out to the native BACCHUS.

Star

A Star object is the container for the stars being run in BACCHUS. At a minimum it requires a name to be instantiated, but to load into stellar_parameters.tab it will require the six necessary parameters (spectra path, teff, logg, etc...). This object will also have access to all the parameter and model information from a BACCHUS analysis, as well as the elemental abundance results (stored in a Results object).

Results

A Results object holds all the data for a single element within a Star. It automatically scrapes the star's directory after a .abund, .eqw, or .param analysis load in the .abu, .plt, and .eqw results as Astropy Tables.

Running a Star

After you've configured your BACCHUS setup to your liking and written the setup to native BACCHUS, you can follow the same procedure normally used in native BACCHUS

for a BACCHUS object bacchus, and a Star object

import PyBACCHUS
from PyBACCHUS import *
from PyBACCHUS.bacchus import BACCHUS
from PyBACCHUS.star import Star

bacchus = BACCHUS('your path here!')

1) bacchus.load_parameters(Star)
2) bacchus.abund(Star)
3) bacchus.eqw(Star)
4) bacchus.param(Star)

Example

import PyBACCHUS
from PyBACCHUS import *
from PyBACCHUS.bacchus import BACCHUS
from PyBACCHUS.star import Star

bacchus = BACCHUS('your path here!')
star = Star(starname)

#let's say we only want to use one CPU and the metal-poor line selenction
bacchus.init.set_ncpu(1)
bacchus.init.set_wavereffile('elements_MP.wln')

#check to see your configuration is good
bacchus.init.show()
bacchus.bsyn.show()

#now we can write out our changes to the init.com file
bacchus.init.write()

#now lets get our star ready. to set its initial guesses, we need a spectra path (str),
#and teff/logg/mh/vmicro/conv all as tuples of the form (guess, uncertainty).

star.set_initial_values(spectra_path, (5000,100), (4.5, 0.1), (0,0.1),(1.5,0.2), (-15,5))
bacchus.stellar_parameters.add_star(star)
bacchus.stellar_parameters.write()

#check to see your stellar_parameters.tab is good
bacchus.stellar_parameters.show()

#now run your abundance analysis!
bacchus.load_parameters(star)
bacchus.param(star)
bacchus.eqw(star, 'C')
bacchus.abund(star, 'Zr')

🚀 Installation

From PyPI (Stable Release)

pip install PyBACCHUS

From GitHub (Development Version)

# Latest development version
pip install git+https://github.com/rocketxturtle/PyBACCHUS

# Or clone and install locally
git clone https://github.com/rocketxturtle/PyBACCHUS.git
cd PyBACCHUS
pip install -e .

Dependencies

The package requires the following Python libraries:

  • numpy - Numerical computations
  • pandas - Data manipulation
  • astropy - Astronomical utilities
  • matplotlib - Plotting functionality

These will be automatically installed with the package.

📁 Project Structure

PyBACCHUS/
├── __init__.py             # Package initialization and version info
├── bacchus.py              # The core BACCHUS object that mimics the file structure of BACCHUS
├── star.py                 # Contains the Star class, which is used to run objects in BACCHUS
├── results.py              # A class that contains all the result data for a star
|_ other                    # Individual classes that mimic the functionality of each BACCHUS module
                              (e.g. bsyn.com, babsma.com, stellar_parameters.tab, ....)

🤝 Contributing

We welcome contributions! Please feel free to:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Areas for Contribution

  • Adding better plotting functionality
  • Interfacing with Korg
  • Documentation & debugging

📚 Citation

If you use PyBACCHUS in your research, please cite this code as well as the original citation for BACCHUS:

@misc{PyBACCHUS,
  author = {{Sinha}, Amaya},
  title = {PyBACCHUS: Interactive Stellar Spectra Plotting Tool},
  year = {2025},
  publisher = {Zenodo},
  doi = {10.5281/zenodo.17070806},
  url = {https://github.com/rocketxturtle/PyBACCHUS}
}
@software{2016ascl.soft05004M,
       author = {{Masseron}, Thomas and {Merle}, Thibault and {Hawkins}, Keith},
        title = "{BACCHUS: Brussels Automatic Code for Characterizing High accUracy Spectra}",
 howpublished = {Astrophysics Source Code Library, record ascl:1605.004},
         year = 2016,
        month = may,
          eid = {ascl:1605.004},
       adsurl = {https://ui.adsabs.harvard.edu/abs/2016ascl.soft05004M},
      adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Developed partially at Code/Astro workshop
  • Special thanks to the astronomy community for feedback and testing

🐛 Bug Reports & Questions

Found a bug or have a question? Please open an issue on our GitHub Issues page.

🔮 Future Enhancements

  • Add in the code for creating multiple parallelized BACCHI
  • Add in better plotting (e.g. with lines) & reading in the SuperMongo plots
  • Add in functionality for editing linelists

Happy stellar spectroscopy! 🔭✨

Remember: The universe is under no obligation to make sense to you, but these spectra might help!

About

A Python Wrapper for running the Brussels Automatic Code for Characterizing High accUracy Spectra (BACCHUS)

Resources

License

Stars

Watchers

Forks

Packages

No packages published