Metadata-Version: 2.4
Name: bbarolo
Version: 2.0.1
Summary: 3D-Barolo (BBarolo): 3D tilted-ring fitting of emission-line datacubes
Author-email: Enrico Di Teodoro <enrico.diteodoro@gmail.com>
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://bbarolo.readthedocs.io
Project-URL: Documentation, https://bbarolo.readthedocs.io
Project-URL: Source, https://github.com/editeodoro/bbarolo2
Project-URL: Issues, https://github.com/editeodoro/bbarolo2/issues
Project-URL: Changelog, https://bbarolo.readthedocs.io/en/latest/reference/changes.html
Keywords: astronomy,kinematics,tilted-ring,datacube,galaxies,rotation curve
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Astronomy
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE.md
License-File: bbarolo/bayesian/nautilus/LICENSE
Requires-Dist: numpy>=1.22
Requires-Dist: scipy>=1.16
Requires-Dist: astropy>=5.0
Requires-Dist: numba>=0.57
Requires-Dist: matplotlib>=3.5
Provides-Extra: bayesian
Requires-Dist: dynesty; extra == "bayesian"
Requires-Dist: nautilus-sampler; extra == "bayesian"
Requires-Dist: corner; extra == "bayesian"
Requires-Dist: threadpoolctl; extra == "bayesian"
Provides-Extra: mpi
Requires-Dist: mpi4py; extra == "mpi"
Requires-Dist: schwimmbad; extra == "mpi"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: license-file

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/editeodoro/bbarolo2/main/docs/figures/3DBAROLO_logo_dark.png">
    <img src="https://raw.githubusercontent.com/editeodoro/bbarolo2/main/docs/figures/3DBAROLO_logo_light.png" alt="3D-Barolo logo" width="600">
  </picture>
</p>

[![Documentation Status](https://img.shields.io/readthedocs/bbarolo)](https://bbarolo.readthedocs.io)
[![License: GPL-3.0](https://img.shields.io/github/license/editeodoro/bbarolo2)](https://github.com/editeodoro/bbarolo2/blob/main/LICENSE.md)
[![Python: 3.11+](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org)
![Language: Python](https://img.shields.io/github/languages/top/editeodoro/bbarolo2)

BBarolo 2 is a GPL-licensed pure-Python version of [3D-Barolo](https://github.com/editeodoro/Bbarolo)
(BBarolo), the code that fits 3D tilted-ring models to emission-line datacubes to derive the kinematics of
galaxies: rotation curves, velocity dispersions and the geometry of the disc. Fitting the whole datacube rather
than a 2D velocity field, it is not biased by beam smearing and works on data of low spatial resolution. It
ports the C++ BBarolo 1.8 and its Python wrapper pyBBarolo: the same tasks (3DFIT, GALMOD, SEARCH, 2DFIT,
moment maps, PV slices, ...), the same parameter files and the same outputs, with nothing to compile. The
numerical kernels are compiled at run time with numba; the rest uses numpy, scipy, astropy and matplotlib.
3DFIT has three methods: CLASSIC (BBarolo 1.x, ring by ring), GLOBAL (all the rings together, at the maximum of the
likelihood) and BAYESIAN (`METHOD BAYESIAN`: the posterior of the ring parameters, sampled with nested sampling,
[nautilus](https://github.com/johannesulf/nautilus) included in the package). SLITFIT fits long-slit spectra, with the
methods GLOBAL and BAYESIAN.

**Status:** BBarolo 2.0.1 (November 2026), the first release of the Python BBarolo.

## Website and full documentation

You can find the documentation at [bbarolo.readthedocs.io](https://bbarolo.readthedocs.io): installation, a
first fit, every task with its parameters and how it works, examples, and the differences from BBarolo 1.8.

## Installation

BBarolo 2 needs Python 3.11 or later. Install it from PyPI with ``pip``:

```shell
pip install bbarolo
```

This installs the package `bbarolo` and the command `BBarolo`, with numpy, scipy, astropy, numba and
matplotlib: everything the tasks need, the Bayesian methods included. The optional extra `bayesian` adds the samplers
dynesty and nautilus-sampler (`SAMPLER DYNESTY` and `NAUTILUS`), corner (the corner plot) and threadpoolctl.

```shell
pip install "bbarolo[bayesian]"
```

> **Note:** `pip` puts the command `BBarolo` in the `bin` folder of the Python environment (`Scripts` on Windows),
> which is in the `PATH` when a conda or virtual environment is active. With `pip install --user` or a system Python,
> pip may warn that the script "is installed in '...' which is not on PATH". Add that folder to the `PATH`, e.g. in
> `~/.bashrc` or `~/.zshrc`, then open a new terminal (or `source ~/.bashrc`):
>
> ```shell
> export PATH="$HOME/.local/bin:$PATH"                  # Linux
> export PATH="$HOME/Library/Python/3.12/bin:$PATH"     # macOS, with Python 3.12
> ```
>
> or run BBarolo as `python -m bbarolo -p param.par`, which needs no change to the `PATH`. If the terminal has already
> run another `BBarolo` (e.g. the C++ 1.8), open a new one or type `hash -r` (`rehash` in zsh and tcsh); `BBarolo -v`
> shows which version runs.

The development version, from the `main` branch of this repository:

```shell
pip install git+https://github.com/editeodoro/bbarolo2
```

To work on the code, install a copy of the repository in editable mode.

```shell
git clone https://github.com/editeodoro/bbarolo2
cd bbarolo2
pip install -e ".[bayesian,test]"
```

## Example

A 3D fit of the HI datacube of NGC 2403 ([examples/ngc2403.fits](https://github.com/editeodoro/bbarolo2/blob/main/examples/ngc2403.fits), 5 MB). From the command
line, with a parameter file as for the C++ BBarolo:

```shell
cd examples
BBarolo -p ngc2403_3DFIT.par
```

In Python, a 3D fit of the rotation curve and the velocity dispersion:

```python
import numpy as np
from bbarolo import FitMod3D

f = FitMod3D("ngc2403.fits", radii=np.arange(15, 1200, 30), xpos=77, ypos=77, vsys=132.8,
             vrot=120, vdisp=8, z0=10, inc=60, pa=123.7, free="VROT VDISP", mask="SEARCH")
res = f.run()                     # in memory: res.rings (the fitted rings), res.model (the model cube)
res.write("output/")              # the files and plots of the command line
```

More examples, from radio cubes of nearby galaxies to ALMA data at high redshift, a protoplanetary disk and a
long-slit spectrum, with global and Bayesian fits, are on the
[example pages](https://bbarolo.readthedocs.io/en/latest/examples/index.html) of the documentation. Their data
and parameter files are in [examples/](https://github.com/editeodoro/bbarolo2/tree/main/examples), with the notebook [examples/examples.ipynb](https://github.com/editeodoro/bbarolo2/blob/main/examples/examples.ipynb),
which runs them all in Python and shows their plots.

## Attribution

A paper describing BBarolo's methods and its tests has been published in the
[Monthly Notices of the Royal Astronomical Society](https://doi.org/10.1093/mnras/stv1213). A draft of the paper
is also available on [arXiv](https://arxiv.org/abs/1505.07834). Please cite the paper if you find BBarolo
helpful in your research.

```
@ARTICLE{2015MNRAS.451.3021D,
   author = {{Di Teodoro}, E.~M. and {Fraternali}, F.},
    title = "{$^{3D}$BAROLO: a new 3D algorithm to derive rotation curves of galaxies}",
  journal = {MNRAS},
     year = 2015,
   volume = 451,
    pages = {3021-3033},
      doi = {10.1093/mnras/stv1213}
}
```

3DFIT and SLITFIT with METHOD BAYESIAN sample the posterior with nautilus
([Lange 2023](https://doi.org/10.1093/mnras/stad2441)): if you use them, please cite nautilus as well.

```
@article{nautilus,
    author = {Lange, Johannes U},
    title = "{nautilus: boosting Bayesian importance nested sampling with deep learning}",
    journal = {Monthly Notices of the Royal Astronomical Society},
    volume = {525},
    number = {2},
    pages = {3181-3194},
    year = {2023},
    month = {08},
    doi = {10.1093/mnras/stad2441},
    url = {https://doi.org/10.1093/mnras/stad2441},
}
```

## License

BBarolo 2 is licensed under the GNU General Public License v3.0 or later (see [LICENSE.md](https://github.com/editeodoro/bbarolo2/blob/main/LICENSE.md)). It
includes a modified copy of nautilus 1.0.6 (`bbarolo/bayesian/nautilus`), licensed under the MIT License,
Copyright (c) 2022 Johannes U. Lange.
