├── .dir-locals.el ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yaml ├── LICENSE ├── README.md ├── docs ├── Makefile ├── basta_crop_low-res.png ├── conf.py ├── contributing.rst ├── controls.rst ├── controls_fit.rst ├── controls_intpol.rst ├── controls_io.rst ├── controls_outplots.rst ├── controls_parameters.rst ├── examples.rst ├── examples_freqs.rst ├── examples_global.rst ├── examples_interpolation.rst ├── examples_isochrones.rst ├── figures │ ├── distance │ │ ├── 11129442_corner.png │ │ ├── 11129442_distance_corner.png │ │ └── 11129442_kiel.png │ ├── epsilon │ │ ├── 16CygA_corner.png │ │ ├── 16CygA_dupechelle.png │ │ ├── 16CygA_dupechelle_uncorrected.png │ │ ├── 16CygA_echelle.png │ │ ├── 16CygA_echelle_uncorrected.png │ │ ├── 16CygA_epsdiff_e012.png │ │ ├── 16CygA_epsdiff_e012_cormap.png │ │ ├── 16CygA_kiel.png │ │ ├── 16CygA_pairechelle.png │ │ ├── 16CygA_pairechelle_uncorrected.png │ │ ├── 16CygA_ratios_r012.png │ │ └── 16CygA_ratios_r012_cormap.png │ ├── freqs │ │ ├── 16CygA_corner.png │ │ ├── 16CygA_dupechelle.png │ │ ├── 16CygA_dupechelle_uncorrected.png │ │ ├── 16CygA_echelle.png │ │ ├── 16CygA_echelle_uncorrected.png │ │ ├── 16CygA_kiel.png │ │ ├── 16CygA_pairechelle.png │ │ └── 16CygA_pairechelle_uncorrected.png │ ├── glitches │ │ ├── 16CygA_corner.png │ │ ├── 16CygA_dupechelle.png │ │ ├── 16CygA_dupechelle_uncorrected.png │ │ ├── 16CygA_echelle.png │ │ ├── 16CygA_echelle_uncorrected.png │ │ ├── 16CygA_glitches_gr012.png │ │ ├── 16CygA_glitches_gr012_cormap.png │ │ ├── 16CygA_kiel.png │ │ ├── 16CygA_pairechelle.png │ │ ├── 16CygA_pairechelle_uncorrected.png │ │ └── 16CygA_ratios_r012.png │ ├── global │ │ ├── 16CygA_corner.png │ │ └── 16CygA_kiel.png │ ├── interp_MS │ │ ├── 16CygA_corner.png │ │ ├── 16CygA_dupechelle.png │ │ ├── 16CygA_dupechelle_uncorrected.png │ │ ├── 16CygA_echelle.png │ │ ├── 16CygA_echelle_uncorrected.png │ │ ├── 16CygA_kiel.png │ │ ├── 16CygA_pairechelle.png │ │ ├── 16CygA_pairechelle_uncorrected.png │ │ └── intpol_example_16CygA_intpolbase.png │ ├── json │ │ ├── 16CygA_corner.png │ │ └── 16CygA_kiel.png │ ├── parallax │ │ ├── 11129442_corner.png │ │ ├── 11129442_distance_corner.png │ │ └── 11129442_kiel.png │ ├── phase │ │ ├── 11129442_corner.png │ │ └── 11129442_kiel.png │ ├── preview_interp_MS │ │ ├── 16CygA_interp_preview_across_resolution.png │ │ └── 16CygA_interp_preview_along_resolution.png │ ├── ratios │ │ ├── 16CygA_corner.png │ │ ├── 16CygA_kiel.png │ │ ├── 16CygA_ratios_r012.png │ │ └── 16CygA_ratios_r012_cormap.png │ └── subgiant │ │ ├── Valid_245_corner.png │ │ ├── Valid_245_dupechelle.png │ │ ├── Valid_245_dupechelle_uncorrected.png │ │ ├── Valid_245_echelle.png │ │ ├── Valid_245_echelle_uncorrected.png │ │ ├── Valid_245_kiel.png │ │ ├── Valid_245_pairechelle.png │ │ └── Valid_245_pairechelle_uncorrected.png ├── grids.rst ├── index.rst ├── install.rst ├── make.bat ├── methods.rst ├── methods_freqs.rst ├── methods_general.rst ├── methods_intpol.rst ├── methods_stats.rst ├── methods_surfind.rst ├── param_classic.csv ├── param_filters.csv ├── prepare_doc_figures.py ├── prepare_param_table.py ├── requirements.txt ├── running.rst ├── source_auxilfuncs.rst ├── source_code.rst ├── source_fileiofuncs.rst ├── source_mainfuncs.rst ├── source_utilfuncs.rst └── troubleshoot.rst ├── examples ├── create_inputfile.py ├── data │ ├── 16CygA.ascii │ ├── Kepler_RGB.ascii │ ├── Kepler_RGB_change-phase-to-RC.ascii │ ├── freqs │ │ ├── 16CygA.fre │ │ ├── 16CygA.glh │ │ ├── 16CygA.xml │ │ ├── Valid_245.fre │ │ └── Valid_245.xml │ └── subgiant.ascii ├── preview_interpolation.py ├── process_jsonfile.py ├── reference │ ├── distance │ │ ├── 11129442_corner.pdf │ │ ├── 11129442_distance_corner.pdf │ │ └── 11129442_kiel.pdf │ ├── epsilon │ │ ├── 16CygA_corner.pdf │ │ ├── 16CygA_dupechelle.pdf │ │ ├── 16CygA_dupechelle_uncorrected.pdf │ │ ├── 16CygA_echelle.pdf │ │ ├── 16CygA_echelle_uncorrected.pdf │ │ ├── 16CygA_epsdiff_e012.pdf │ │ ├── 16CygA_epsdiff_e012_cormap.pdf │ │ ├── 16CygA_kiel.pdf │ │ ├── 16CygA_pairechelle.pdf │ │ ├── 16CygA_pairechelle_uncorrected.pdf │ │ ├── 16CygA_ratios_r012.pdf │ │ └── 16CygA_ratios_r012_cormap.pdf │ ├── freqs │ │ ├── 16CygA_corner.pdf │ │ ├── 16CygA_dupechelle.pdf │ │ ├── 16CygA_dupechelle_uncorrected.pdf │ │ ├── 16CygA_echelle.pdf │ │ ├── 16CygA_echelle_uncorrected.pdf │ │ ├── 16CygA_kiel.pdf │ │ ├── 16CygA_pairechelle.pdf │ │ └── 16CygA_pairechelle_uncorrected.pdf │ ├── glitches │ │ ├── 16CygA_corner.pdf │ │ ├── 16CygA_dupechelle.pdf │ │ ├── 16CygA_dupechelle_uncorrected.pdf │ │ ├── 16CygA_echelle.pdf │ │ ├── 16CygA_echelle_uncorrected.pdf │ │ ├── 16CygA_kiel.pdf │ │ ├── 16CygA_pairechelle.pdf │ │ └── 16CygA_pairechelle_uncorrected.pdf │ ├── global │ │ ├── 16CygA_corner.pdf │ │ └── 16CygA_kiel.pdf │ ├── interp_MS │ │ ├── 16CygA_corner.pdf │ │ ├── 16CygA_dupechelle.pdf │ │ ├── 16CygA_dupechelle_uncorrected.pdf │ │ ├── 16CygA_echelle.pdf │ │ ├── 16CygA_echelle_uncorrected.pdf │ │ ├── 16CygA_kiel.pdf │ │ ├── 16CygA_pairechelle.pdf │ │ ├── 16CygA_pairechelle_uncorrected.pdf │ │ └── intpol_example_16CygA_intpolbase.pdf │ ├── json │ │ ├── 16CygA.json │ │ ├── 16CygA_corner.pdf │ │ └── 16CygA_kiel.pdf │ ├── parallax │ │ ├── 11129442_corner.pdf │ │ ├── 11129442_distance_corner.pdf │ │ └── 11129442_kiel.pdf │ ├── phase │ │ ├── 11129442_corner.pdf │ │ └── 11129442_kiel.pdf │ ├── preview_interp_MS │ │ ├── 16CygA_interp_preview_across_resolution.pdf │ │ └── 16CygA_interp_preview_along_resolution.pdf │ ├── ratios │ │ ├── 16CygA_corner.pdf │ │ ├── 16CygA_kiel.pdf │ │ ├── 16CygA_ratios_r012.pdf │ │ └── 16CygA_ratios_r012_cormap.pdf │ └── subgiant │ │ ├── Valid_245_corner.pdf │ │ ├── Valid_245_dupechelle.pdf │ │ ├── Valid_245_dupechelle_uncorrected.pdf │ │ ├── Valid_245_echelle.pdf │ │ ├── Valid_245_echelle_uncorrected.pdf │ │ ├── Valid_245_kiel.pdf │ │ ├── Valid_245_pairechelle.pdf │ │ └── Valid_245_pairechelle_uncorrected.pdf └── xmlinput │ ├── create_inputfile_distance.py │ ├── create_inputfile_epsilondifference.py │ ├── create_inputfile_freqs.py │ ├── create_inputfile_glitches.py │ ├── create_inputfile_global.py │ ├── create_inputfile_interp_MS.py │ ├── create_inputfile_json.py │ ├── create_inputfile_parallax.py │ ├── create_inputfile_phase.py │ ├── create_inputfile_ratios.py │ └── create_inputfile_subgiant.py ├── pyproject.toml ├── setup.cfg └── src └── basta ├── __about__.py ├── __init__.py ├── bastamain.py ├── constants.py ├── distances.py ├── downloader.py ├── downloader_examples.py ├── fileio.py ├── freq_fit.py ├── glitch_fit.py ├── glitch_fq.f95 ├── glitch_sd.f95 ├── icov_sd.f95 ├── interpolation_across.py ├── interpolation_along.py ├── interpolation_combined.py ├── interpolation_driver.py ├── interpolation_helpers.py ├── plot_corner.py ├── plot_driver.py ├── plot_interp.py ├── plot_kiel.py ├── plot_seismic.py ├── plots.mplstyle ├── priors.py ├── process_output.py ├── run.py ├── sd.f95 ├── stats.py ├── utils_distances.py ├── utils_examples.py ├── utils_general.py ├── utils_seismic.py ├── utils_xml.py ├── xml_create.py └── xml_run.py /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((python-mode . ((flycheck-flake8rc . "setup.cfg") (flycheck-pylintrc . "setup.cfg")))) 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Output-folders 2 | output*/ 3 | examples/output*/ 4 | 5 | # Input/output files 6 | *.log 7 | *.pdf 8 | *.p 9 | *.dat 10 | *.res 11 | *.out 12 | *.bak 13 | *.hdf5 14 | *.htm 15 | 16 | # Re-include pdf's for the documentation 17 | !/examples/reference/*.pdf 18 | !/examples/reference/*/*.pdf 19 | 20 | # Documentation 21 | .idea 22 | docs/old 23 | docs/.idea 24 | examples/make_input.py 25 | 26 | # Demo scripts 27 | examples/*.xml 28 | examples/*/*.xml 29 | examples/grids/ 30 | reference_*/ 31 | reference_note.txt 32 | 33 | # Editor 34 | *.swp 35 | .vscode/ 36 | 37 | # Folder for downloading/storing the dustmaps (and grids) 38 | dustmaps/ 39 | _dustpath.py 40 | grids/ 41 | _gridpath.py 42 | 43 | # Virtual environment 44 | /venv*/ 45 | /bastaenv/ 46 | 47 | ########### 48 | ### Generic 49 | ########### 50 | 51 | # Byte-compiled / optimized / DLL files 52 | __pycache__/ 53 | *.py[cod] 54 | *$py.class 55 | 56 | # C extensions 57 | *.so 58 | 59 | # Distribution / packaging 60 | .Python 61 | env/ 62 | build/ 63 | develop-eggs/ 64 | dist/ 65 | downloads/ 66 | eggs/ 67 | .eggs/ 68 | lib/ 69 | lib64/ 70 | parts/ 71 | sdist/ 72 | var/ 73 | *.egg-info/ 74 | .installed.cfg 75 | *.egg 76 | 77 | # PyInstaller 78 | # Usually these files are written by a python script from a template 79 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 80 | *.manifest 81 | *.spec 82 | 83 | # Installer logs 84 | pip-log.txt 85 | pip-delete-this-directory.txt 86 | 87 | # Unit test / coverage reports 88 | htmlcov/ 89 | .tox/ 90 | .coverage 91 | .coverage.* 92 | .cache 93 | nosetests.xml 94 | coverage.xml 95 | *,cover 96 | .hypothesis/ 97 | 98 | # Translations 99 | *.mo 100 | *.pot 101 | 102 | # Django stuff: 103 | *.log 104 | 105 | # Sphinx documentation 106 | docs/_build/ 107 | 108 | # PyBuilder 109 | target/ 110 | 111 | # Ipython Notebook 112 | .ipynb_checkpoints 113 | 114 | # Checkers 115 | .mypy_cache 116 | 117 | # Pyenv 118 | .python-version 119 | 120 | # Fortran/F2PY compilation 121 | fort.* 122 | *.dSYM 123 | *.md5 124 | 125 | # Misc 126 | .DS_Store 127 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v5.0.0 4 | hooks: 5 | - id: trailing-whitespace 6 | - id: end-of-file-fixer 7 | - id: check-yaml 8 | - id: check-added-large-files 9 | args: [--maxkb=2000] 10 | - id: check-ast 11 | - id: check-merge-conflict 12 | - repo: https://github.com/psf/black 13 | rev: 24.10.0 14 | hooks: 15 | - id: black 16 | exclude: venv*/|dustmaps/|grids/ 17 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file (updated based on September 2023 migration) 3 | # https://blog.readthedocs.com/migrate-configuration-v2/ 4 | 5 | # Required 6 | version: 2 7 | 8 | # Set the version of Python and other tools you might need 9 | build: 10 | os: ubuntu-22.04 11 | tools: 12 | python: "3.12" 13 | 14 | # Build documentation in the docs/ directory with Sphinx 15 | sphinx: 16 | configuration: docs/conf.py 17 | 18 | # Specified dependencies 19 | # https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 20 | python: 21 | install: 22 | - requirements: docs/requirements.txt 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 The BASTA development team 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BASTA: The BAyesian STellar Algorithm 2 | 3 | [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) 4 | [![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 5 | [![Documentation Status](https://readthedocs.org/projects/basta/badge/?version=latest)](https://basta.readthedocs.io/en/latest/?badge=latest) 6 | [![arXiv](https://img.shields.io/badge/arXiv-2109.14622-b31b1b.svg)](https://arxiv.org/abs/2109.14622) 7 | [![ADS](https://img.shields.io/badge/ads-2022MNRAS.509.4344A-blue.svg)](https://ui.adsabs.harvard.edu/abs/2022MNRAS.509.4344A/abstract) 8 | [![DOI](https://img.shields.io/badge/doi-10.1093/mnras/stab2911-orange.svg)](https://doi.org/10.1093/mnras/stab2911) 9 | 10 | Current stable version: v1.5.3 11 | 12 | **Important note:** BASTA is currently developed for Python 3.12, but Python >= 3.10 should suffice. 13 | 14 | 15 | ## Before you begin 16 | 17 | *Please follow the repository on GitHub to get notifications on new releases: Click "Watch" then "Custom" and tick "Releases.* 18 | 19 | Please have a look at [our documentation](https://basta.readthedocs.io/en/latest/index.html#). 20 | 21 | There we have written a guide [guide to installing BASTA](https://basta.readthedocs.io/en/latest/install.html). 22 | 23 | On there, you will also find an [introduction to running BASTA](https://basta.readthedocs.io/en/latest/running.html). 24 | 25 | If you are curious on what BASTA can do, we have created several [fitting examples](https://basta.readthedocs.io/en/latest/examples.html) and the exact code to run them available. 26 | 27 | If you have any questions, or encounter any issues, feel free to write to us through the [discussions page](https://github.com/orgs/BASTAcode/discussions). 28 | 29 | 30 | ## Quick start guide 31 | 32 | BASTA can be obtained from GitHub or from the Python Package Index (PyPI); the full details are given in the documentation. 33 | 34 | *We strongly recommend to create a fresh virtual environment to install BASTA in!* 35 | 36 | With the virtual environment activated: 37 | 38 | ``` 39 | pip install basta 40 | ``` 41 | or 42 | ``` 43 | pip install https://github.com/BASTAcode/BASTA/archive/refs/heads/main.zip 44 | ``` 45 | 46 | To make the code ready to run you need to download some additional assets: a grid of stellar models and the dustmaps. To complete the setup of the code and download the grid used in most of our examples run the following (feel free to change the paths as you like): 47 | 48 | ``` 49 | mkdir -p ~/BASTA/grids 50 | mkdir -p ~/BASTA/dust 51 | BASTAdownload --gridpath ~/BASTA/grids --dustpath ~/BASTA/dust 16CygA 52 | ``` 53 | 54 | Finally, to obtain the full suite of examples run: 55 | 56 | ``` 57 | cd ~/BASTA 58 | BASTAexamples full 59 | ``` 60 | 61 | Congratulations! You now have a fully functional installation of BASTA! We strongly recommend looking at the documentation for information on how to use the code. 62 | 63 | 64 | 65 | 66 | 67 | ## References and acknowledgments 68 | 69 | There are two papers containing the rationale, main features, and capabilities of the code: 70 | 71 | * [The BASTA paper I](https://ui.adsabs.harvard.edu/abs/2015MNRAS.452.2127S/abstract). 72 | * [The BASTA paper II](https://ui.adsabs.harvard.edu/abs/2022MNRAS.509.4344A/abstract). 73 | 74 | Please cite these references if you use BASTA in your work, and include the link to the code's repository `https://github.com/BASTAcode/BASTA`. 75 | 76 | Due to its versatility, BASTA is used in a large variety of studies requiring robust determination of fundamental stellar properties. We have compiled a (non-exhaustive) [list of papers using BASTA results](https://ui.adsabs.harvard.edu/public-libraries/x2tCt52HR_yqG-oaUabo_A) that showcases these applications. If your paper using BASTA results is missing from the list please contact us. 77 | 78 | 79 | ## Authors 80 | 81 | The current core developing team members are: 82 | 83 | * Jakob Lysgaard Rørsted (maintainer) 84 | * Mark Lykke Winther (co-maintainer) 85 | * Amalie Stokholm (co-maintainer) 86 | * Kuldeep Verma 87 | 88 | 89 | The original author of the code is: 90 | 91 | * Víctor Aguirre Børsen-Koch 92 | 93 | 94 | Throughout the years, many people have contributed to the addition and development of various parts and modules of BASTA. We welcome further contributions from the community as well as issues reporting. Please look at the [contribution section](https://basta.readthedocs.io/en/latest/contributing.html) in the documentation for further details. 95 | 96 | 97 | ## Listings 98 | 99 | In addition to the shields/icons in the top, BASTA can be found in the following software listings/catalogues: 100 | 101 | * Astrophysics Source Code Library / [ASCL](https://ascl.net/2110.010) 102 | * Exoplanet Modeling and Analysis Center / [EMAC](https://emac.gsfc.nasa.gov#bbcded4b-27d8-49f5-be4d-76e1fec748eb) 103 | * The Python Package Index / [PyPI](https://pypi.org/project/basta/) 104 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = BASTA 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/basta_crop_low-res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/basta_crop_low-res.png -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | 16 | # Make the modules importable 17 | sys.path.insert(0, os.path.abspath("..")) 18 | sys.path.insert(0, os.path.abspath("../src")) 19 | sys.path.insert(0, os.path.abspath("../src/basta")) 20 | sys.path.insert(0, os.path.abspath("../examples")) 21 | 22 | # -- Project information ----------------------------------------------------- 23 | 24 | # General information about the project. 25 | project = "BASTA" 26 | copyright = "2025, The BASTA Team" 27 | author = "The BASTA Team" 28 | 29 | # The short X.Y version. 30 | version = "1.5.3" 31 | 32 | # The full version, including alpha/beta/rc tags. 33 | release = "1.5.3" 34 | 35 | 36 | # -- General configuration ------------------------------------------------ 37 | 38 | # Add any Sphinx extension module names here, as strings. They can be 39 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 40 | # ones. 41 | extensions = [ 42 | "sphinx.ext.autodoc", 43 | "sphinx.ext.todo", 44 | "sphinx.ext.mathjax", 45 | "sphinx.ext.viewcode", 46 | "sphinx.ext.napoleon", 47 | ] 48 | 49 | # Napoleon (docstring reading) settings 50 | napoleon_google_docstring = False 51 | napoleon_use_param = False 52 | napoleon_use_rtype = False 53 | 54 | # Add any paths that contain templates here, relative to this directory. 55 | templates_path = ["_templates"] 56 | 57 | # The suffix(es) of source filenames. 58 | # You can specify multiple suffix as a list of string: 59 | # 60 | source_suffix = ".rst" 61 | 62 | # The master toctree document. 63 | master_doc = "index" 64 | 65 | # The language for content autogenerated by Sphinx. Refer to documentation 66 | # for a list of supported languages. 67 | # 68 | # This is also used if you do content translation via gettext catalogs. 69 | # Usually you set "language" from the command line for these cases. 70 | language = "en" 71 | 72 | # List of patterns, relative to source directory, that match files and 73 | # directories to ignore when looking for source files. 74 | # This patterns also effect to html_static_path and html_extra_path 75 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] 76 | 77 | # The name of the Pygments (syntax highlighting) style to use. 78 | pygments_style = "sphinx" 79 | 80 | # If true, `todo` and `todoList` produce output, else they produce nothing. 81 | todo_include_todos = False 82 | 83 | # Example configuration for intersphinx: refer to the Python standard library. 84 | intersphinx_mapping = {"https://docs.python.org/3/": None} 85 | 86 | # This value contains a list of modules to be mocked up. This is useful when some 87 | # external dependencies are not met at build time and break the building process. 88 | # You may only specify the root package of the dependencies themselves and omit 89 | # the sub-modules: 90 | autodoc_mock_imports = [ 91 | "astropy", 92 | "bottleneck", 93 | "dustmaps", 94 | "h5py", 95 | "healpy", 96 | "matplotlib", 97 | "scikit-learn", 98 | "sklearn", 99 | "scipy", 100 | "tqdm", 101 | "basta._dustpath", 102 | "basta._gridpath", 103 | ] 104 | 105 | 106 | # -- Options for HTML output ---------------------------------------------- 107 | 108 | # The theme to use for HTML and HTML Help pages. See the documentation for 109 | # a list of builtin themes. 110 | html_theme = "sphinx_rtd_theme" 111 | 112 | # Add any paths that contain custom static files (such as style sheets) here, 113 | # relative to this directory. They are copied after the builtin static files, 114 | # so a file named "default.css" will overwrite the builtin "default.css". 115 | html_static_path = ["_static"] 116 | 117 | # Logo 118 | html_logo = "basta_crop_low-res.png" 119 | html_theme_options = { 120 | "logo_only": True, 121 | } 122 | 123 | 124 | # -- Options for HTMLHelp output ------------------------------------------ 125 | 126 | # Output file base name for HTML help builder. 127 | htmlhelp_basename = "BASTAdoc" 128 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. _contrib: 2 | 3 | Contributing to BASTA 4 | ##################### 5 | 6 | First off all, thanks for taking the time to contribute! 7 | 8 | Found a bug? Have a new feature to suggest? Want to contribute changes? Make sure to read this first. 9 | 10 | This is still work-in-progress, as we have only just made the code public and changed workflow as a result of a migration from GitLab to GitHub. 11 | 12 | 13 | .. _contrib_bugs: 14 | 15 | How can I report bugs and errors? 16 | ********************************* 17 | 18 | This section guides you through submitting a bug report. Following these guidelines helps maintainers understand your report, reproduce the behavior, and find related reports. 19 | 20 | Report bugs 21 | =========== 22 | 23 | Before creating bug reports, please check the following: 24 | 25 | * If you can reproduce the problem in the latest version of BASTA. 26 | * If the problem has already been reported. Perform a `cursory search `_ and if the issue is still open add a comment to it instead of opening a new one. 27 | 28 | How Do I Submit A (Good) Bug Report? 29 | ==================================== 30 | 31 | Bugs are tracked as `Github issues `_. Explain the problem and include additional details to help 32 | maintainers reproduce the problem: 33 | 34 | * Use a clear and descriptive title for the issue to identify the problem. 35 | * Describe the exact steps which produce the problem in as many details as possible. 36 | * Describe the behavior you observed after following the steps and point out what exactly is the problem with that behavior. 37 | * Explain which behavior you expected to see instead and why. 38 | * If the problem was not triggered by a specific action, describe what you were doing before the problem happened and share more information using the guidelines below. 39 | * Did the problem start happening recently (e.g. after updating to a new version of BASTA) or was this always a problem? 40 | * If the problem started happening recently, can you reproduce the problem in an older version of BASTA? What is the most recent version in which the problem does not happen? 41 | 42 | Include details about your configuration and environment: 43 | 44 | * Which version of BASTA are you using? 45 | * Are you running BASTA in the virtual environment? 46 | * What is the name and version of the OS you are using? 47 | 48 | 49 | .. _contrib_add: 50 | 51 | How can I add new features? 52 | *************************** 53 | 54 | This section guides you through how you can begin contribution to BASTA. Affected by the migration and still work in progress... 55 | 56 | Please make a fork of the repository. In your fork, please make a new branch for the feature you want to add (or bug you want to fix or...). 57 | 58 | If you did not activate the git hooks during installation, now is the time to do so: 59 | 60 | .. code-block:: bash 61 | 62 | source venv/bin/activate 63 | pre-commit install 64 | 65 | 66 | It might take a minute or two to complete. Now, to ensure everything is 67 | correctly setup, run the command: 68 | 69 | .. code-block:: bash 70 | 71 | pre-commit run --all-files 72 | 73 | 74 | It should pass all checks. 75 | 76 | To share your improvements with us, please make a pull request. Before doing that, have a look at :ref:`contrib_style`. 77 | 78 | 79 | .. _contrib_enhanc: 80 | 81 | Suggesting enhancements to the core-devel team 82 | ********************************************** 83 | 84 | This section guides you through submitting an enhancement suggestion for BASTA, including completely new features and minor improvements to existing functionality. Following these guidelines helps developers and the community understand your suggestion and find related suggestions. 85 | 86 | Before Submitting An Enhancement Suggestion 87 | =========================================== 88 | 89 | Perform a `cursory search `_ to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one. 90 | 91 | How Do I Submit A (Good) Enhancement Suggestion? 92 | ================================================ 93 | 94 | Enhancement suggestions are tracked as `Github issues `_. Please create an issue and provide the following information: 95 | 96 | * Use a clear and descriptive title for the issue to identify the suggestion. 97 | * Provide a step-by-step description of the suggested enhancement in as many details as possible. 98 | * Describe the current behavior and explain which behavior you expected to see instead and why. 99 | 100 | 101 | .. _contrib_style: 102 | 103 | Styleguides 104 | *********** 105 | 106 | Git Commit Messages 107 | =================== 108 | 109 | * Use the imperative mood ("Move cursor to..." not "Moves cursor to..." or "Moved cursor to...") 110 | * Limit the first line to 72 characters or less 111 | 112 | Pull requests 113 | ============= 114 | 115 | * When you make the pull request, it is important to set the target branch to ``devel``. Be sure to do this as the first thing, since your description text will disappear then you change the target. 116 | * If the new-feature is still a work-in-progress, please state so in the title of the merge request (e.g. 'WIP: Resample corner plots'). When your branch is ready to be merged, please remove the 'WIP' in the title of your merge request. 117 | * If applicable, refer to the issue(s) your merge request will fix. 118 | 119 | Code style 120 | ========== 121 | 122 | BASTA uses the code style defined by the `Black formatter `_. 123 | 124 | 125 | Disclaimer 126 | ********** 127 | 128 | This contribution guide was inspired by the amazing contribution guide to the `Atom project `_. 129 | -------------------------------------------------------------------------------- /docs/controls.rst: -------------------------------------------------------------------------------- 1 | .. _controls: 2 | 3 | All controls 4 | ============ 5 | 6 | The following sections give the full overview and documentation of the control options in BASTA. 7 | For the recommended set of control options for each fitting case BASTA is used for, see instead :ref:`examples`. 8 | 9 | The methods employed are described in the :ref:`BASTA papers`, while the following is 10 | the documentation of how the controls for these methods are adjusted. The documentation follows 11 | the structure of the :py:func:`define_input` template function in ``BASTA/examples/create_inputfile.py``, 12 | separated into individual sections for each control group (python dictionary) being: 13 | 14 | .. toctree:: 15 | :maxdepth: 1 16 | 17 | controls_parameters 18 | controls_io 19 | controls_fit 20 | controls_outplots 21 | controls_intpol 22 | 23 | For examples of input files for each fitting case, with the recommended options, see the template 24 | files ``BASTA/examples/xmlinput/create_inputfile_*.py`` (which can be obtained with the `BASTAexamples` tools, if you do not already have it). 25 | 26 | When the control options have been set, the fit is performed (as explained in :ref:`running`) by 27 | creating the ``xml`` input file, which is then run by BASTA. This is done using the commands 28 | 29 | .. code-block:: bash 30 | 31 | source bastaenv/bin/activate 32 | python create_inputfile.py 33 | BASTArun input_myfit.xml 34 | -------------------------------------------------------------------------------- /docs/controls_intpol.rst: -------------------------------------------------------------------------------- 1 | .. _controls_intpol: 2 | 3 | Interpolation controls 4 | ********************** 5 | 6 | In the following, an overview of all control options related to the BASTA 7 | interpolation routine is given, which corresponds to the interpolation controls 8 | block in the :py:func:`define_input` function in the ``create_inputfile.py`` 9 | scripts. To see the recommended/default usage of these 10 | controls for specific fitting cases, see the :ref:`examples ` section, or the provided 11 | example scripts ``BASTA/examples/xmlinput/create_inputfile_*.py``. 12 | For an overview of the routine, see the :ref:`method section `. 13 | 14 | Overall, the interpolation routine is a large, almost separate, module for BASTA. 15 | It improves the resolution of the grid of models by interpolating between/along 16 | tracks. This allows for the posterior distributions to be smoother, and gaps in 17 | the parameter space to be filled. The routine is however based on many 18 | user-defined choices, and has not been tested in extensive details. It is thus 19 | an **experimental feature**, and should be used with care. 20 | 21 | This feature is toggled on/off with the boolean 22 | 23 | .. code-block:: python 24 | 25 | interpolation = False 26 | 27 | 28 | which by default is turned off. The following description is based 29 | around interpolating a grid of stellar evolutionary tracks. The 30 | method is however also applicable to grids of stellar isochrones, whereby 31 | the words tracks and isocohrones are interchangeable in the descriptions. 32 | 33 | 34 | Sub-grid from limits 35 | ==================== 36 | .. code-block:: python 37 | 38 | define_intpol["intpolparams"]["limits"] = { 39 | "Teff": {"sigmacut": 1}, 40 | "FeH": {"abstol": 0.2}, 41 | } 42 | 43 | The part of the original grid to be interpolated within (sub-grid), 44 | is defined through these limits. The application/usage is identical to 45 | the :ref:`flat priors `, and it is generally 46 | recommended using a wider prior/limit here than when fitting, to ensure 47 | the interpolated grid actually covers the desired parameter range of the 48 | following fit. 49 | 50 | 51 | Definition of applied method 52 | ============================ 53 | .. code-block:: python 54 | 55 | define_intpol["intpolparams"]["method"] = { 56 | "case": "combined", 57 | "construction": "bystar", 58 | } 59 | 60 | Defines the overarching methods by which interpolation should be applied. 61 | The keyword ``case`` controls which interpolation method should be used 62 | among the following 63 | 64 | * ``along``: Interpolation purely along the tracks of the sub-grid, to increase the resolution within the tracks, but not place new between the tracks. 65 | * ``across``: Interpolation purely across the tracks of the sub-grid. New tracks will be placed in between the originals, while the resolution along the track will attempt to mimic the original tracks used for interpolation. 66 | * ``combined``: Interpolation will be applied both across and along the tracks in the sub-grid, in a combined approach. When this mode is selected, it therefore needs the control blocks of both methods to be provided. 67 | 68 | The keyword ``construction`` controls how interpolation is applied for a 69 | BASTA run with multiple stars. If set to ``"bystar"``, a sub-grid based on 70 | provided limits will be determined and interpolated within for each star 71 | being fitted. If set to ``"encompass"``, a single sub-grid based on the 72 | proivded limits applied to the full range of observed parameters across 73 | all inputted stars will be determined and interpolated within, and then 74 | used when fitting all of the stars. For example, if an absolute tolerance 75 | limit of 300K is set for a sample of stars ranging from 5500K to 6100K in 76 | effective temperature, the sub-grid will span fram 5350K to 6250K. 77 | 78 | Name of interpolated grid 79 | ========================= 80 | 81 | .. code-block:: python 82 | 83 | define_intpol["intpolparams"]["name"] = "testgrid" 84 | 85 | Optional control of the name of the outputted interpolated sub-grid. 86 | The name will always be preceded by ``intpol_``, and if the method of 87 | construction is ``"bystar"``, the identifier of the star will be appended 88 | to the name. If not provided, the name will be the same as the original 89 | grid. 90 | 91 | Across tracks resolution 92 | ======================== 93 | 94 | .. code-block:: python 95 | 96 | define_intpol["intpolparams"]["gridresolution"] = { 97 | "scale": 1.5, 98 | "baseparam": "rhocen", 99 | "extend": False, 100 | } 101 | 102 | Control group for how to scale resolution across the tracks. 103 | 104 | The ``scale`` indicates the minimum multiplicative factor by which the 105 | number of tracks should be increased. For example, if the sub-grid 106 | contains 10 tracks, and ``scale`` is set to 1.5, *at least* 15 new tracks 107 | will be interpolated to. 108 | 109 | The ``baseparam`` defines what quantity along the tracks should be used 110 | as a base for interpolation. This should be a continuous, monotonic function 111 | that scales with evolutionary phase. Preliminary testing determined central 112 | density (:math:`\rho_{\text{cen}}`, ``"rhocen"``) to generally be a good choice, 113 | central hydrogen abundance (:math:`X_{\text{cen}}`, ``"xcen"``) to be good for 114 | exclusively main-sequence grids, and the large frequency separation (:math:`\Delta\nu`, 115 | ``"dnufit"``) to be good when interpolating individual frequencies. 116 | 117 | The ``extend`` key toggles whether the original tracks in the sub-grid should be 118 | copied to the interpolated grid. This is by default ``False``, as this interferes 119 | with the desired homogeneity of the distribution of models in the grid. For the 120 | ``combined`` case of interpolation they will also have a different resolution along 121 | the tracks. However, the impact on the derived posterior is alleviated by the 122 | weighting of models/tracks according to their occupied volume in the parameter space, 123 | and thus including the original tracks should not cause discrepancies, and allows 124 | for a denser occupation of the parameter space. 125 | 126 | 127 | Along tracks resolution 128 | ======================= 129 | .. code-block:: python 130 | 131 | define_intpol["intpolparams"]["trackresolution"] = { 132 | "param": "dnufit", 133 | "value": 0.01, 134 | "baseparam": "rhocen", 135 | } 136 | 137 | Control group for how to scale resolution along the tracks. 138 | 139 | The ``param`` key defines the parameter for which a certain resolution is desired, 140 | and can be any continuous, monotonic parameter. The ``value`` key defines the target 141 | resolution in this parameter, in the units provided in the :ref:`parameter list `. 142 | 143 | The ``baseparam`` key defines what parameter is used as a base for interpolation. 144 | A transformation between this and the above resolution parameter is then made, as 145 | the resolution parameter might not be an appropriate choice to use as a base for 146 | interpolation (see :ref:`description in methods `). 147 | -------------------------------------------------------------------------------- /docs/controls_io.rst: -------------------------------------------------------------------------------- 1 | .. _controls_io: 2 | 3 | I/O controls 4 | ************ 5 | 6 | The following lists all possible control options for the I/O control block in the :py:func:`define_input` 7 | function in the ``create_inputfile.py`` scripts. To see the recommended/default usage of these 8 | controls for specific fitting cases, see the :ref:`examples ` section, or the provided 9 | example scripts ``BASTA/examples/xmlinput/create_inputfile_*.py``. 10 | 11 | .. _Name of input file: 12 | 13 | Name of input file 14 | ================== 15 | .. code-block:: python 16 | 17 | xmlfilename = "input_myfit.xml" 18 | 19 | Name and location of the produced input file to be run by BASTA. The only requirement 20 | is for it to end on ``xml``. From there the user can freely define name and location 21 | of the file, e.g. when producing multiple input file for different frequency fitting methods, 22 | whereby the user might want to store them as ``freqfits/input03_r012.xml``. 23 | 24 | Name of grid file 25 | ================= 26 | .. code-block:: python 27 | 28 | define_io["gridfile"] = os.path.join(BASTADIR, "grids", "Garstec_16CygA.hdf5") 29 | 30 | Name and location of the grid of stellar models to fit the observed stars to. It must be provided 31 | as a :py:func:`hdf5` file, otherwise there are no requirements on location or name. 32 | 33 | The default points to the standard location of grids downloaded 34 | using the :py:func:`BASTAdownload` command (see :ref:`grids`), that being the ``grids/`` directory 35 | within the main BASTA directory. The default grid used (``Garstec_16CygA.hdf5``) is the small grid 36 | computed for the star 16 Cyg A, specifically for the examples given in :ref:`the examples `. 37 | 38 | .. _controls_io_outputdir: 39 | 40 | Output directory 41 | ================ 42 | .. code-block:: python 43 | 44 | define_io["outputpath"] = os.path.join("output", "myfit") 45 | 46 | The directory into which the output from the BASTA run will be stored, relative to the location of 47 | the :ref:`input file`. If the directory does not exist, it will be created on 48 | startup of BASTA. 49 | 50 | .. _controls_io_paramfile: 51 | 52 | Observed parameters file 53 | ======================== 54 | .. code-block:: python 55 | 56 | define_io["asciifile"] = os.path.join("data", "16CygA.ascii") 57 | 58 | The name and location of the user-provided stellar parameters to be fitted. It must 59 | be provided in ASCII format, readable by the 60 | `numpy.genfromtxt `_ 61 | routine. Location is provided relative to the location from which the python script is run. 62 | This constitutes the list of stars for which the defined fit is run. 63 | For a basic example, see the ``BASTA/examples/data/16CygA.ascii`` file, for a single star. 64 | 65 | .. code-block:: python 66 | 67 | define_io["params"] = ( 68 | "starid", 69 | "RA", 70 | "DEC", 71 | "numax", 72 | "numax_err", 73 | "dnu", 74 | "dnu_err", 75 | "Teff", 76 | "Teff_err", 77 | "FeH", 78 | "FeH_err", 79 | "logg", 80 | "logg_err", 81 | ) 82 | 83 | The by-column definition of which parameters are in the file. The first entry must be the 84 | ``starid``, which is the identifying string/name of the star(s). It must be unique and compatible 85 | with the filesystem on which BASTA is run, as by-star output files uses this identifier for the 86 | naming of the files. 87 | 88 | The remaining names in the ``params`` tuple *must follow the order* in which they are provided in 89 | the ASCII file, all columns must be named in the tuple, and the names must match the parameter names 90 | in BASTA's :ref:`parameter list `, where 91 | the units assumed by BASTA is also available. The associated error of a parameter must be provided 92 | as a distinct column with the same name of the parameter followed by ``_err``. 93 | 94 | The only exception is the large frequency separation, :math:`\Delta\nu`, which here should simply 95 | be ``dnu``, as it has multiple purposes depending on the methods employed. If the parameter is 96 | fitted directly, the grid value it is compared to is defined in the :ref:`list of fit parameters `. 97 | 98 | Note that the provided parameters can exceed the parameters needed by BASTA, as it simply searches 99 | this list for what it needs. Therefore, the user can supply a single file with all available information 100 | for the given star(s), and use it in multiple different runs of BASTA that needs different parameters, 101 | as long as the necessary parameters are provided. 102 | 103 | 104 | Format options 105 | -------------- 106 | If the user has a parameter file in a specific format, the following options can be passed to 107 | the `numpy.genfromtxt `_ 108 | routine, to allow BASTA to load it. 109 | 110 | .. code-block:: python 111 | 112 | define_io["delimiter"] = "," 113 | 114 | This can be set to change the assumed delimiter between columns in the ASCII file. It is ``None`` 115 | by default, which means any consecutive whitespace act as a delimiter. 116 | 117 | .. code-block:: python 118 | 119 | define_io["missingval"] = -999.999 120 | 121 | Placeholder value to indicate missing values. It is generally advised to provide BASTA with a 122 | complete table with bad stars removed, but using this key, missing values can be ignored. 123 | This might be useful if a large pre-computed table is provided, where some data is not available 124 | for all stars. 125 | 126 | Be aware that if a :ref:`parameter to be fitted` is missing, the star will be skipped! 127 | 128 | .. code-block:: python 129 | 130 | define_io["overwriteparams"] = {"dnufit": (100, 2)} 131 | 132 | Overwrite the value and error of a given parameter, for every star. Given as dictionary entries 133 | in the form ``{paramerer: (value, error)}``. 134 | -------------------------------------------------------------------------------- /docs/controls_outplots.rst: -------------------------------------------------------------------------------- 1 | .. _controls_outplots: 2 | 3 | Output controls 4 | *************** 5 | 6 | In the following, an overview of the all the controls related to what will be outputted 7 | when running BASTA is given, which corresponds to the fitting controls block in the :py:func:`define_input` 8 | function in the ``create_inputfile.py`` scripts. To see the recommended/default usage of these 9 | controls for specific fitting cases, see the :ref:`examples ` section, or the provided 10 | example scripts ``BASTA/examples/xmlinput/create_inputfile_*.py``. 11 | 12 | Output file 13 | =========== 14 | 15 | .. code-block:: python 16 | 17 | define_output["outputfile"] = "results.ascii" 18 | 19 | Name of the outputted ASCII file containing the inferred parameters (listed below here). 20 | Will be placed in the given :ref:`output directory `, and can be 21 | any format that can be created using `numpy.savetxt `_. 22 | 23 | .. _controls_outplots_outparams: 24 | 25 | Output/inferred parameters 26 | ========================== 27 | .. code-block:: python 28 | 29 | define_output["outparams"] = ("Teff", "FeH", "logg", "radPhot", "massfin", "age") 30 | 31 | List of parameters to be inferred and printed to output. Can be any parameter 32 | contained in the grid, and listed in the :meth:`parameter list `. 33 | These will be printed to the output file in the same order as provided. It is 34 | recommended to **always** include the :ref:`parameters being fitted `, 35 | to compare with the observed values. 36 | 37 | A special keyword that can be included is ``"distance"``, which will try to 38 | infer the distance to the star given observed magnitudes and coordinates, as 39 | shown in :ref:`the example ` or explained in 40 | :ref:`the method section `. 41 | 42 | Optional outputs 43 | ================ 44 | .. code-block:: python 45 | 46 | define_output["optionaloutputs"] = True 47 | 48 | Will produce a dump (`.json` file) of the :math:`\chi^2` and logarithmic likelihood of 49 | each model considered in the fit (not excluded by :ref:`priors `), 50 | by default ``False``. This can be read into python using :meth:`filio.load_selectedmodels`, 51 | and used to determine and compare the N'th best fitting model, or similar statistics. 52 | 53 | 54 | Output statistics 55 | ================= 56 | By default, BASTA reports/outputs the median, 16th and 84th quantiles of the 57 | posterior distribution of the given parameter. However, should the user want 58 | to change this (e.g. to compare against other methods), it is done through 59 | the following options. 60 | 61 | .. code-block:: python 62 | 63 | define_output["centroid"] = "mean" 64 | define_output["uncert"] = "std" 65 | 66 | The ``centroid`` can be changed between reporting the ``median`` of the distribution 67 | (default) and reporting the ``mean`` value. The unceartainty (``uncert``) can be changed 68 | between reporting the ``quantiles`` (default) or the standard deviation (``std``). 69 | 70 | Plotting controls 71 | ================= 72 | 73 | In the following, an overview of the plotting related controls are given. These 74 | control which of the automatically generatable plots should be produced when 75 | running BASTA. 76 | 77 | Corner plot 78 | ----------- 79 | .. code-block:: python 80 | 81 | define_plots["cornerplots"] = define_output["outparams"] 82 | 83 | The list of parameters to display the posterior distributions and correlations of in 84 | a corner diagram. This is typically set to the same as the :ref:`outputted parameter `, 85 | but can be set with a separate tuple of parameters. If ``"distance"`` is present in 86 | the list/tuple, an additional corner diagram with the distance-related parameters is 87 | produced. 88 | 89 | 90 | Kiel diagram 91 | ------------ 92 | .. code-block:: python 93 | 94 | define_plots["kielplots"] = True 95 | 96 | Toggle for outputting a Kiel (HR) diagram of the resulting fit. This displays the 97 | tracks/isochrones considered in the fit, and overlays the observed parameters using 98 | different colours, to give a visual representation of the convergence of observed 99 | parameters across the models. 100 | 101 | .. _controls_outplots_freqplots: 102 | 103 | Individual frequencies plots 104 | ---------------------------- 105 | .. code-block:: python 106 | 107 | define_plots["freqplots"] = False 108 | 109 | Controls for which plots to be produced, from the individual frequencies and/or 110 | quantities derived therefrom, of the best fitting model compared to the observations. 111 | This requires the individual frequencies to be supplied (see :ref:`controls_fit_freqparams`), 112 | and be available in the grid. If set to ``False`` none of the plots will be produced, 113 | while ``True`` will produce *all* figures (with default choices of sequences for the 114 | derived quantities) for each star being fitted. They are placed in the 115 | :ref:`output directory ` following the syntax ``_.``. 116 | 117 | The plots can enabled individually by instead providing a tuple with the names of 118 | plots to be produced. The options are: 119 | 120 | * ``echelle``: Produces two échelle diagrams of the provided observed individual frequencies against the models, one being with the surface-corrected model frequencies, and the other the uncorrected model frequencies, whereby the ``_uncorrected`` is added to the filename. Using different keys, varied versions of the échelle diagrams are produced. The options are: 121 | 122 | * ``echelle``: Simplest version of the diagram, as described above. 123 | * ``pairechelle``: Adds a line between the observed frequencies and the matched model frequency. 124 | * ``dupechelle``: Same as ``pairechelle``, but adds a duplicated panel, so sequences crossing the axis can be visualized in a clearer way. 125 | * ``allechelle``: Produces *all* the above versions. 126 | * ``ratios``: Produces a plot of the observed frequency ratios against the best fitting model. If ratios are being fitted, it will plot the sequence being fitted. If not fitted, the default ``r01`` sequence will be plotted. Instead of ``ratios``, specific sequences can be set in the list to produce plots for specific sequences. Multiple can be defined at the same time. 127 | * ``epsdiff``: Same as for ratios, but for the phase shift differences. Default is the ``e012`` sequence. 128 | 129 | If ``correlations`` in the :ref:`freqparams ` input is set 130 | to ``True``, a correlation map of the individual frequencies or derived quantities 131 | will also be produced, following the syntax ``__cormap.``. 132 | 133 | Plot format 134 | ----------- 135 | .. code-block:: python 136 | 137 | define_plots["plotfmt"] = "pdf" 138 | 139 | Defines the format of which figures are created. Default is ``png`` which is a 140 | small format, so preferable when creating many figures/fitting multiple stars. 141 | However, if high resolution/vector graphics is desirable, ``pdf`` is recommended. 142 | Otherwise, it can be any file format compatible with 143 | `matplotlib.pyplot.savefig `_. 144 | 145 | 146 | Star identifier in plots 147 | ------------------------ 148 | .. code-block:: python 149 | 150 | define_plots["nameinplot"] = True 151 | 152 | The star identifier is normally only contained in the name of plot files. 153 | However, depending on the preferred post-processing procedure of the user, 154 | it can be beneficial to include in the plots itself, which can be turned 155 | on using this key. Currently, only implemented for Kiel diagram and corner plots. 156 | -------------------------------------------------------------------------------- /docs/controls_parameters.rst: -------------------------------------------------------------------------------- 1 | .. _controls_params: 2 | 3 | Available model parameters 4 | ************************** 5 | 6 | In the following, the list of all parameters that are recognized 7 | by BASTA is listed, which is extracted from the :meth:`constants.parameters` 8 | class. 9 | 10 | **Please note** that these might not be available/present in the grid, 11 | and there might also be parameters available in the grid that are not 12 | listed here. If these are added to the list in the :meth:`module `, 13 | these can also be fitted using BASTA. 14 | 15 | .. _controls_params_classic: 16 | 17 | Classical parameters 18 | ==================== 19 | 20 | .. csv-table:: Model parameters available in BASTA 21 | :file: ../docs/param_classic.csv 22 | :delim: | 23 | :header-rows: 1 24 | 25 | 26 | .. _controls_params_filters: 27 | 28 | Synthetic magnitudes 29 | ==================== 30 | 31 | .. csv-table:: Magnitudes for given filters 32 | :file: ../docs/param_filters.csv 33 | :delim: | 34 | :header-rows: 1 35 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | .. _examples: 2 | 3 | Examples of fits 4 | ################ 5 | 6 | *Important:* If you did not clone the code from GitHub and did not download the examples yet, please run: 7 | 8 | .. code-block:: bash 9 | 10 | cd ~/BASTA 11 | BASTAexamples full 12 | 13 | 14 | The following sections give practical examples of commonly used fits with BASTA, and explain the options in the code following the template given in :py:func:`define_input` in ``BASTA/examples/create_inputfile.py`` (in the following this will be denoted as :py:meth:`create_inputfile.define_input`). 15 | 16 | The fitting examples are located in ``BASTA/examples/xmlinput/`` and a reference set of output can be found in ``BASTA/examples/reference/``, which includes all fits described in the following sections. These can be compared to the output you obtain when running the code as a further sanity check. 17 | 18 | Overview of fitting examples: 19 | 20 | .. toctree:: 21 | :maxdepth: 1 22 | 23 | examples_global 24 | examples_freqs 25 | examples_isochrones 26 | examples_interpolation 27 | 28 | 29 | Additional (non-fitting) examples 30 | ================================= 31 | 32 | In ``BASTA/examples`` two additional files are present: 33 | 34 | * ``process_jsonfile.py``, which shows how to use the ``.json`` files from BASTA. These files are a full dump of the likelihood information for the full grid and can be used to re-create e.g. posterior distributions for a completed fit without re-running BASTA. `Note:` For this example to work, one of the two fitting examples producing a ``.json`` file (either the default template or the one denoted ``_json``) must be completed prior to running this. 35 | 36 | * ``preview_interpolation.py``, which can be used to visualise a specific set of settings for interpolation in a grid. This is useful for deciding on limits and resolution before running the fit, as the full interpolation itself can be rather time consuming. More details are given in the :ref:`example_interp` example. 37 | -------------------------------------------------------------------------------- /docs/examples_global.rst: -------------------------------------------------------------------------------- 1 | .. _example_global: 2 | 3 | Spectroscopy and global asteroseismic parameters 4 | ************************************************ 5 | 6 | This example describes the fitting of what we call global parameters of the grid, with a specific application to 7 | asteroseismology for illustration purposes. As a general recommendation, the user should explore the 8 | :ref:`parameter list ` for a complete list of available fitting parameters. 9 | 10 | Block 2 of :py:meth:`create_inputfile.define_input` (in ``BASTA/examples/create_inputfile.py``) defines the fitting parameters. For this example it looks as follows: 11 | 12 | .. code-block:: python 13 | 14 | # ================================================================================== 15 | # BLOCK 2: Fitting control 16 | # ================================================================================== 17 | define_fit["fitparams"] = ("Teff", "FeH", "dnufit", "numax") 18 | 19 | 20 | That is, we will fit effective temperature, metallicity [Fe/H], the large frequency separation :math:`\Delta\nu`, and 21 | the frequency of maximum power :math:`\nu_\mathrm{max}`. Note that the input value of :math:`\Delta\nu` is called 22 | ``dnu`` in block 1 of :py:meth:`create_inputfile.define_input`, and the parameter we are fitting here is called 23 | ``dnufit``. The reason is that BASTA supports several definitions of :math:`\Delta\nu` and it is the user's decision 24 | which one to fit. A description of the various types of :math:`\Delta\nu` available is given in Section 4.1.1 of 25 | `The BASTA paper II `_, and their corresponding variable 26 | names can be found in the :ref:`parameter list `. 27 | 28 | The next block to be modified is 2a, where priors to the fit can be selected. We will apply a Salpeter IMF and flat 29 | priors in :math:`T_\mathrm{eff}` and metallicity, where the likelihoods will be calculated only for models within a 30 | certain tolerance from the observed values of each star: 31 | 32 | .. code-block:: python 33 | 34 | # ------------------------------------------------------------ 35 | # BLOCK 2a: Fitting control, priors 36 | # ------------------------------------------------------------ 37 | define_fit["priors"] = {"Teff": {"sigmacut": "5"}, "FeH": {"abstol": "0.5"}} 38 | define_fit["priors"] = {**define_fit["priors"], "IMF": "salpeter1955"} 39 | 40 | Finally, we define a reference solar model and the assumed solar values: 41 | 42 | .. code-block:: python 43 | 44 | # ------------------------------------------------------------ 45 | # BLOCK 2b: Fitting control, solar scaling 46 | # ------------------------------------------------------------ 47 | define_fit["solarmodel"] = True 48 | define_fit["sundnu"] = 135.1 49 | define_fit["sunnumax"] = 3090.0 50 | 51 | Note that, in the present example, the solar model is used to scale the grid values of ``dnufit`` as described in 52 | Section 4.1.1 of `The BASTA paper II `_. 53 | 54 | In the folder ``BASTA/examples/xmlinput/`` you can find a file called ``create_inputfile_global.py`` that has been prepared following the above instructions to make a fit of the Kepler target 16 Cyg A to the example grid shipped with 55 | the code. Simply run the following commands on your terminal: 56 | 57 | .. code-block:: bash 58 | 59 | cd BASTA 60 | source venv/bin/activate 61 | cd examples/xmlinput 62 | python create_inputfile_global.py 63 | 64 | You should see the following output printed in your terminal: 65 | 66 | .. code-block:: text 67 | 68 | ********************************************** 69 | *** Generating an XML input file for BASTA *** 70 | ********************************************** 71 | 72 | Reading user input ... 73 | Done! 74 | 75 | Running sanity checks ... 76 | Done! 77 | 78 | Creating XML input file 'input_global.xml' ... 79 | Done! 80 | 81 | 82 | Summary of the requested BASTA run 83 | ---------------------------------------- 84 | 85 | A total of 1 star(s) will be fitted with {Teff, FeH, dnufit, numax} to the grid 'BASTADIR/grids/Garstec_16CygA.hdf5'. 86 | 87 | This will output {Teff, FeH, dnufit, numax, radPhot, massfin, age} to a results file. 88 | 89 | Corner plots include {Teff, FeH, dnufit, numax, radPhot, massfin, age} with observational bands on {Teff, FeH, dnufit, numax}. 90 | Kiel diagrams will be made with observational bands on {Teff, FeH, dnufit, numax}. 91 | 92 | A restricted flat prior will be applied to: Teff, FeH. 93 | Additionally, a Salpeter1955 IMF will be used as a prior. 94 | 95 | 96 | !!! To perform the fit, run the command: BASTArun input_global.xml 97 | 98 | Once the file is created, run BASTA as explained to perform the fit: 99 | 100 | .. code-block:: bash 101 | 102 | BASTArun input_global.xml 103 | 104 | The output of the fit can be found in ``BASTA/examples/output/global/``. It includes a Kiel diagram that should 105 | look like the following: 106 | 107 | .. figure:: figures/global/16CygA_kiel.png 108 | :alt: Kiel diagram plot of the 16 Cyg A fit using global asteroseismic quantities. 109 | 110 | Kiel diagram of the 16 Cyg A fit using global asteroseismic quantities. 111 | 112 | This figure is **only** a visual aid to understand the results, as it depicts the position of the found median and best fit model within the grid. It also highlights in different colours which parts of the grid agree within the 113 | uncertainties of the inputted ``fitparams``. Note that the number of tracks plotted are selected to lie within the 16 114 | and 84 percentiles mass and metallicity output of the solution, and are **not** the only tracks present in the grid nor the only tracks used for the likelihood calculation. 115 | 116 | Finally, a corner plot of the parameters included in ``cornerplots`` is also part of the output: 117 | 118 | .. figure:: figures/global/16CygA_corner.png 119 | :alt: Corner plot of the 16 Cyg A fit using global asteroseismic quantities. 120 | 121 | Corner plot of the 16 Cyg A fit using global asteroseismic quantities. 122 | 123 | Please note that you might get distributions and numbers with tiny variations compared to what is shown above. This is because BASTA is using using a random sampling scheme to obtain the posterior distibutions. If you want to get exactly the same as in the reference examples, add ``--seed 42`` to ``BASTArun`` 124 | 125 | Finally it should be noted that the distributions are spiky, which are a reflection of the resolution of the grid (and the small uncertainties on asteroseismic parameters). If you consider this to be an issue for your purposes, don't forget to check our section on :ref:`example_interp`. 126 | 127 | **Congratulations! You just completed your first fit using BASTA. Easy-peasy, right?** 128 | -------------------------------------------------------------------------------- /docs/examples_interpolation.rst: -------------------------------------------------------------------------------- 1 | .. _example_interp: 2 | 3 | Interpolation of tracks and isochrones 4 | ************************************** 5 | 6 | If the resolutions of a particular grid is considered insufficient for a particular fit, BASTA includes the option of 7 | performing interpolation across and/or along tracks and isochrones. What the procedure does is to produce a new 8 | interpolated grid of models, store it in ``hdf5`` format, and perform a fit to the input given in ``fitparams``. Since 9 | the new interpolated grid is stored, additional fits can be made without the need of interpolating again just by using 10 | the normal BASTA scripts described in the previous examples (with the appropriate options). 11 | 12 | As a general rule, since the interpolation takes place in a restricted parameter space, all scripts given in this 13 | example do not include additional priors than the IMF in block 2a. 14 | 15 | Example: main-sequence star and tracks 16 | ====================================== 17 | 18 | In this first example we will use the grid provided with the code for the target 16 Cyg A in 19 | ``BASTA/grids/Garstec_16CygA.hdf5``. 20 | 21 | Checking/previewing the interpolation 22 | ------------------------------------- 23 | 24 | Before running the interpolation, we always recommend to check what the original coverage of the grid is, and what would be the resulting coverage given certain values for the interpolation. We have included a script in ``BASTA/examples/preview_interpolation.py`` that serves this purpose, and requires the following input: 25 | 26 | .. code-block:: python 27 | 28 | define_input["gridfile"] = os.path.join( 29 | BASTADIR, "grids", "Garstec_16CygA.hdf5" 30 | ) 31 | 32 | define_input["construction"] = "bystar" 33 | 34 | define_input["limits"] = { 35 | "Teff": {"abstol": 150}, 36 | "FeH": {"abstol": 0.2}, 37 | "dnufit": {"abstol": 8}, 38 | } 39 | 40 | Here we have defined the region of the grid where the interpolation will be carried out. In this case we select models within 150 K in effective temperature, 0.2 dex in [Fe/H], and 8 :math:`\mu \mathrm{Hz}` in large frequency separation of the observed values of 16 Cyg. We also define that the ranges are applied ``bystar``, which is not strictly relevant here as we are only fitting one star, but it is important if more than one target is interpolated at the same time. In that case ``bystar`` produces one interpolated grid per target using the limits defined in ``["limits"]`` for each target, while the ``encompass`` option produces one larger interpolated grid encompassing all targets in the list within the limits set in ``["limits"]``. 41 | 42 | The next blocks define the desired resolution along and across tracks/isochrones: 43 | 44 | .. code-block:: python 45 | 46 | outpath = os.path.join("output", "preview_interp_MS") 47 | along_interpolation = True 48 | if along_interpolation: 49 | define_along["resolution"] = { 50 | "freqs": 0.5, 51 | } 52 | define_along["figurename"] = os.path.join( 53 | outpath, "interp_preview_along_resolution.pdf" 54 | ) 55 | 56 | The parameters in ``["resolution"]`` define the resolution `along` a given track. In this case we set a value of 0.5 57 | :math:`\mu \mathrm{Hz}` in the individual oscillation frequencies, and what BASTA does is interpolating along a track 58 | such that the lowest observed l=0 mode has the required resolution of 0.5 :math:`\mu \mathrm{Hz}`. All other modes are interpolated accordingly. 59 | 60 | Finally, we define the settings for the interpolation `across/between` tracks: 61 | 62 | .. code-block:: python 63 | 64 | across_interpolation = True 65 | if across_interpolation: 66 | define_across["resolution"] = { 67 | "scale": 6 68 | } 69 | define_across["figurename"] = os.path.join( 70 | outpath, "interp_preview_across_resolution.pdf" 71 | ) 72 | 73 | Since the input grid we are using has been constructed using Sobol sampling, we define a ``scale`` parameter of 5 in 74 | ``["resolution"]``, which increases the number of tracks with respect to the original by a factor of 6. The following figures shows the new sampling, and compares the desired resolution to the `current` distributions of parameter values in the grid: 75 | 76 | .. figure:: figures/preview_interp_MS/16CygA_interp_preview_across_resolution.png 77 | :alt: Distribution in mass and metallicity of the current grid and desired interpolated grid. 78 | 79 | Distribution in mass and metallicity of the current grid (base) and desired interpolated grid. 80 | 81 | .. figure:: figures/preview_interp_MS/16CygA_interp_preview_along_resolution.png 82 | :alt: Distribution in individual frequency resolution of the current grid. 83 | 84 | Distribution in individual frequency resolution of the current grid. 85 | 86 | 87 | Running the fit with interpolation 88 | ---------------------------------- 89 | 90 | If the resolution is satisfactory for your needs, the relevant parameters to be modified in :py:meth:`create_inputfile.define_input` are those given in block 5 of the included example ``create_inputfile_interp_MS.py``. 91 | 92 | .. code-block:: python 93 | 94 | # ================================================================================== 95 | # BLOCK 5: Interpolation 96 | # ================================================================================== 97 | interpolation = True 98 | if interpolation: 99 | define_intpol["intpolparams"] = {} 100 | 101 | define_intpol["intpolparams"]["limits"] = { 102 | "Teff": {"abstol": 150}, 103 | "FeH": {"abstol": 0.2}, 104 | "dnufit": {"abstol": 8}, 105 | } 106 | 107 | define_intpol["intpolparams"]["method"] = { 108 | "case": "combined", 109 | "construction": "bystar", 110 | } 111 | 112 | define_intpol["intpolparams"]["name"] = "example" 113 | 114 | We define the name of the output grid to be ``intpol_example_16CygA.hdf5``. Next we set the level of refinement in 115 | the interpolation. 116 | 117 | .. code-block:: python 118 | 119 | define_intpol["intpolparams"]["gridresolution"] = { 120 | "scale": 6.0, 121 | "baseparam": "rhocen", 122 | } 123 | 124 | define_intpol["intpolparams"]["trackresolution"] = { 125 | "param": "freqs", 126 | "value": 0.5, 127 | "baseparam": "rhocen", 128 | } 129 | 130 | The variable ``baseparam`` defines the property used as base in the interpolation along and across the tracks, which we set in both cases to central density. 131 | 132 | Running the ``create_inputfile_interp_MS.py`` script produces the input file `input_interp_MS.xml`. Once BASTA begins 133 | the interpolation you might see messages such as: 134 | 135 | .. code-block:: text 136 | 137 | Warning: Interpolating track 270 was aborted due to no overlap in rhocen of the enveloping track! 138 | 139 | These are normal and can be safely ignored, as the strict cuts applied in effective temperature and metallicity result 140 | in some tracks having central density values outside the vertices of the interpolation and are therefore ignored. Also, messages like the following can be safely ignored: 141 | 142 | .. code-block:: text 143 | 144 | Stopped interpolation along track467 as the number of points would decrease from 24 to 22 145 | 146 | This simply states that the track has the required resolution along the track and therefore it does not require 147 | interpolation. 148 | 149 | `Please note that performing the interpolation can take a while! With the settings specified above, it takes around 20 minutes on our testing machine` 150 | 151 | After the interpolation and fit are performed the results are stored in ``BASTA/examples/output/interp_MS/``, 152 | including the new interpolated grid. The following figures compare the Kiel diagrams of the grids with and without 153 | interpolation, as well as the corner plots. 154 | 155 | .. figure:: figures/freqs/16CygA_kiel.png 156 | :alt: Kiel diagram of the 16 Cyg A fit using the original grid. 157 | 158 | Kiel diagram of the 16 Cyg A fit using the original grid. 159 | 160 | .. figure:: figures/interp_MS/16CygA_kiel.png 161 | :alt: Kiel diagram of the 16 Cyg A fit using the interpolated grid. 162 | 163 | Kiel diagram of the 16 Cyg A fit using the interpolated grid. 164 | 165 | .. figure:: figures/freqs/16CygA_corner.png 166 | :alt: Corner plot of the 16 Cyg A fit using the original grid. 167 | 168 | Corner plot of the 16 Cyg A fit using the original grid. 169 | 170 | .. figure:: figures/interp_MS/16CygA_corner.png 171 | :alt: Corner plot of the 16 Cyg A fit using the interpolated grid. 172 | 173 | Corner plot of the 16 Cyg A fit using the interpolated grid. 174 | -------------------------------------------------------------------------------- /docs/figures/distance/11129442_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/distance/11129442_corner.png -------------------------------------------------------------------------------- /docs/figures/distance/11129442_distance_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/distance/11129442_distance_corner.png -------------------------------------------------------------------------------- /docs/figures/distance/11129442_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/distance/11129442_kiel.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_corner.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_dupechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_dupechelle.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_dupechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_dupechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_echelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_echelle.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_echelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_echelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_epsdiff_e012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_epsdiff_e012.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_epsdiff_e012_cormap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_epsdiff_e012_cormap.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_kiel.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_pairechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_pairechelle.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_pairechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_pairechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_ratios_r012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_ratios_r012.png -------------------------------------------------------------------------------- /docs/figures/epsilon/16CygA_ratios_r012_cormap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/epsilon/16CygA_ratios_r012_cormap.png -------------------------------------------------------------------------------- /docs/figures/freqs/16CygA_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/freqs/16CygA_corner.png -------------------------------------------------------------------------------- /docs/figures/freqs/16CygA_dupechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/freqs/16CygA_dupechelle.png -------------------------------------------------------------------------------- /docs/figures/freqs/16CygA_dupechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/freqs/16CygA_dupechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/freqs/16CygA_echelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/freqs/16CygA_echelle.png -------------------------------------------------------------------------------- /docs/figures/freqs/16CygA_echelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/freqs/16CygA_echelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/freqs/16CygA_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/freqs/16CygA_kiel.png -------------------------------------------------------------------------------- /docs/figures/freqs/16CygA_pairechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/freqs/16CygA_pairechelle.png -------------------------------------------------------------------------------- /docs/figures/freqs/16CygA_pairechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/freqs/16CygA_pairechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_corner.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_dupechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_dupechelle.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_dupechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_dupechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_echelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_echelle.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_echelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_echelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_glitches_gr012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_glitches_gr012.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_glitches_gr012_cormap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_glitches_gr012_cormap.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_kiel.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_pairechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_pairechelle.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_pairechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_pairechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/glitches/16CygA_ratios_r012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/glitches/16CygA_ratios_r012.png -------------------------------------------------------------------------------- /docs/figures/global/16CygA_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/global/16CygA_corner.png -------------------------------------------------------------------------------- /docs/figures/global/16CygA_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/global/16CygA_kiel.png -------------------------------------------------------------------------------- /docs/figures/interp_MS/16CygA_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/interp_MS/16CygA_corner.png -------------------------------------------------------------------------------- /docs/figures/interp_MS/16CygA_dupechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/interp_MS/16CygA_dupechelle.png -------------------------------------------------------------------------------- /docs/figures/interp_MS/16CygA_dupechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/interp_MS/16CygA_dupechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/interp_MS/16CygA_echelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/interp_MS/16CygA_echelle.png -------------------------------------------------------------------------------- /docs/figures/interp_MS/16CygA_echelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/interp_MS/16CygA_echelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/interp_MS/16CygA_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/interp_MS/16CygA_kiel.png -------------------------------------------------------------------------------- /docs/figures/interp_MS/16CygA_pairechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/interp_MS/16CygA_pairechelle.png -------------------------------------------------------------------------------- /docs/figures/interp_MS/16CygA_pairechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/interp_MS/16CygA_pairechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/interp_MS/intpol_example_16CygA_intpolbase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/interp_MS/intpol_example_16CygA_intpolbase.png -------------------------------------------------------------------------------- /docs/figures/json/16CygA_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/json/16CygA_corner.png -------------------------------------------------------------------------------- /docs/figures/json/16CygA_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/json/16CygA_kiel.png -------------------------------------------------------------------------------- /docs/figures/parallax/11129442_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/parallax/11129442_corner.png -------------------------------------------------------------------------------- /docs/figures/parallax/11129442_distance_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/parallax/11129442_distance_corner.png -------------------------------------------------------------------------------- /docs/figures/parallax/11129442_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/parallax/11129442_kiel.png -------------------------------------------------------------------------------- /docs/figures/phase/11129442_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/phase/11129442_corner.png -------------------------------------------------------------------------------- /docs/figures/phase/11129442_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/phase/11129442_kiel.png -------------------------------------------------------------------------------- /docs/figures/preview_interp_MS/16CygA_interp_preview_across_resolution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/preview_interp_MS/16CygA_interp_preview_across_resolution.png -------------------------------------------------------------------------------- /docs/figures/preview_interp_MS/16CygA_interp_preview_along_resolution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/preview_interp_MS/16CygA_interp_preview_along_resolution.png -------------------------------------------------------------------------------- /docs/figures/ratios/16CygA_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/ratios/16CygA_corner.png -------------------------------------------------------------------------------- /docs/figures/ratios/16CygA_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/ratios/16CygA_kiel.png -------------------------------------------------------------------------------- /docs/figures/ratios/16CygA_ratios_r012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/ratios/16CygA_ratios_r012.png -------------------------------------------------------------------------------- /docs/figures/ratios/16CygA_ratios_r012_cormap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/ratios/16CygA_ratios_r012_cormap.png -------------------------------------------------------------------------------- /docs/figures/subgiant/Valid_245_corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/subgiant/Valid_245_corner.png -------------------------------------------------------------------------------- /docs/figures/subgiant/Valid_245_dupechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/subgiant/Valid_245_dupechelle.png -------------------------------------------------------------------------------- /docs/figures/subgiant/Valid_245_dupechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/subgiant/Valid_245_dupechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/subgiant/Valid_245_echelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/subgiant/Valid_245_echelle.png -------------------------------------------------------------------------------- /docs/figures/subgiant/Valid_245_echelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/subgiant/Valid_245_echelle_uncorrected.png -------------------------------------------------------------------------------- /docs/figures/subgiant/Valid_245_kiel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/subgiant/Valid_245_kiel.png -------------------------------------------------------------------------------- /docs/figures/subgiant/Valid_245_pairechelle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/subgiant/Valid_245_pairechelle.png -------------------------------------------------------------------------------- /docs/figures/subgiant/Valid_245_pairechelle_uncorrected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/docs/figures/subgiant/Valid_245_pairechelle_uncorrected.png -------------------------------------------------------------------------------- /docs/grids.rst: -------------------------------------------------------------------------------- 1 | .. _grids: 2 | 3 | Grids of models 4 | ############### 5 | 6 | BASTA uses grids of stellar tracks or isochrones stored in hierarchical data format ``hdf5``. The list of 7 | parameters included in our grids can be seen in the :ref:`parameter list `, but one should keep in mind that 8 | not all parameters are included in all grids. As an example, isochrones do not contain individual frequencies of 9 | oscillations while stellar tracks do, and fits to e.g., frequency ratios can only be performed with grids of stellar 10 | tracks. If in doubt about a particular entry in the :ref:`parameter list ` you are encouraged to contact one of 11 | the core developers of BASTA. 12 | 13 | A small grid is downloaded automatically if you follow the recommended installation instructions and is (as a default) stored in 14 | ``BASTA/grids/Garstec_16CygA.hdf5``. As the name suggest, this grid is built with the GARching STellar Evolution 15 | Code around the observed parameters of the *Kepler* target 16 Cyg A. Many of the :ref:`examples` are built using 16 | this grid, while others are constructed from larger grids that can be downloaded. 17 | 18 | For this purpose, BASTA includes a grid download tool that can be easily accessed from the command line. After 19 | installing the code, go to the BASTA folder and run the following: 20 | 21 | .. code-block:: bash 22 | 23 | BASTAdownload -h 24 | 25 | and follow the instructions to download the grids. Currently the following grids are available for download: 26 | 27 | * The validation grid of stellar tracks described in Section 6 of `The BASTA paper II `_ (called `validation`) 28 | * A complete grid of BaSTI stellar isochrones including all science cases described in the `Solar scaled paper `_ and the `Alpha-enhanced paper `_. (called `iso`) 29 | 30 | Additional grids can be built by the BASTA core development team upon reasonable request. Currently we are working on 31 | the following additions to the list of grids: 32 | 33 | * The complete grid of BaSTI stellar tracks described in the `Solar scaled paper `_ and the `Alpha-enhanced paper `_. 34 | * A tool to build your own MESA grids 35 | 36 | Stay tuned to the repository updates if you are interested in these grids. 37 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | BASTA: The BAyesian STellar Algorithm 2 | ##################################### 3 | 4 | **Welcome to BASTA's documentation!** 5 | 6 | BASTA is a Python-based fitting tool designed to determine properties of stars using a pre-computed grid of stellar 7 | models. It calculates the probability density function of a given stellar property based on a set of observational 8 | constraints defined by the user. 9 | 10 | Current stable version: v1.5.3 11 | 12 | *Please follow the repository on* `GitHub `_ *to get notifications on new releases: Click "Watch" then "Custom" and tick "Releases.* 13 | 14 | 15 | 16 | .. toctree:: 17 | :maxdepth: 1 18 | :caption: Contents: 19 | 20 | install 21 | grids 22 | running 23 | examples 24 | methods 25 | controls 26 | troubleshoot 27 | contributing 28 | source_code 29 | 30 | 31 | .. _ref_refs: 32 | 33 | References and acknowledgements 34 | ******************************* 35 | 36 | There are two articles containing the rationale, main features, and capabilities of the code: 37 | 38 | * `The BASTA paper I `_ 39 | * `The BASTA paper II `_ 40 | 41 | Please consider citing these articles if you use BASTA in your work, and include the link to the code's repository 42 | ``https://github.com/BASTAcode/BASTA``. 43 | 44 | Due to its versatility, BASTA is used in a large variety of studies requiring robust determination of fundamental 45 | stellar properties. We have compiled a (non-exhaustive) 46 | `list of papers using BASTA results `_ 47 | that showcases these applications. If your paper using BASTA results is missing from the list please contact us. 48 | 49 | .. _ref_authors: 50 | 51 | Authors 52 | ******* 53 | The current core developing team members are: 54 | 55 | * Jakob Lysgaard Rørsted (maintainer) 56 | * Mark Lykke Winther (co-maintainer) 57 | * Amalie Stokholm (co-maintainer) 58 | * Kuldeep Verma 59 | 60 | 61 | The original author of the code is: 62 | 63 | * Víctor Aguirre Børsen-Koch 64 | 65 | 66 | 67 | Throughout the years, many people have contributed to the addition and development of various parts and modules of 68 | BASTA. We welcome further contributions from the community as well as issues reporting. Please look at the section 69 | :ref:`contrib` for further details. 70 | 71 | 72 | Find what you are looking for 73 | ***************************** 74 | 75 | * :ref:`genindex` 76 | * :ref:`modindex` 77 | * :ref:`search` 78 | -------------------------------------------------------------------------------- /docs/install.rst: -------------------------------------------------------------------------------- 1 | .. _install: 2 | 3 | Installation 4 | ############ 5 | 6 | .. _ref_code: 7 | 8 | Obtaining the code and virtual environment 9 | ****************************************** 10 | 11 | *Important note: BASTA requires Python 3.10 or newer; it is currently developed for Python 3.12.* 12 | 13 | 14 | Start out by obtaining a copy of BASTA; either from GitHub by cloning the GitHub repository or downloadning a source code release, or from the Python Package Index (PyPI). 15 | 16 | 17 | .. _ref_venv: 18 | 19 | Virtual environment 20 | =================== 21 | To ensure functionality, we suggest to install the code in a fresh virtual environment. You can do this by running (but feel free to do this anyway you prefer): 22 | 23 | .. code-block:: bash 24 | 25 | mkdir ~/venvs; cd venvs 26 | python3 -m venv bastaenv 27 | source ~/venvs/bastaenv/bin/activate 28 | pip install --upgrade pip setuptools wheel 29 | deactivate 30 | source ~/venvs/bastaenv/bin/activate 31 | 32 | 33 | .. _ref_pip: 34 | 35 | Using pip (from PyPI or GitHub) 36 | =============================== 37 | As mentioned above, we strongly recommend to install the code in a fresh virtual environment. 38 | 39 | With the environment installed and activated, you can obtain BASTA and all dependencies: 40 | 41 | .. code-block:: bash 42 | 43 | pip install basta 44 | 45 | 46 | It is also possible to instead obtain the code package directly from GitHub: 47 | 48 | .. code-block:: bash 49 | 50 | pip install https://github.com/BASTAcode/BASTA/archive/refs/heads/main.zip 51 | 52 | Note that by changing `main.zip` to `devel.zip` in the line above, you will get the most recent (and perhaps unstable!) development version of the code (*not recommended*). 53 | 54 | 55 | 56 | .. _ref_github_dev: 57 | 58 | Clone the GitHub repository (for developers) 59 | ============================================ 60 | 61 | Cloning from GitHub has the advantage that it is easier to modify the source code if you wish to do so. 62 | 63 | As a default, we recommend that you install BASTA in the folder ``~/BASTA`` if you install from GitHub but it is not a requirement. If you have a user on GitHub and use an ssh-keypair, you can simply run: 64 | 65 | .. code-block:: bash 66 | 67 | git clone git@github.com:BASTAcode/BASTA.git 68 | 69 | If you prefer to enter username and password instead of a key-pair run: 70 | 71 | .. code-block:: bash 72 | 73 | git clone https://github.com/BASTAcode/BASTA.git 74 | 75 | Now, assuming you have downloaded the code, you can run the following to setup a virtual environment in the same folder (feel free to do it any other way you prefer; we strongly recommend to install the code in a fresh virtual environment): 76 | 77 | .. code-block:: bash 78 | 79 | cd BASTA 80 | python3 -m venv bastaenv 81 | source bastaenv/bin/activate 82 | 83 | Then you can install the code and dependencies into the virtual environment: 84 | 85 | .. code-block:: bash 86 | 87 | pip install -e . 88 | 89 | Using `-e` will let you modify the source code and it will take effect at next run without reinstalling the code. 90 | 91 | 92 | .. _ref_dust: 93 | 94 | Before first use 95 | **************** 96 | 97 | To finalise the setup, you will need to download a example grid and obtain the dustmaps. BASTA is shipped with a tool to do so: 98 | 99 | .. code-block:: bash 100 | 101 | BASTAdownload 102 | 103 | If you cloned BASTA from GitHub, you most likely wish to use the default location and can just run `BASTAdownload 16CygA`. Otherwise, you can do something like: 104 | 105 | .. code-block:: bash 106 | 107 | mkdir -p ~/BASTA/grids 108 | mkdir -p ~/BASTA/dust 109 | BASTAdownload --gridpath ~/BASTA/grids --dustpath ~/BASTA/dust 16CygA 110 | 111 | 112 | If you installed BASTA from PyPI and wish to obtain the examples and template input file(s), take a look at: 113 | 114 | .. code-block:: bash 115 | 116 | cd ~/BASTA 117 | BASTAexamples full 118 | 119 | If you only need the input template, run `BASTAexamples simple` in the directory where you need the template. 120 | 121 | BASTA is now ready to go. If you need to fit acoustic glitches or wish to contribute to the code, please continue reading on this page. If not, then proceed in the menu to the next item. 122 | 123 | 124 | .. _ref_fortran: 125 | 126 | Glitch-fitting and Fortran modules 127 | ================================== 128 | 129 | *If you don't want to contribute fit glitches, you can safely skip this section!* 130 | 131 | In case you need to fit glitches (and only in that case), you must compile the external Fortran-modules. Firstly, activate your virtual environment and then: 132 | 133 | .. code-block:: bash 134 | 135 | pip install meson ninja 136 | 137 | 138 | Assuming you cloned the repository from GitHub to the suggested location run the following: 139 | 140 | .. code-block:: bash 141 | 142 | cd ~/BASTA/src/basta 143 | f2py -c glitch_fq.f95 -m glitch_fq 144 | f2py -c glitch_sd.f95 -m glitch_sd 145 | f2py -c icov_sd.f95 -m icov_sd 146 | f2py -c sd.f95 -m sd 147 | 148 | 149 | 150 | .. _ref_hooks: 151 | 152 | Git hooks 153 | ========= 154 | 155 | *If you don't want to contribute to BASTA, you can safely skip this section!* 156 | 157 | BASTA uses ``pre-commit`` to manage git hooks, and the final setup task is to 158 | activate them: 159 | 160 | .. code-block:: bash 161 | 162 | source bastaenv/bin/activate 163 | pre-commit install 164 | 165 | 166 | It might take a minute or two to complete. Now, to ensure everything is 167 | correctly setup, run the command: 168 | 169 | .. code-block:: bash 170 | 171 | pre-commit run --all-files 172 | 173 | 174 | It should pass all checks. 175 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | set SPHINXPROJ=BASTA 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 20 | echo.installed, then set the SPHINXBUILD environment variable to point 21 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 22 | echo.may add the Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /docs/methods.rst: -------------------------------------------------------------------------------- 1 | .. _methods: 2 | 3 | Methods 4 | ####### 5 | 6 | *Note: This part of the documentation is work in progress!* 7 | 8 | In these sections, the methods adapted and applied by BASTA is detailed. 9 | 10 | The origin, justification and impact of the methods are not described here, but in the related papers. 11 | This simply acts as a description of how the methods are applied, to understand how BASTA is used. 12 | 13 | The following topics are covered: 14 | 15 | .. toctree:: 16 | :maxdepth: 2 17 | 18 | methods_stats 19 | methods_general 20 | methods_freqs 21 | methods_surfind 22 | methods_intpol 23 | -------------------------------------------------------------------------------- /docs/methods_freqs.rst: -------------------------------------------------------------------------------- 1 | .. _methods_freqs.rst: 2 | 3 | Individual frequencies 4 | ********************** 5 | 6 | 7 | 8 | .. _methods_freqs_dnufrac: 9 | 10 | Frequency constraint 11 | ==================== 12 | (equivalent to a :ref:`prior `). As the sign of the correction is known, this fraction applies to the upper limit of the :math:`\nu_\text{mod} - \nu_\text{obs}` difference, while the lower limit is limited to :math:`-3\sigma_\nu`. 13 | 14 | 15 | .. _methods_freqs_exclude: 16 | 17 | Excluding frequencies 18 | ===================== 19 | 20 | 21 | 22 | .. _methods_freqs_matching: 23 | 24 | Frequency matching 25 | ================== 26 | -------------------------------------------------------------------------------- /docs/methods_general.rst: -------------------------------------------------------------------------------- 1 | .. _methods_general: 2 | 3 | General methods 4 | *************** 5 | 6 | 7 | .. _methods_general_distance: 8 | 9 | Fitting distance/parallax 10 | ========================= 11 | -------------------------------------------------------------------------------- /docs/methods_intpol.rst: -------------------------------------------------------------------------------- 1 | .. _methods_intpol: 2 | 3 | Interpolation of stellar models 4 | ******************************* 5 | -------------------------------------------------------------------------------- /docs/methods_stats.rst: -------------------------------------------------------------------------------- 1 | .. _methods_stats: 2 | 3 | Statistical methods 4 | ******************* 5 | 6 | 7 | .. _methods_stats_bayes: 8 | 9 | Bayesian Statistics 10 | ===================================== 11 | 12 | Bayes theorem, priors, import from MLW thesis 13 | 14 | 15 | .. _methods_stats_posterior: 16 | 17 | Posterior 18 | ========= 19 | How the posterior distributions are drawn, import from MLW thesis 20 | -------------------------------------------------------------------------------- /docs/methods_surfind.rst: -------------------------------------------------------------------------------- 1 | .. _methods_surfind: 2 | 3 | Surface independent 4 | ******************* 5 | 6 | 7 | Frequency ratios 8 | ================ 9 | 10 | 11 | Frequency phase shift differences 12 | ================================= 13 | -------------------------------------------------------------------------------- /docs/param_classic.csv: -------------------------------------------------------------------------------- 1 | Key|Unit|Parameter|Description 2 | ``age``|Myr|Age (Myr)|Current age in Myr 3 | ``alphaFe``|dex|:math:`\text{[}\alpha\text{/Fe] (dex)}`|Alpha enhancement 4 | ``alphaMLT``||:math:`\alpha_\mathrm{MLT}`|Mixing length efficiency 5 | ``d02fit``|microHz|:math:`d_{02,{\rm fit}}\text{ (}\mu\text{Hz)}`|Weighted mean small frequency separation 6 | ``d02mean``|microHz|:math:`d_{02,{\rm mean}}\text{ (}\mu\text{Hz)}`|Simple mean small frequency separation 7 | ``dage``|Myr|:math:`\text{Age}_\mathrm{weight}\text{ (Myr)}`|Bayesian age weight 8 | ``dif``||Diffusion|Atomic diffusion: 0) no and 1) yes 9 | ``distance``|pc|:math:`d\text{ (pc)}`|Stellar distance 10 | ``dmass``|solar|:math:`M_\mathrm{weight}`|Bayesian mass weight 11 | ``dnuAsf``|solar|:math:`\Delta \nu_\mathrm{Asfgrid}\text{ (}\mu\text{Hz)}`|Large frequency separation corrected with Asfgrid following Sharma et al. 2016, Stello and Sharma 2022 12 | ``dnufit``|microHz|:math:`\Delta \nu_\mathrm{fit}\text{ (}\mu\text{Hz)}`|Large frequency separation from linear fit to individual :math:`\ell=0` modes 13 | ``dnufitMos12``|microHz|:math:`\Delta \nu_\mathrm{fit}\text{ (}\mu\text{Hz)}`|Large frequency separation from linear fit to individual :math:`\ell=0` modes (Mosser et al. 2012) 14 | ``dnuscal``|solar|:math:`\Delta \nu_\mathrm{scaling}\text{ (}\mu\text{Hz)}`|Large frequency separation from scaling relations 15 | ``dnuSer``|solar|:math:`\Delta \nu_\mathrm{Serenelli 17}`|Large frequency separation corrected following Serenelli et al. 2017 16 | ``epsfit``||:math:`\epsilon_\mathrm{fit}`|Dimensionless frequency offset 17 | ``epsfitMos12``||:math:`\epsilon_\mathrm{fit}`|Dimensionless frequency offset (Mosser et al. 12) 18 | ``errflagSer``||:math:`\text{error}_\mathrm{flag}\text{ (Serenelli 17)}`|Error output of the corrections from Serenelli et al. 2017 19 | ``eta``||:math:`\eta`|Reimers mass loss 20 | ``fdnuAsf``||:math:`\text{f}_{\Delta \nu}\text{ (Asfgrid)}`|Correction factor for large frequency separation with Asfgrid following Sharma et al. 2016, Stello and Sharma 2022 21 | ``fdnuSer``||:math:`\text{f}_\Delta \nu\text{ (Serenelli 17)}`|Correction factor for large frequency separatoin from Serenelli et al. 2017 22 | ``FeH``|dex|[Fe/H] (dex)|Iron abundance 23 | ``FeHini``|dex|:math:`\text{[Fe/H]}_\mathrm{ini}\text{ (dex)}`|Initial iron abundance 24 | ``Gconst``|cm3/gs2|G|Gravitational constant 25 | ``gcut``||:math:`g_\mathrm{cut}`|Geometric cutoff 26 | ``logg``|log10(cm/s2)|:math:`\log \, g\text{ (dex)}`|Surface gravity 27 | ``LPhot``|solar|:math:`L\text{ (L}_\odot\text{)}`|Photospheric luminosity 28 | ``massfin``|solar|:math:`M\text{ (M}_\odot\text{)}`|Current mass 29 | ``massini``|solar|:math:`M_\mathrm{ini}\text{ (M}_\odot\text{)}`|Initial mass 30 | ``Mbcz``||:math:`\text{M}_\mathrm{bcz}\text{ (m/M)}`|Mass coordinate of base of the convective zone 31 | ``Mcore``||:math:`\text{M}_\mathrm{core}\text{ (m/M)}`|Mass coordinate of the convective core 32 | ``McoreX``||:math:`\text{M}_\mathrm{core}\text{ (m/M)}`|Mass coordinate of the convective core (old diagnostic) 33 | ``MeH``|dex|[M/H] (dex)|Metallicity 34 | ``MeHini``|dex|:math:`\text{[M/H]}_\mathrm{ini}\text{ (dex)}`|Initial metallicity 35 | ``MMaxNucE``||:math:`\text{M}_\mathrm{max}(\epsilon)\text{ (m/M)}`|Mass coordinate of maximum energy generation 36 | ``modnum``||Model|Model number 37 | ``numax``|solar|:math:`\nu_\mathrm{max}\text{ (}\mu\text{Hz)}`|Frequency of maximum oscillation power 38 | ``numaxAsf``|solar|:math:`\nu_\mathrm{max,\,Asfgrid}\text{ (}\mu\text{Hz)}`|Frequency of maximum oscillation power corrected with Asfgrid following Sharma et al. 2016, Stello and Sharma 2022 39 | ``nummodSer``||:math:`\text{N}_\mathrm{modes}\text{ (Serenelli 17)}`|Number of modes used in the corrections from Serenelli et al. 2017 40 | ``ove``||:math:`\xi_\mathrm{ove}`|Overshooting efficiency 41 | ``phase``||Phase|Evolutionary phase: 1) hydrogen or 2) helium burning 42 | ``PS``|s|:math:`\Delta \Pi\text{ (s)}`|Asymptotic period spacing 43 | ``radPhot``|solar|:math:`R_\mathrm{phot}\text{ (R}_\odot\text{)}`|Photospheric radius 44 | ``radTot``|solar|:math:`R_\mathrm{tot}\text{ (R}_\odot\text{)}`|Total radius 45 | ``Rbcz``||:math:`\text{R}_\mathrm{bcz}\text{ (r/R}_\mathrm{phot}\text{)}`|Radius coordinate of base of the convective zone 46 | ``Rcore``||:math:`\text{R}\mathrm{core}\text{ (r/R}_\mathrm{phot}\text{)}`|Radius coordination of the convective core 47 | ``RcoreX``||:math:`\text{R}\mathrm{core}\text{ (r/R}_\mathrm{phot}\text{)}`|Radius coordination of the convective core (old diagnostic) 48 | ``rho``|g/cm3|:math:`\rho\text{ (g/cm}^3\text{)}`|Mean stellar density 49 | ``rhocen``|g/cm3|:math:`\rho_\mathrm{cen}\text{ (g/cm}^3\text{)}`|Central density 50 | ``RMaxNucE``||:math:`\text{R}_\mathrm{max}(\epsilon)\text{ (r/R)}_\mathrm{phot}`|Radius coordinate of maximum energy generation 51 | ``TAMS``||TAMS|Age scaled by TAMS (terminal age of main sequence, X :math:`_\mathrm{cen}` <1e-5) 52 | ``tau0``|s|:math:`\tau\text{ (s)}`|Acoustic radius 53 | ``taubcz``|s|:math:`\tau_\mathrm{bcz,\,integration}\text{ (s)}`|Acoustic depth of the base the convective envelope by integration 54 | ``tauhe``|s|:math:`\tau_\mathrm{He,\,integration}\text{ (s)}`|Acoustic depth of the helium ionization zone by integration 55 | ``Teff``|K|:math:`T_\mathrm{eff}\text{ (K)}`|Effective temperature 56 | ``TPS``|s|t|to be completed 57 | ``xcen``||:math:`\text{X}_\mathrm{cen}`|Central hydrogen fraction 58 | ``xini``||:math:`\text{X}_\mathrm{ini}`|Initial hydrogen fraction 59 | ``xsur``||:math:`\text{X}_\mathrm{sur}`|Surface hydrogen fraction 60 | ``ycen``||:math:`\text{Y}_\mathrm{cen}`|Central helium fraction 61 | ``yini``||:math:`\text{Y}_\mathrm{ini}`|Initial helium fraction 62 | ``ysur``||:math:`\text{Y}_\mathrm{sur}`|Surface helium fraction 63 | ``ZAMSLPhot``|solar|:math:`\text{ZAMS }L\text{ (L}_odot\text{)}`|Luminosity at the ZAMS 64 | ``ZAMSTeff``|K|:math:`\text{ZAMS }T_\mathrm{eff}\text{ (K)}`|Effective temperature at the ZAMS 65 | ``zcen``||:math:`\text{Z}_\mathrm{cen}`|Central heavy elements fraction 66 | ``zini``||:math:`\text{Z}_\mathrm{ini}`|Initial heavy elements fraction 67 | ``zsur``||:math:`\text{Z}_\mathrm{sur}`|Surface heavy elements fraction 68 | -------------------------------------------------------------------------------- /docs/param_filters.csv: -------------------------------------------------------------------------------- 1 | Key|Unit|Parameter|Description 2 | ``Mu_JC``|mag|:math:`U`| :math:`U` magnitude in the Johnson/Cousins photometric system 3 | ``Mbx_JC``|mag|:math:`Bx`| :math:`Bx` magnitude in the Johnson/Cousins photometric system 4 | ``Mb_JC``|mag|:math:`B`| :math:`B` magnitude in the Johnson/Cousins photometric system 5 | ``Mv_JC``|mag|:math:`V`| :math:`V` magnitude in the Johnson/Cousins photometric system 6 | ``Mr_JC``|mag|:math:`R`| :math:`R` magnitude in the Johnson/Cousins photometric system 7 | ``Mi_JC``|mag|:math:`I`| :math:`I` magnitude in the Johnson/Cousins photometric system 8 | ``Mj_JC``|mag|:math:`J`| :math:`J` magnitude in the Johnson/Cousins photometric system 9 | ``Mh_JC``|mag|:math:`H`| :math:`H` magnitude in the Johnson/Cousins photometric system 10 | ``Mk_JC``|mag|:math:`K`| :math:`K` magnitude in the Johnson/Cousins photometric system 11 | ``Mlp_JC``|mag|:math:`Lp`| :math:`Lp` magnitude in the Johnson/Cousins photometric system 12 | ``Ml_JC``|mag|:math:`L`| :math:`L` magnitude in the Johnson/Cousins photometric system 13 | ``Mm_JC``|mag|:math:`M`| :math:`M` magnitude in the Johnson/Cousins photometric system 14 | ``Mu_SAGE``|mag|:math:`u`| :math:`u` magnitude in the SAGE photometric system 15 | ``Mv_SAGE``|mag|:math:`v`| :math:`v` magnitude in the SAGE photometric system 16 | ``Mg_SAGE``|mag|:math:`g`| :math:`g` magnitude in the SAGE photometric system 17 | ``Mr_SAGE``|mag|:math:`r`| :math:`r` magnitude in the SAGE photometric system 18 | ``Mi_SAGE``|mag|:math:`i`| :math:`i` magnitude in the SAGE photometric system 19 | ``DDO51_SAGE``|mag|DDO51|DDO51 magnitude in the SAGE photometric system 20 | ``Han_SAGE``|mag|:math:`\text{H}\alpha_\mathrm{n}`|H :math:`\alpha_\mathrm{n}` magnitude in the SAGE photometric system 21 | ``Haw_SAGE``|mag|:math:`\text{H}\alpha_\mathrm{w}`|H :math:`\alpha_\mathrm{w}` magnitude in the SAGE photometric system 22 | ``Mj_2MASS``|mag|:math:`J`| :math:`J` magnitude in the 2MASS photometric system 23 | ``Mh_2MASS``|mag|:math:`H`| :math:`H` magnitude in the 2MASS photometric system 24 | ``Mk_2MASS``|mag|:math:`K`| :math:`K` magnitude in the 2MASS photometric system 25 | ``G_GAIA``|mag|:math:`G`| :math:`G` magnitude in the Gaia photometric system 26 | ``BP_GAIA``|mag|:math:`G_\mathrm{BP}`| :math:`G_\mathrm{BP}` magnitude in the Gaia photometric system 27 | ``RP_GAIA``|mag|:math:`G_\mathrm{RP}`| :math:`G_\mathrm{RP}` magnitude in the Gaia photometric system 28 | ``F070W_JWST``|mag|F070W|F070W magnitude in the JWST photometric system 29 | ``F090W_JWST``|mag|F090W|F090W magnitude in the JWST photometric system 30 | ``F115W_JWST``|mag|F115W|F115W magnitude in the JWST photometric system 31 | ``F150W_JWST``|mag|F150W|F150W magnitude in the JWST photometric system 32 | ``F200W_JWST``|mag|F200W|F200W magnitude in the JWST photometric system 33 | ``F277W_JWST``|mag|F277W|F277W magnitude in the JWST photometric system 34 | ``F356W_JWST``|mag|F356W|F356W magnitude in the JWST photometric system 35 | ``F444W_JWST``|mag|F444W|F444W magnitude in the JWST photometric system 36 | ``Mu_SLOAN``|mag|:math:`u\prime`| :math:`u\prime` magnitude in the Sloan photometric system 37 | ``Mg_SLOAN``|mag|:math:`g\prime`| :math:`g\prime` magnitude in the Sloan photometric system 38 | ``Mr_SLOAN``|mag|:math:`r\prime`| :math:`r\prime` magnitude in the Sloan photometric system 39 | ``Mi_SLOAN``|mag|:math:`i\prime`| :math:`i\prime` magnitude in the Sloan photometric system 40 | ``Mz_SLOAN``|mag|:math:`z\prime`| :math:`z\prime` magnitude in the Sloan photometric system 41 | ``Mu_STROMGREN``|mag|:math:`u`| :math:`u` magnitude in the Stromgren photometric system 42 | ``Mv_STROMGREN``|mag|:math:`v`| :math:`v` magnitude in the Stromgren photometric system 43 | ``Mb_STROMGREN``|mag|:math:`b`| :math:`b` magnitude in the Stromgren photometric system 44 | ``My_STROMGREN``|mag|:math:`y`| :math:`y` magnitude in the Stromgren photometric system 45 | ``m1_STROMGREN``|mag|:math:`m_{1}`|Index m1 in the Stromgren photometric system 46 | ``c1_STROMGREN``|mag|:math:`c_{1}`|Index c1 in the Stromgren photometric system 47 | ``Mz_VISTA``|mag|:math:`Z`| :math:`Z` magnitude in the VISTA photometric system 48 | ``My_VISTA``|mag|:math:`Y`| :math:`Y` magnitude in the VISTA photometric system 49 | ``Mj_VISTA``|mag|:math:`J`| :math:`J` magnitude in the VISTA photometric system 50 | ``Mh_VISTA``|mag|:math:`H`| :math:`H` magnitude in the VISTA photometric system 51 | ``Mk_VISTA``|mag|:math:`K`| :math:`K` magnitude in the VISTA photometric system 52 | ``F160W_WFC2``|mag|F160W|F160W in the WFC2 photometric system 53 | ``F170W_WFC2``|mag|F170W|F170W in the WFC2 photometric system 54 | ``F185W_WFC2``|mag|F185W|F185W in the WFC2 photometric system 55 | ``F218W_WFC2``|mag|F218W|F218W in the WFC2 photometric system 56 | ``F255W_WFC2``|mag|F255W|F255W in the WFC2 photometric system 57 | ``F300W_WFC2``|mag|F300W|F300W in the WFC2 photometric system 58 | ``F336W_WFC2``|mag|F336W|F336W in the WFC2 photometric system 59 | ``F380W_WFC2``|mag|F380W|F380W in the WFC2 photometric system 60 | ``F439W_WFC2``|mag|F439W|F439W in the WFC2 photometric system 61 | ``F450W_WFC2``|mag|F450W|F450W in the WFC2 photometric system 62 | ``F555W_WFC2``|mag|F555W|F555W in the WFC2 photometric system 63 | ``F606W_WFC2``|mag|F606W|F606W in the WFC2 photometric system 64 | ``F622W_WFC2``|mag|F622W|F622W in the WFC2 photometric system 65 | ``F675W_WFC2``|mag|F675W|F675W in the WFC2 photometric system 66 | ``F702W_WFC2``|mag|F702W|F702W in the WFC2 photometric system 67 | ``F791W_WFC2``|mag|F791W|F791W in the WFC2 photometric system 68 | ``F814W_WFC2``|mag|F814W|F814W in the WFC2 photometric system 69 | ``F435W_ACS``|mag|F435W|F435W in the ACS photometric system 70 | ``F475W_ACS``|mag|F475W|F475W in the ACS photometric system 71 | ``F555W_ACS``|mag|F555W|F555W in the ACS photometric system 72 | ``F606W_ACS``|mag|F606W|F606W in the ACS photometric system 73 | ``F625W_ACS``|mag|F625W|F625W in the ACS photometric system 74 | ``F775W_ACS``|mag|F775W|F775W in the ACS photometric system 75 | ``F814W_ACS``|mag|F814W|F814W in the ACS photometric system 76 | ``F218W_WFC3``|mag|F218W|F218W in the WFC3 UVIS/IR photometric system 77 | ``F225W_WFC3``|mag|F225W|F225W in the WFC3 UVIS/IR photometric system 78 | ``F275W_WFC3``|mag|F275W|F275W in the WFC3 UVIS/IR photometric system 79 | ``F336W_WFC3``|mag|F336W|F336W in the WFC3 UVIS/IR photometric system 80 | ``F390W_WFC3``|mag|F390W|F390W in the WFC3 UVIS/IR photometric system 81 | ``F438W_WFC3``|mag|F438W|F438W in the WFC3 UVIS/IR photometric system 82 | ``F475W_WFC3``|mag|F475W|F475W in the WFC3 UVIS/IR photometric system 83 | ``F555W_WFC3``|mag|F555W|F555W in the WFC3 UVIS/IR photometric system 84 | ``F606W_WFC3``|mag|F606W|F606W in the WFC3 UVIS/IR photometric system 85 | ``F625W_WFC3``|mag|F625W|F625W in the WFC3 UVIS/IR photometric system 86 | ``F775W_WFC3``|mag|F775W|F775W in the WFC3 UVIS/IR photometric system 87 | ``F814W_WFC3``|mag|F814W|F814W in the WFC3 UVIS/IR photometric system 88 | ``F105W_WFC3``|mag|F105W|F105W in the WFC3 UVIS/IR photometric system 89 | ``F110W_WFC3``|mag|F110W|F110W in the WFC3 UVIS/IR photometric system 90 | ``F125W_WFC3``|mag|F125W|F125W in the WFC3 UVIS/IR photometric system 91 | ``F140W_WFC3``|mag|F140W|F140W in the WFC3 UVIS/IR photometric system 92 | ``F160W_WFC3``|mag|F160W|F160W in the WFC3 UVIS/IR photometric system 93 | ``Mu_DECAM``|mag|:math:`u`| :math:`u` in the DECAM photometric system 94 | ``Mg_DECAM``|mag|:math:`g`| :math:`g` in the DECAM photometric system 95 | ``Mr_DECAM``|mag|:math:`r`| :math:`r` in the DECAM photometric system 96 | ``Mi_DECAM``|mag|:math:`i`| :math:`i` in the DECAM photometric system 97 | ``Mz_DECAM``|mag|:math:`z`| :math:`z` in the DECAM photometric system 98 | ``My_DECAM``|mag|:math:`y`| :math:`y` in the DECAM photometric system 99 | ``Mu_SKYMAPPER``|mag|:math:`u`| :math:`u` in the SkyMapper photometric system 100 | ``Mv_SKYMAPPER``|mag|:math:`v`| :math:`v` in the SkyMapper photometric system 101 | ``Mg_SKYMAPPER``|mag|:math:`g`| :math:`g` in the SkyMapper photometric system 102 | ``Mr_SKYMAPPER``|mag|:math:`r`| :math:`r` in the SkyMapper photometric system 103 | ``Mi_SKYMAPPER``|mag|:math:`i`| :math:`i` in the SkyMapper photometric system 104 | ``Mz_SKYMAPPER``|mag|:math:`z`| :math:`z` in the SkyMapper photometric system 105 | ``Mule_SKYMAPPER``|mag|:math:`u_\mathrm{le}`| :math:`u_\mathrm{le}` in the SkyMapper photometric system 106 | ``Mkp_KEPLER``|mag|:math:`K_{p}`|Magnitude in the Kepler photometric system 107 | ``Mhp_TYCHO``|mag|:math:`H_{p}`|Hipparcos magnitude in the Tycho photometric system 108 | ``Mb_TYCHO``|mag|:math:`B_{t}`| :math:`B` magnitude in the Tycho photometric system 109 | ``Mv_TYCHO``|mag|:math:`V_{t}`| :math:`V` magnitude in the Tycho photometric system 110 | ``Mt_TESS``|mag|:math:`T_{\mathrm{mag}}`|Magnitude in the TESS photometric system 111 | -------------------------------------------------------------------------------- /docs/prepare_doc_figures.py: -------------------------------------------------------------------------------- 1 | # Convert reference figures from the examples to png to be rendered by the documentation 2 | import os 3 | import subprocess 4 | from contextlib import contextmanager 5 | 6 | from tqdm import tqdm 7 | 8 | 9 | @contextmanager 10 | def cd(newdir): 11 | """Change directory""" 12 | prevdir = os.getcwd() 13 | os.chdir(os.path.expanduser(newdir)) 14 | try: 15 | yield 16 | finally: 17 | os.chdir(prevdir) 18 | 19 | 20 | # Settings for imagemagic (change name on Windows) 21 | imname = ["convert"] 22 | settings = ["-density", "96", "-quality", "85"] 23 | imgcmd = imname + settings 24 | 25 | # Paths 26 | indir = os.path.abspath("../examples/reference") 27 | outdir = os.path.abspath("figures") 28 | 29 | # Transverse all example cases and process all pdf -> png, and store in output dir 30 | with cd(indir): 31 | cases = next(os.walk("."))[1] 32 | for case in tqdm(cases): 33 | os.makedirs(os.path.join(outdir, case), exist_ok=True) 34 | with cd(os.path.join(indir, case)): 35 | files = next(os.walk("."))[2] 36 | for file in files: 37 | if not file.endswith(".pdf"): 38 | continue 39 | outname = file[:-4] + ".png" 40 | outfile = os.path.join(outdir, case, outname) 41 | imgcall = imgcmd + [f"{file}", f"{outfile}"] 42 | subprocess.check_call(imgcall) 43 | -------------------------------------------------------------------------------- /docs/prepare_param_table.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import numpy as np 3 | 4 | from basta import constants as bc 5 | 6 | 7 | def make_tables(): 8 | """ 9 | Makes csv tables of constants.parameters.params, for the 10 | documentation, to be more readily readable by users. 11 | Divides into two tables: Photometric filters/magnitudes, 12 | and the rest (classic). 13 | """ 14 | 15 | # Get all parameters, sort by filter and sort classic 16 | allparams = np.array(bc.parameters.params) 17 | filters = [f[0] for f in bc.extinction.R] 18 | clasparams = [] 19 | filtparams = [] 20 | for param in allparams: 21 | if param[0] in filters: 22 | filtparams.append(param) 23 | else: 24 | clasparams.append(param) 25 | clasparams = np.array(clasparams)[np.argsort([p[0].lower() for p in clasparams])] 26 | 27 | # Open table, prepare writer, write header 28 | parmfile = open("param_classic.csv", "w", newline="") 29 | parmwriter = csv.writer(parmfile, delimiter="|") 30 | parmwriter.writerow(["Key", "Unit", "Parameter", "Description"]) 31 | 32 | # Write table 33 | for param in clasparams: 34 | # Reformat and write entry 35 | refparam = reformat_entry(param) 36 | parmwriter.writerow(refparam) 37 | 38 | # Close table 39 | parmfile.close() 40 | 41 | # Open table, prepare writer, write header 42 | filtfile = open("param_filters.csv", "w", newline="") 43 | filtwriter = csv.writer(filtfile, delimiter="|") 44 | filtwriter.writerow(["Key", "Unit", "Parameter", "Description"]) 45 | 46 | # Write table 47 | for param in filtparams: 48 | # Reformat and write entry 49 | refparam = reformat_entry(param) 50 | filtwriter.writerow(refparam) 51 | 52 | # Close table file 53 | filtfile.close() 54 | 55 | 56 | def reformat_entry(listpar): 57 | # Ignore color column 58 | lpar = list(listpar)[:-1] 59 | 60 | # None should just be empty entries 61 | if None in lpar: 62 | lpar[np.where(np.array(lpar) == None)[0][0]] = "" 63 | 64 | # Replace LaTeX math with reStructuredText math 65 | # Wrap remaining in \text 66 | if "$" in lpar[2]: 67 | string = ":math:`" 68 | splstr = lpar[2].split("$") 69 | for j, ss in enumerate(splstr): 70 | if j % 2 == 0 and ss != "": 71 | string += "\\text{" + ss + "}" 72 | elif ss != "": 73 | string += ss 74 | string += "`" 75 | 76 | lpar[2] = string 77 | 78 | # Sometimes it is also in description. Above changes 79 | # font family, the following only works if there are 80 | # ONLY ONE math section 81 | if "$" in lpar[3]: 82 | lpar[3] = lpar[3].replace("$", " :math:`", 1) 83 | lpar[3] = lpar[3].replace("$", "`", 1) 84 | 85 | # Wrap key in backquotes for highlighting 86 | lpar[0] = "``" + lpar[0] + "``" 87 | return lpar 88 | 89 | 90 | if __name__ == "__main__": 91 | make_tables() 92 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy>=2.1.3 2 | Sphinx>=8.1.3 3 | sphinx-rtd-theme>=3.0.1 4 | -------------------------------------------------------------------------------- /docs/running.rst: -------------------------------------------------------------------------------- 1 | .. _running: 2 | 3 | Running BASTA 4 | ############# 5 | 6 | Two steps to running BASTA 7 | ************************** 8 | 9 | The following tutorial is a general introduction to fitting observational data and determining stellar properties with 10 | BASTA. It is meant as a guide to get started with simple fits based of various sets of input, and should not be 11 | considered as the default settings for producing scientific results. We encourage the users to explore the options 12 | offered by the code and build their input files according to their needs. As a final remark, we note that *BASTA is designed to fit any input given without ensuring that the solution is physically viable*. In other words, it is *up to the user to correctly interpret the results of any fit done with the code*. 13 | 14 | The input to the code is given using an ``.xml`` file containing all the relevant information to perform the fit. 15 | 16 | A Python routine to produce such ``.xml`` files in a semi-automatic way is included in the code repository and can be found in ``BASTA/examples/create_inputfile.py`` if you cloned the code from GitHub or installed the full examples suite with `BASTAexamples full`. You can also obtain this file with `BASTAexamples simple`. This is meant as a basic version just to check that the code is running. It also serves as a template with all options documented. For examples of 'real' fits, have a look at the examples sections in this tutorial (:ref:`examples`). 17 | 18 | The basic procedure to run BASTA can be reduced to the two following steps: 19 | 20 | 1. Create the input file 21 | ======================== 22 | 23 | The following commands will create a file named ``input_myfit.xml`` in the directory ``BASTA/examples/``. 24 | 25 | .. code-block:: bash 26 | 27 | cd BASTA 28 | source bastaenv/bin/activate 29 | cd examples/ 30 | python create_inputfile.py 31 | 32 | 2. Run BASTA 33 | ============ 34 | 35 | Once the ``input_myfit.xml`` has been correctly created, BASTA is simply run as follows (with the virtual environment activated): 36 | 37 | .. code-block:: bash 38 | 39 | BASTArun input_myfit.xml 40 | 41 | The output of the fit is located in ``BASTA/examples/output/myfit`` and we encourage the user to inspect it and ensure that BASTA is correctly running while getting familiar with the type of output and figures produced. 42 | 43 | 44 | Common blocks 45 | ************* 46 | 47 | Regardless of the type of fit, a standard I/O block must be specified containing the name of the ``.xml`` file to be 48 | created, the grid of models to be used, and the output directory for the results. Additionally, an ascii file with the parameters of the star(s) to be fitted must be given (more details in the full file). The following comprises (most of) Block 1 of :py:meth:`create_inputfile.define_input` (note that some comments have been removed compared to the full file): 49 | 50 | .. code-block:: python 51 | 52 | # ================================================================================== 53 | # BLOCK 1: I/O 54 | # ================================================================================== 55 | # Name of the XML input file to produce 56 | xmlfilename = "input_myfit.xml" 57 | 58 | # The path to the grid to be used by BASTA for the fitting. 59 | define_io["gridfile"] = os.path.join(BASTADIR, "grids", "Garstec_16CygA.hdf5") 60 | 61 | # Where to store the output of the BASTA run 62 | define_io["outputpath"] = os.path.join("output", "myfit") 63 | 64 | # Location of the input file with the star(s) to be fitted and the columns included 65 | define_io["asciifile"] = os.path.join("data", "16CygA.ascii") 66 | define_io["params"] = ( 67 | "starid", 68 | "RA", 69 | "DEC", 70 | "numax", 71 | "numax_err", 72 | "dnu", 73 | "dnu_err", 74 | "Teff", 75 | "Teff_err", 76 | "FeH", 77 | "FeH_err", 78 | "logg", 79 | "logg_err", 80 | ) 81 | 82 | Note that BASTA uses the `numpy.genfromtxt `_ 83 | function to read the input ascii file, allowing the presence of additional columns that will not be 84 | used by the code as long as the appropriate number of entries is given in ``define_io["params"]``. 85 | 86 | The other common blocks to all fits are the ones corresponding to the fitting, output, and plotting controls. The main components (again some comments and auxiliary things are removed compared to the file): 87 | 88 | .. code-block:: python 89 | 90 | # ================================================================================== 91 | # BLOCK 2: Fitting control 92 | # ================================================================================== 93 | # A list of the parameters to fit must be given to BASTA in a tuple. 94 | define_fit["fitparams"] = ("Teff", "FeH", "logg") 95 | 96 | # ================================================================================== 97 | # BLOCK 3: Output control 98 | # ================================================================================== 99 | # A list of quantities to output. 100 | define_output["outparams"] = ("Teff", "FeH", "logg", "radPhot", "massfin", "age") 101 | 102 | # Name of the output file containing the results of the fit in ascii format. 103 | define_output["outputfile"] = "results.ascii" 104 | 105 | # A dump of the statistics (chi2, logPDF) for all models in the grids can be saved 106 | # to a .json file. 107 | define_output["optionaloutputs"] = True 108 | 109 | # ================================================================================== 110 | # BLOCK 4: Plotting control 111 | # ================================================================================== 112 | # Corner plots of posteriors. Specify a list of parameters to plot. 113 | define_plots["cornerplots"] = define_output["outparams"] 114 | 115 | # BASTA can produce a Kiel diagram (Teff vs logg) with the observations and the 116 | # model points from the grid. The latter will be color coded based on the fitting 117 | # parameters and their uncertainties/constraints. 118 | define_plots["kielplots"] = True 119 | 120 | 121 | Please note that Block 2 contains five sub-blocks with different controls depending on the specific type of fit. Also note that in the above example, the same quantities being output to ``results.ascii`` are included in the corner plot, but these can be specified independently. Finally, some options have been omitted for clarity, e.g., the entry ``define_plots["freqplots"]`` in Block 4 as it is only relevant when fitting :ref:`example_freqs`. 122 | 123 | **Important** The summary statistics for all stars included in the input ascii will be written to ``results.ascii``, 124 | while figures and details of the run for each individual target will be stored as., ``starid_XXX.png`` and 125 | ``starid.json``. If another run is made for the same stars varying some of the fit parameters, it **must** be stored 126 | in a different folder otherwise BASTA will overwrite the previous output. 127 | -------------------------------------------------------------------------------- /docs/source_auxilfuncs.rst: -------------------------------------------------------------------------------- 1 | .. _auxilfuncs: 2 | 3 | BASTA auxiliary functions 4 | ************************* 5 | 6 | Plotting functions 7 | ================== 8 | 9 | .. automodule:: plot_corner 10 | :members: 11 | 12 | .. automodule:: plot_interp 13 | :members: 14 | 15 | .. automodule:: plot_kiel 16 | :members: 17 | 18 | .. automodule:: plot_seismic 19 | :members: 20 | 21 | Processing tools 22 | ================ 23 | 24 | .. automodule:: create_inputfile 25 | :members: 26 | 27 | .. automodule:: downloader 28 | :members: 29 | 30 | .. automodule:: preview_interpolation 31 | :members: 32 | 33 | .. automodule:: process_jsonfile 34 | :members: 35 | -------------------------------------------------------------------------------- /docs/source_code.rst: -------------------------------------------------------------------------------- 1 | .. _source_code: 2 | 3 | Source code structure 4 | ##################### 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | source_mainfuncs 10 | source_utilfuncs 11 | source_fileiofuncs 12 | source_auxilfuncs 13 | 14 | .. buildfuncs 15 | distfuncs 16 | fiofuncs 17 | auxfuncs 18 | -------------------------------------------------------------------------------- /docs/source_fileiofuncs.rst: -------------------------------------------------------------------------------- 1 | .. _fileiofuncs: 2 | 3 | BASTA FIle I/O functions 4 | ************************ 5 | 6 | .. automodule:: fileio 7 | :members: 8 | 9 | .. automodule:: xml_create 10 | :members: 11 | 12 | .. automodule:: xml_run 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source_mainfuncs.rst: -------------------------------------------------------------------------------- 1 | .. _mainfuncs: 2 | 3 | BASTA main functions 4 | ******************** 5 | 6 | The main BASTA programme 7 | ======================== 8 | 9 | .. automodule:: bastamain 10 | :members: 11 | 12 | .. _constants: 13 | 14 | The constants module 15 | ==================== 16 | 17 | .. automodule:: constants 18 | :members: 19 | 20 | The distance module 21 | =================== 22 | 23 | .. automodule:: distances 24 | :members: 25 | 26 | The asteroseismic module 27 | ======================== 28 | 29 | .. automodule:: freq_fit 30 | :members: 31 | 32 | .. automodule:: glitch_fit 33 | :members: 34 | 35 | The stats module 36 | ================ 37 | 38 | .. automodule:: priors 39 | :members: 40 | 41 | .. automodule:: process_output 42 | :members: 43 | 44 | .. automodule:: stats 45 | :members: 46 | -------------------------------------------------------------------------------- /docs/source_utilfuncs.rst: -------------------------------------------------------------------------------- 1 | .. _utilfuncs: 2 | 3 | BASTA utility functions 4 | *********************** 5 | 6 | .. automodule:: utils_distances 7 | :members: 8 | 9 | .. automodule:: utils_general 10 | :members: 11 | 12 | .. automodule:: utils_seismic 13 | :members: 14 | 15 | .. automodule:: utils_xml 16 | :members: 17 | -------------------------------------------------------------------------------- /docs/troubleshoot.rst: -------------------------------------------------------------------------------- 1 | .. _trouble: 2 | 3 | Troubleshoot 4 | ############ 5 | 6 | Here is an overview of some common/known problems and how to solve them. 7 | 8 | 9 | .. _trouble_quick: 10 | 11 | I don't want to read this whole thing — I just have a question! 12 | *************************************************************** 13 | 14 | **Please do not file an issue to ask a question.** You can use the `discussion tab 15 | `_ on GitHub if you have a 16 | question. You are also free to get in touch with us using some other channel. 17 | 18 | 19 | .. _trouble_virt: 20 | 21 | Installation of the virtual environment 22 | *************************************** 23 | 24 | On certain Linux systems (e.g., specific versions of Debian and Ubuntu), the 25 | creation of the virtualenv will fail with the output: 26 | 27 | .. code-block:: bash 28 | 29 | Error: Command [...] returned non-zero exit status 1 30 | 31 | This due to a problem with a specifc version of ``pyenv``. To fix the problem 32 | do the following: 33 | 34 | .. code-block:: bash 35 | 36 | rm -r venv 37 | python3 -m venv --without-pip venv 38 | source venv/bin/activate 39 | curl https://bootstrap.pypa.io/get-pip.py | python 40 | deactivate 41 | source venv/bin/activate 42 | pip install -r requirements.txt 43 | deactivate 44 | 45 | and everything should be setup correctly. Now, continue following the :ref:`install` instructions. 46 | 47 | 48 | .. _trouble_hdf5: 49 | 50 | Unable to open HDF5 file 51 | ************************ 52 | 53 | HDF5 files are known to sometimes cause problems on NFS-mounted filesystems. This can cause errors of the 54 | form: 55 | 56 | .. code-block:: bash 57 | 58 | OSError: Unable to open file (unable to lock file, errno = 37, error message = 'No locks available') 59 | 60 | To fix this, just run the following in the shell: 61 | 62 | .. code-block:: bash 63 | 64 | export HDF5_USE_FILE_LOCKING=‘FALSE’ 65 | 66 | and try again. If the problem persists, just add the line to your ``~/.bashrc`` (or equivalent). 67 | However, it might have unknown side-effects! 68 | -------------------------------------------------------------------------------- /examples/data/16CygA.ascii: -------------------------------------------------------------------------------- 1 | # starid RA DEC numax enumax dnu ednu teff eteff feh efeh logg elogg 2 | 16CygA 295.45 50.53 2188.5 20.0 103.3 0.50 5825 50 0.10 0.026 4.33 0.07 3 | -------------------------------------------------------------------------------- /examples/data/Kepler_RGB.ascii: -------------------------------------------------------------------------------- 1 | #KIC_ID RA_GAIA DEC_GAIA TEFF ERROR_TEFF F_H ERROR_F_H DNU ERROR_DNU NUMAX ERROR_NUMAX JMAG_TMASS ERROR_JMAG_TMASS HMAG_TMASS ERROR_HMAG_TMASS KMAG_TMASS ERROR_KMAG_TMASS PARALLAX_GAIA ERROR_PARALLAX_GAIA PHASE 2 | 11129442 287.6593666976113 48.763765537235656 4486.0390625 77.0811767578125 0.05205268048970586 0.07018779768794775 4.301 0.02576659803774614 37.47 1.0499687771569208 10.390000343322754 0.020999999716877937 9.800000190734863 0.032999999821186066 9.673999786376953 0.024000000208616257 0.6336537709460811 0.009854819625616074 rgb 3 | -------------------------------------------------------------------------------- /examples/data/Kepler_RGB_change-phase-to-RC.ascii: -------------------------------------------------------------------------------- 1 | #KIC_ID RA_GAIA DEC_GAIA TEFF ERROR_TEFF F_H ERROR_F_H DNU ERROR_DNU NUMAX ERROR_NUMAX JMAG_TMASS ERROR_JMAG_TMASS HMAG_TMASS ERROR_HMAG_TMASS KMAG_TMASS ERROR_KMAG_TMASS PARALLAX_GAIA ERROR_PARALLAX_GAIA PHASE 2 | 11129442 287.6593666976113 48.763765537235656 4486.0390625 77.0811767578125 0.05205268048970586 0.07018779768794775 4.301 0.02576659803774614 37.47 1.0499687771569208 10.390000343322754 0.020999999716877937 9.800000190734863 0.032999999821186066 9.673999786376953 0.024000000208616257 0.6336537709460811 0.009854819625616074 clump 3 | -------------------------------------------------------------------------------- /examples/data/freqs/16CygA.fre: -------------------------------------------------------------------------------- 1 | #order, degree, frequency, error (symmetric), flag (not in use yet) 2 | 11 1 1334.28530945 1.00643301638 1 3 | 12 0 1390.80818859 0.8633433785 1 4 | 12 1 1437.38529836 0.447420447278 1 5 | 12 2 1487.8314424 0.706849942065 1 6 | 13 0 1495.05302937 0.235285033687 1 7 | 13 1 1542.05982978 0.140171466481 1 8 | 13 2 1590.36630376 0.386663478749 1 9 | 14 0 1598.68962055 0.0720618901275 1 10 | 14 1 1645.139472 0.108858525051 1 11 | 14 2 1693.93679038 0.18596079409 1 12 | 15 0 1700.95243323 0.101411045839 1 13 | 15 1 1747.19868228 0.0848920204053 1 14 | 15 2 1795.84331391 0.130726571757 1 15 | 16 0 1802.35128017 0.0794675195876 1 16 | 16 1 1849.00886124 0.0556096542426 1 17 | 16 2 1898.39891315 0.0978307904853 1 18 | 17 0 1904.52077374 0.0583487048825 1 19 | 17 1 1952.00824484 0.0503908592746 1 20 | 17 2 2001.58790927 0.0815081444474 1 21 | 18 0 2007.5379801 0.0445692583862 1 22 | 17 3 2045.85069541 0.368183739741 1 23 | 18 1 2055.49320744 0.0472804914998 1 24 | 18 2 2105.37354776 0.0558153334323 1 25 | 19 0 2110.94954597 0.0407199203066 1 26 | 18 3 2150.05661231 0.204012805992 1 27 | 19 1 2159.14877541 0.0494573640208 1 28 | 19 2 2208.92783634 0.0717291103363 1 29 | 20 0 2214.22506316 0.0537751945651 1 30 | 19 3 2253.79553858 0.250212175298 1 31 | 20 1 2262.56252349 0.0509946731215 1 32 | 20 2 2312.50466457 0.0785928264579 1 33 | 21 0 2317.28210729 0.0569411856738 1 34 | 20 3 2357.49675501 0.226731165752 1 35 | 21 1 2366.24466426 0.0596394964582 1 36 | 21 2 2416.24891009 0.122573197268 1 37 | 22 0 2420.93720443 0.07995713686 1 38 | 21 3 2461.45180311 0.358181828777 1 39 | 22 1 2470.22662466 0.0909626771702 1 40 | 22 2 2520.73413189 0.199416581001 1 41 | 23 0 2524.94962077 0.155829791254 1 42 | 23 1 2574.66041144 0.121085459821 1 43 | 23 2 2624.63604946 0.361848612348 1 44 | 24 0 2628.92965688 0.259114657152 1 45 | 24 1 2679.72574867 0.200730389785 1 46 | 24 2 2730.02356348 0.756400749965 1 47 | 25 0 2733.57075288 0.420028514192 1 48 | 25 1 2783.81583474 0.335402736433 1 49 | 25 2 2836.08826477 0.797972728065 1 50 | 26 0 2840.14780305 0.943677463919 1 51 | 26 1 2890.1976045 0.69212063401 1 52 | 26 2 2940.39275845 1.10281086603 1 53 | 27 0 2944.93721665 0.791933776405 1 54 | 27 1 2994.83963647 1.01260477451 1 55 | -------------------------------------------------------------------------------- /examples/data/freqs/16CygA.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | -------------------------------------------------------------------------------- /examples/data/freqs/Valid_245.fre: -------------------------------------------------------------------------------- 1 | # order, degree, frequency, error (symmetric), flag (not in use yet) 2 | 8 0 428.02553033 0.17026864 1 3 | 8 1 451.23116944 0.13725090 1 4 | 9 0 469.03422874 0.11497947 1 5 | 9 1 488.32052134 0.09381336 1 6 | 10 0 508.90699634 0.07488837 1 7 | 10 1 527.64439079 0.06104803 1 8 | 10 2 544.73664430 0.05100163 1 9 | 11 0 549.27356299 0.04872996 1 10 | 11 1 568.83597854 0.04120327 1 11 | 11 2 586.75712303 0.03726869 1 12 | 12 0 590.29568302 0.03683112 1 13 | 12 1 591.98340155 0.03665656 1 14 | 13 1 612.38267096 0.03654170 1 15 | 12 2 627.14816111 0.03875175 1 16 | 13 0 631.34055645 0.03973418 1 17 | 14 1 640.51384722 0.04238708 1 18 | 15 1 658.21101164 0.04966742 1 19 | 13 2 668.20055273 0.05496026 1 20 | 14 0 672.52683330 0.05759421 1 21 | 16 1 690.29898761 0.06986953 1 22 | 14 2 709.74531269 0.08640084 1 23 | 17 1 712.92723219 0.08958549 1 24 | 15 0 714.25211050 0.09074298 1 25 | 18 1 736.60940556 0.11526906 1 26 | 15 2 751.58002487 0.13367223 1 27 | 16 0 755.97660455 0.13945024 1 28 | 19 1 772.93696075 0.16313009 1 29 | 16 2 793.71084355 0.19695814 1 30 | 20 1 798.05639663 0.20372279 1 31 | 17 0 798.17819936 0.20379684 1 32 | 21 1 821.06428413 0.24617938 1 33 | 18 0 839.95284722 0.28392497 1 34 | 22 1 857.48564215 0.32156001 1 35 | 19 0 881.71001825 0.37994429 1 36 | 23 1 890.99016142 0.40219136 1 37 | 24 1 947.06663105 0.55569654 1 38 | -------------------------------------------------------------------------------- /examples/data/freqs/Valid_245.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /examples/data/subgiant.ascii: -------------------------------------------------------------------------------- 1 | #starid Teff eTeff FeH eFeH dnu ednu numax enumax 2 | Valid_245 5239.75122407817798 70.00000000000000 -0.25142305540132 0.10000000000000 41.03366557478375 0.20663215353800 664.64957303658275 13.17603760179196 3 | -------------------------------------------------------------------------------- /examples/process_jsonfile.py: -------------------------------------------------------------------------------- 1 | """ 2 | An example of how to extract information from a BASTA .json file. 3 | 4 | IMPORTANT: Please run an example producing a json-file to run this tutorial!! 5 | """ 6 | 7 | import os 8 | import sys 9 | 10 | import h5py 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | from scipy.stats import gaussian_kde 14 | from scipy.ndimage import gaussian_filter 15 | 16 | import basta.fileio as fio 17 | from basta.downloader import get_basta_dir 18 | 19 | # Definition of the path to BASTA, just in case you need it 20 | BASTADIR = get_basta_dir() 21 | 22 | 23 | def extract_from_json(jsonfile, gridfile, parameter): 24 | """ 25 | Extract information from a BASTA json file. 26 | 27 | During a fit, if "optionaloutputs" is True, a dump of the statistics for each star 28 | will be stored in a .json file. The grid used to perform the fit is required to 29 | obtain any useful information from the json-dump. 30 | 31 | Parameters 32 | ---------- 33 | jsonfile : str 34 | Path to the .json file from the BASTA fit 35 | 36 | gridfile : str 37 | Path to the grid used to compute the fit 38 | 39 | parameter : str 40 | The parameter values to extract (must be a valid name!) 41 | 42 | Returns 43 | ------- 44 | parametervals : array_like 45 | Values of the given parameter for all models (with non-zero likelihood) in the 46 | grid 47 | 48 | loglikes : array_like 49 | The log(likelihood) of all models in the grid, excluding zero-likelihood models 50 | 51 | chi2 : array_like 52 | The chi**2 values of all models (with non-zero likelihood) in the grid 53 | """ 54 | # The json file can be read into selectedmodels (in BASTA lingo), which contains 55 | # chi2 and log-likelihood (called logPDF internally) of all models in the grid. It 56 | # is stored by track (see below). 57 | selectedmodels = fio.load_selectedmodels(jsonfile) 58 | 59 | # Typically, we want to extract the likelihoods and the values of a given parameter 60 | # for all models in the grid/fit 61 | with h5py.File(gridfile, "r") as grid: 62 | parametervals = [] 63 | loglikes = [] 64 | chi2s = [] 65 | 66 | # In selectedmodels, the information is accessed by looping over the tracks 67 | for trackpath, trackstats in sorted(selectedmodels.items()): 68 | # The log-likelihood (called logPDF) and chi2 can be stored directly 69 | loglikes.append(trackstats.logPDF) 70 | chi2s.append(trackstats.chi2) 71 | 72 | # The corresponding parameter values can be extracted from the grid 73 | gridval = grid["{0}/{1}".format(trackpath, parameter)] 74 | parametervals.append(gridval[trackstats.index]) 75 | 76 | # After extraction it is useful to collapse the lists into numpy arrays 77 | parametervals = np.concatenate(parametervals) 78 | loglikes = np.concatenate(loglikes) 79 | chi2s = np.concatenate(chi2s) 80 | 81 | return parametervals, loglikes, chi2s 82 | 83 | 84 | def sample_posterior(vals, logys): 85 | """ 86 | Computation of the posterior of a parameter by numerical sampling. Duplication of 87 | how it is performed in basta/process_output.py. 88 | 89 | Parameters 90 | ---------- 91 | vals : array_like 92 | Parameter values 93 | 94 | logys : array_like 95 | Corresponding log(likelihood)'s 96 | 97 | Returns 98 | ------ 99 | samples : array_like 100 | Samples of the posterior. Can be used to make the posterior distribution. 101 | """ 102 | lk = logys - np.amax(logys) 103 | post = np.exp(lk - np.log(np.sum(np.exp(lk)))) 104 | nsamples = min(100000, len(logys)) 105 | sampled_indices = np.random.choice(a=np.arange(len(post)), p=post, size=nsamples) 106 | return vals[sampled_indices] 107 | 108 | 109 | def main(): 110 | """ 111 | An example of how to extract information from a BASTA .json file. Will be plotted 112 | as a simple histogram and as a KDE-representation (as BASTA uses for the corner 113 | plots). Uses the auxiliary functions above. 114 | 115 | IMPORTANT: Please run the example in examples/xmlinput/{create_inputfile_json.py, 116 | input_json.xml} or the template examples/{create_inputfile.py, 117 | input_myfit.xml} produce the input files required by this module! 118 | 119 | Parameters 120 | ---------- 121 | None 122 | 123 | Returns 124 | ------- 125 | None 126 | """ 127 | # Init 128 | plt.close("all") 129 | outdir = os.path.join("output", "json-analysis") 130 | if not os.path.exists(outdir): 131 | os.makedirs(outdir) 132 | 133 | # Extract a given parameter and corresponding statistics 134 | param = "massini" 135 | infile = os.path.join("output", "json", "16CygA.json") 136 | gridf = os.path.join(BASTADIR, "grids", "Garstec_16CygA.hdf5") 137 | print(f"Using statistics from '{infile}' with grid from '{gridf}'!\n") 138 | print("Loading stats and grid ... ", end="", flush=True) 139 | try: 140 | paramvals, loglike, _ = extract_from_json( 141 | jsonfile=infile, gridfile=gridf, parameter=param 142 | ) 143 | except FileNotFoundError: 144 | print(f"\nCannot read '{infile}'! Did you run 'xmlinput/input_json.xml'?") 145 | infile = os.path.join("output", "myfit", "16CygA.json") 146 | print(f"Trying '{infile}' instead ... ", end="", flush=True) 147 | try: 148 | paramvals, loglike, _ = extract_from_json( 149 | jsonfile=infile, gridfile=gridf, parameter=param 150 | ) 151 | except FileNotFoundError: 152 | print("\nCannot read that either! Aborting!!") 153 | sys.exit(1) 154 | print("Done!", flush=True) 155 | 156 | # The extracted information can then be used to, e.g., sample the posterior 157 | print("Sampling the posterior ... ", end="", flush=True) 158 | samples = sample_posterior(vals=paramvals, logys=loglike) 159 | print("Done!", flush=True) 160 | 161 | # ... which can then be plotted in a simple, smoothed histogram 162 | print("Creating posterior histogram ... ", end="", flush=True) 163 | _, ax = plt.subplots() 164 | counts, bins = np.histogram(a=samples, bins=100) # Fixed bins 165 | counts = gaussian_filter(input=counts, sigma=2) # Slightly smoothed 166 | x0 = np.array(list(zip(bins[:-1], bins[1:]))).flatten() 167 | y0 = np.array(list(zip(counts, counts))).flatten() 168 | ax.plot(x0, y0, label="Smoothed posterior histogram (100 bins)") 169 | ax.set_xlabel(param) 170 | ax.set_ylabel("Counts") 171 | ax.legend(loc="best", facecolor="none", edgecolor="none", fontsize="small") 172 | plt.savefig( 173 | os.path.join(outdir, f"posterior_{param}_simple.pdf"), bbox_inches="tight" 174 | ) 175 | print("Done!", flush=True) 176 | 177 | # ... or in a KDE smoothed version, like the BASTA cornerplots 178 | print("Creating posterior KDE ... ", end="", flush=True) 179 | histargs = {"color": "tab:cyan", "alpha": 0.17} 180 | histargs_line = {"color": "tab:orange", "alpha": 0.7} 181 | histargs_fill = {"color": "tab:orange", "alpha": 0.1} 182 | _, ax = plt.subplots() 183 | counts, bins = np.histogram(a=samples, bins="auto") 184 | counts = gaussian_filter(input=counts, sigma=1) 185 | kernel = gaussian_kde(samples, bw_method="silverman") 186 | x0 = np.linspace(np.amin(samples), np.amax(samples), num=500) 187 | y0 = kernel(x0) 188 | y0 /= np.amax(y0) 189 | x0_hist = np.array(list(zip(bins[:-1], bins[1:]))).flatten() 190 | y0_hist = np.array(list(zip(counts, counts))).flatten() / np.amax(counts) 191 | ax.fill_between( 192 | x0_hist, y0_hist, interpolate=True, label="Posterior histogram", **histargs 193 | ) 194 | ax.plot(x0, y0, label="Posterior KDE", **histargs_line) 195 | ax.fill_between(x0, y0, interpolate=True, **histargs_fill) 196 | ax.set_xlabel(param) 197 | ax.set_ylabel("Density") 198 | ax.legend(loc="best", facecolor="none", edgecolor="none", fontsize="small") 199 | ax.get_yaxis().set_ticks([]) 200 | plt.savefig(os.path.join(outdir, f"posterior_{param}.pdf"), bbox_inches="tight") 201 | print("Done!", flush=True) 202 | 203 | # Done! 204 | print(f"\nPlots saved to '{outdir}'!") 205 | 206 | 207 | if __name__ == "__main__": 208 | main() 209 | -------------------------------------------------------------------------------- /examples/reference/distance/11129442_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/distance/11129442_corner.pdf -------------------------------------------------------------------------------- /examples/reference/distance/11129442_distance_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/distance/11129442_distance_corner.pdf -------------------------------------------------------------------------------- /examples/reference/distance/11129442_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/distance/11129442_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_corner.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_dupechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_dupechelle.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_dupechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_dupechelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_echelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_echelle.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_echelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_echelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_epsdiff_e012.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_epsdiff_e012.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_epsdiff_e012_cormap.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_epsdiff_e012_cormap.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_pairechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_pairechelle.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_pairechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_pairechelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_ratios_r012.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_ratios_r012.pdf -------------------------------------------------------------------------------- /examples/reference/epsilon/16CygA_ratios_r012_cormap.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/epsilon/16CygA_ratios_r012_cormap.pdf -------------------------------------------------------------------------------- /examples/reference/freqs/16CygA_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/freqs/16CygA_corner.pdf -------------------------------------------------------------------------------- /examples/reference/freqs/16CygA_dupechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/freqs/16CygA_dupechelle.pdf -------------------------------------------------------------------------------- /examples/reference/freqs/16CygA_dupechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/freqs/16CygA_dupechelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/freqs/16CygA_echelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/freqs/16CygA_echelle.pdf -------------------------------------------------------------------------------- /examples/reference/freqs/16CygA_echelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/freqs/16CygA_echelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/freqs/16CygA_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/freqs/16CygA_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/freqs/16CygA_pairechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/freqs/16CygA_pairechelle.pdf -------------------------------------------------------------------------------- /examples/reference/freqs/16CygA_pairechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/freqs/16CygA_pairechelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/glitches/16CygA_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/glitches/16CygA_corner.pdf -------------------------------------------------------------------------------- /examples/reference/glitches/16CygA_dupechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/glitches/16CygA_dupechelle.pdf -------------------------------------------------------------------------------- /examples/reference/glitches/16CygA_dupechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/glitches/16CygA_dupechelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/glitches/16CygA_echelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/glitches/16CygA_echelle.pdf -------------------------------------------------------------------------------- /examples/reference/glitches/16CygA_echelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/glitches/16CygA_echelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/glitches/16CygA_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/glitches/16CygA_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/glitches/16CygA_pairechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/glitches/16CygA_pairechelle.pdf -------------------------------------------------------------------------------- /examples/reference/glitches/16CygA_pairechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/glitches/16CygA_pairechelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/global/16CygA_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/global/16CygA_corner.pdf -------------------------------------------------------------------------------- /examples/reference/global/16CygA_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/global/16CygA_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/interp_MS/16CygA_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/interp_MS/16CygA_corner.pdf -------------------------------------------------------------------------------- /examples/reference/interp_MS/16CygA_dupechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/interp_MS/16CygA_dupechelle.pdf -------------------------------------------------------------------------------- /examples/reference/interp_MS/16CygA_dupechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/interp_MS/16CygA_dupechelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/interp_MS/16CygA_echelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/interp_MS/16CygA_echelle.pdf -------------------------------------------------------------------------------- /examples/reference/interp_MS/16CygA_echelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/interp_MS/16CygA_echelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/interp_MS/16CygA_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/interp_MS/16CygA_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/interp_MS/16CygA_pairechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/interp_MS/16CygA_pairechelle.pdf -------------------------------------------------------------------------------- /examples/reference/interp_MS/16CygA_pairechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/interp_MS/16CygA_pairechelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/interp_MS/intpol_example_16CygA_intpolbase.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/interp_MS/intpol_example_16CygA_intpolbase.pdf -------------------------------------------------------------------------------- /examples/reference/json/16CygA_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/json/16CygA_corner.pdf -------------------------------------------------------------------------------- /examples/reference/json/16CygA_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/json/16CygA_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/parallax/11129442_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/parallax/11129442_corner.pdf -------------------------------------------------------------------------------- /examples/reference/parallax/11129442_distance_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/parallax/11129442_distance_corner.pdf -------------------------------------------------------------------------------- /examples/reference/parallax/11129442_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/parallax/11129442_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/phase/11129442_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/phase/11129442_corner.pdf -------------------------------------------------------------------------------- /examples/reference/phase/11129442_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/phase/11129442_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/preview_interp_MS/16CygA_interp_preview_across_resolution.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/preview_interp_MS/16CygA_interp_preview_across_resolution.pdf -------------------------------------------------------------------------------- /examples/reference/preview_interp_MS/16CygA_interp_preview_along_resolution.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/preview_interp_MS/16CygA_interp_preview_along_resolution.pdf -------------------------------------------------------------------------------- /examples/reference/ratios/16CygA_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/ratios/16CygA_corner.pdf -------------------------------------------------------------------------------- /examples/reference/ratios/16CygA_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/ratios/16CygA_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/ratios/16CygA_ratios_r012.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/ratios/16CygA_ratios_r012.pdf -------------------------------------------------------------------------------- /examples/reference/ratios/16CygA_ratios_r012_cormap.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/ratios/16CygA_ratios_r012_cormap.pdf -------------------------------------------------------------------------------- /examples/reference/subgiant/Valid_245_corner.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/subgiant/Valid_245_corner.pdf -------------------------------------------------------------------------------- /examples/reference/subgiant/Valid_245_dupechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/subgiant/Valid_245_dupechelle.pdf -------------------------------------------------------------------------------- /examples/reference/subgiant/Valid_245_dupechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/subgiant/Valid_245_dupechelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/subgiant/Valid_245_echelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/subgiant/Valid_245_echelle.pdf -------------------------------------------------------------------------------- /examples/reference/subgiant/Valid_245_echelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/subgiant/Valid_245_echelle_uncorrected.pdf -------------------------------------------------------------------------------- /examples/reference/subgiant/Valid_245_kiel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/subgiant/Valid_245_kiel.pdf -------------------------------------------------------------------------------- /examples/reference/subgiant/Valid_245_pairechelle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/subgiant/Valid_245_pairechelle.pdf -------------------------------------------------------------------------------- /examples/reference/subgiant/Valid_245_pairechelle_uncorrected.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/examples/reference/subgiant/Valid_245_pairechelle_uncorrected.pdf -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["hatchling"] 3 | build-backend = "hatchling.build" 4 | 5 | [tool.hatch.version] 6 | path = "src/basta/__about__.py" 7 | 8 | 9 | [project] 10 | name = "BASTA" 11 | description = "The BAyesian STellar Algorithm" 12 | dynamic = ["version"] 13 | authors = [ 14 | { name="The BASTA Team", email="jakob@phys.au.dk" }, 15 | ] 16 | maintainers = [ 17 | { name="Jakob Lysgaard Rørsted", email="jakob@phys.au.dk" }, 18 | ] 19 | readme = "README.md" 20 | license = { file = "LICENSE" } 21 | classifiers = [ 22 | # Full list on https://pypi.org/classifiers/ 23 | "Development Status :: 5 - Production/Stable", 24 | "License :: OSI Approved :: MIT License", 25 | "Intended Audience :: Science/Research", 26 | "Topic :: Scientific/Engineering :: Astronomy", 27 | "Programming Language :: Python :: 3", 28 | "Programming Language :: Python :: 3.10", 29 | "Programming Language :: Python :: 3.11", 30 | "Programming Language :: Python :: 3.12", 31 | ] 32 | requires-python = ">=3.10" 33 | dependencies = [ 34 | "astropy>=6.1.4", 35 | "black>=24.10.0", 36 | "bottleneck>=1.4.2", 37 | "dustmaps>=1.0.13", 38 | "h5py>=3.12.1", 39 | "healpy>=1.18.0", 40 | "matplotlib>=3.9.2", 41 | "numpy>=2.1.3", 42 | "pre-commit>=4.0.1", 43 | "scikit-learn>=1.5.2", 44 | "scipy>=1.14.1", 45 | "tqdm>=4.67.0", 46 | ] 47 | 48 | 49 | [project.urls] 50 | Homepage = "https://github.com/BASTAcode/BASTA" 51 | Documentation = "https://basta.readthedocs.io" 52 | Issues = "https://github.com/BASTAcode/BASTA/issues" 53 | Repository = "https://github.com/BASTAcode/BASTA.git" 54 | 55 | 56 | [project.scripts] 57 | BASTArun = "basta.run:main" 58 | BASTAmultirun = "basta.run:multi" 59 | BASTAdownload = "basta.downloader:main" 60 | BASTAexamples = "basta.downloader_examples:main" 61 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | # Respect the descisions by Black in different tools 2 | [pycodestyle] 3 | max-line-length = 88 4 | ignore = E203, W503 5 | 6 | [flake8] 7 | max-line-length = 88 8 | extend-ignore = E203, W503 9 | 10 | [pylint] 11 | max-line-length = 88 12 | 13 | [pylint.messages_control] 14 | disable = C0330, C0326, C0103, C0209 15 | 16 | [isort] 17 | multi_line_output = 3 18 | include_trailing_comma = True 19 | force_grid_wrap = 0 20 | use_parentheses = True 21 | line_length = 88 22 | -------------------------------------------------------------------------------- /src/basta/__about__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.5.3" 2 | -------------------------------------------------------------------------------- /src/basta/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BASTAcode/BASTA/d544da8535c476b3545f21713a42534bc75f5880/src/basta/__init__.py -------------------------------------------------------------------------------- /src/basta/downloader.py: -------------------------------------------------------------------------------- 1 | """ 2 | Routines to download assets 3 | """ 4 | 5 | import os 6 | import gzip 7 | import shutil 8 | import requests 9 | import argparse 10 | from tqdm import tqdm 11 | 12 | # Import dusmaps configuration (the maps themselves are slow) 13 | from dustmaps.config import config 14 | 15 | DUSTMAPFILE = "_dustpath.py" 16 | GRIDPATHFILE = "_gridpath.py" 17 | 18 | 19 | def get_basta_dir() -> str: 20 | """ 21 | Helper to obtain location of BASTA *source code* directory 22 | 23 | Note: This function was changed in 1.5.0 to not point at the top-level/root dir to 24 | properly handle pip-installations 25 | """ 26 | rootdir = os.path.dirname(os.path.abspath(__file__)) 27 | return rootdir 28 | 29 | 30 | def get_grid(case: str, gridpath=None): 31 | """ 32 | Download a grid from the BASTAcode grid repository. Will be stored in the default 33 | location: BASTA/grids/ . 34 | 35 | Parameters 36 | ---------- 37 | case : str 38 | Which grid to download. Possible value: "16CygA", "validation", "iso". 39 | gridpath : str, optional 40 | Path to user-defined location of where to save grids 41 | """ 42 | # Settings 43 | block_size = 1024 44 | tqdm_settings = { 45 | "unit": "B", 46 | "unit_scale": True, 47 | "unit_divisor": 1024, 48 | "ascii": True, 49 | "desc": "--> Progress", 50 | } 51 | 52 | # Mapping to download location 53 | # --> Switched to anon share link due to (temporary?) issues with ERDA 54 | # NB! Direct link to files differs in URL from true share link... 55 | # (https://anon.erda.au.dk/sharelink/GxpLJyuB4m) 56 | # baseurl = "https://www.erda.au.dk/vgrid/BASTA/public-grids/" 57 | baseurl = "https://anon.erda.au.dk/share_redirect/GxpLJyuB4m/" 58 | 59 | # Resolve grid name and location 60 | # --> Overwrite settings for 'secret' experimental/development grids 61 | if case == "iso": 62 | gridname = "BaSTI_iso2018.hdf5" 63 | elif case in ["16CygA", "validation", "validation_new-weights"]: 64 | gridname = f"Garstec_{case}.hdf5" 65 | elif case in ["barbieMS", "kenMS"]: 66 | print("Important information: Development grid selected!\n") 67 | baseurl = "https://anon.erda.au.dk/share_redirect/aRWqftqng4" 68 | gridname = f"Garstec_{case}.hdf5" 69 | else: 70 | raise ValueError("Unknown grid!") 71 | url = os.path.join(baseurl, f"{gridname}.gz") 72 | 73 | # Default or user-defined location? 74 | home = get_basta_dir() 75 | if gridpath: 76 | basedir = os.path.abspath(gridpath) 77 | else: 78 | basedir = os.path.abspath("grids") 79 | 80 | # Write grid datafolder to file (for easy reference in the examples) 81 | with open(os.path.join(home, GRIDPATHFILE), "w") as f: 82 | f.write(f"__gridpath__ = '{os.path.abspath(basedir)}'\n") 83 | 84 | # Obtain the grid if it does not exist 85 | if not os.path.exists(basedir): 86 | os.makedirs(basedir) 87 | gridpath = os.path.join(basedir, gridname) 88 | if not os.path.exists(gridpath): 89 | try: 90 | # Step 1: Download 91 | gz_tmp = gridpath + ".gz" 92 | print(f"Downloading '{gridname}' to '{gz_tmp}'") 93 | res = requests.get(url, stream=True) 94 | res.raise_for_status() 95 | total_size = int(res.headers.get("content-length", 0)) 96 | with tqdm(total=total_size, **tqdm_settings) as pbar: 97 | with open(gz_tmp, "wb") as fid: 98 | for data in res.iter_content(block_size): 99 | datasize = fid.write(data) 100 | pbar.update(datasize) 101 | 102 | # Step 2: Extract 103 | print( 104 | f"Decompressing grid into '{gridpath}' ... ", 105 | end="", 106 | flush=True, 107 | ) 108 | with gzip.open(gz_tmp, "rb") as fin: 109 | with open(gridpath, "wb") as fout: 110 | shutil.copyfileobj(fin, fout) 111 | print("done!") 112 | 113 | except Exception: 114 | if os.path.exists(gridpath): 115 | shutil.rmtree(gridpath) 116 | raise 117 | 118 | finally: 119 | if os.path.exists(gz_tmp): 120 | os.remove(gz_tmp) 121 | 122 | else: 123 | print(f"The grid '{gridpath}' already exists! Will not download.") 124 | 125 | 126 | def get_dustmaps(dustpath: str | None = None, skip: bool = False): 127 | """ 128 | Configure dustmaps and download if necessary 129 | 130 | Parameters 131 | ---------- 132 | dustpath : str, optional 133 | Where to store/find dustmaps 134 | skip : bool, optional 135 | Skip the download of the dustmaps 136 | """ 137 | home = get_basta_dir() 138 | 139 | # Default or user-defined location? 140 | if dustpath: 141 | dustfolder = os.path.abspath(dustpath) 142 | else: 143 | dustfolder = os.path.abspath("dustmaps") 144 | 145 | # Write dustmap datafolder to file 146 | with open(os.path.join(home, DUSTMAPFILE), "w") as f: 147 | f.write(f"__dustpath__ = '{dustfolder}'\n") 148 | 149 | # Configure package to use the specified path 150 | config["data_dir"] = dustfolder 151 | print("\n=========================") 152 | print(f"Location of dustmaps: {dustfolder}") 153 | if not os.path.exists(dustfolder): 154 | os.mkdir(dustfolder) 155 | 156 | # Install if required 157 | if not skip: 158 | print("Obtaining dustmaps!") 159 | # SFD/Schlegel dustmap 160 | print("\nFetching the SFD dustmap ...\n", flush=True) 161 | import dustmaps.sfd 162 | 163 | dustmaps.sfd.fetch() 164 | print("\nDone!") 165 | print("----------") 166 | 167 | # Bayestar/Green dustmap 168 | print("\nFetching the Bayestar dustmap ...\n", flush=True) 169 | import dustmaps.bayestar 170 | 171 | dustmaps.bayestar.fetch() 172 | print("\nDone!") 173 | else: 174 | print("Assuming dustmaps to be available without download!") 175 | 176 | 177 | def main(): 178 | """ 179 | Run the downloader 180 | """ 181 | helptext = ( 182 | "Download assets for BASTA. Currently, it will download grids and dustmaps." 183 | ) 184 | parser = argparse.ArgumentParser(description=helptext) 185 | 186 | # Argument: Which grid to download 187 | # --> Only these grids are supported 188 | allowed_grids = [ 189 | "16CygA", 190 | "validation", 191 | "iso", 192 | "validation_new-weights", 193 | ] 194 | dev_grids = [ 195 | "barbieMS", 196 | "kenMS", 197 | ] 198 | parser.add_argument( 199 | "grid", help=f"The grid to download. Allowed cases: {allowed_grids}" 200 | ) 201 | 202 | # Optional argument: Where to save the grid 203 | parser.add_argument( 204 | "--gridpath", type=str, help="Store grid in non-standard location." 205 | ) 206 | 207 | # Optional argument: Location of dustmaps 208 | parser.add_argument( 209 | "--dustpath", 210 | type=str, 211 | help="Store dustmaps in non-standard location (will make BASTA search in this location at runtime)", 212 | ) 213 | 214 | # Optional argument: Don't download dustmaps 215 | parser.add_argument( 216 | "--no-dustmaps", 217 | action="store_true", 218 | help="Skip download of dustmaps. Warning: BASTA will not work if they are not available.", 219 | ) 220 | 221 | # Parse and check 222 | args = parser.parse_args() 223 | if args.grid not in allowed_grids: 224 | if args.grid not in dev_grids: 225 | raise ValueError(f"Unknown grid requsted! Select from: {allowed_grids}") 226 | 227 | get_grid(case=args.grid, gridpath=args.gridpath) 228 | get_dustmaps(dustpath=args.dustpath, skip=args.no_dustmaps) 229 | -------------------------------------------------------------------------------- /src/basta/downloader_examples.py: -------------------------------------------------------------------------------- 1 | """ 2 | Routines to download examples (for non-GitHub installations) 3 | """ 4 | 5 | import os 6 | import gzip 7 | import shutil 8 | import tarfile 9 | import requests 10 | import argparse 11 | from tqdm import tqdm 12 | 13 | from basta.__about__ import __version__ 14 | from basta.downloader import get_basta_dir 15 | 16 | EXAMPLESFILE = "_examplespath.py" 17 | 18 | 19 | def get_bundle(version: float, force: bool = False): 20 | """ 21 | Download a bundle file with examples from the BASTAcode examples repository. 22 | 23 | Parameters 24 | ---------- 25 | case : str 26 | Which version of the examples to get 27 | 28 | force : bool, optional 29 | Overwrite existing folder 30 | """ 31 | # Settings 32 | block_size = 1024 33 | tqdm_settings = { 34 | "unit": "B", 35 | "unit_scale": True, 36 | "unit_divisor": 1024, 37 | "ascii": True, 38 | "desc": "--> Progress", 39 | } 40 | 41 | # Mapping to download location 42 | # --> Switched to anon share link due to (temporary?) issues with ERDA 43 | # NB! Direct link to files differs in URL from true share link... 44 | # (https://anon.erda.au.dk/sharelink/FVgq2M3mxY) 45 | # baseurl = "https://www.erda.au.dk/vgrid/BASTA/public-examples/" 46 | baseurl = "https://anon.erda.au.dk/share_redirect/FVgq2M3mxY" 47 | 48 | # Resolve grid name, location and write to file for easy reference 49 | getname = "basta-examples_v" + version.replace(".", "-") + ".tar.gz" 50 | url = os.path.join(baseurl, getname) 51 | basedir = os.path.abspath(".") 52 | outpath = os.path.join(basedir, "examples") 53 | 54 | # Obtain the grid if it does not exist 55 | tmptar = "examples.tar" 56 | if not os.path.exists(outpath) or force: 57 | try: 58 | # Step 1: Download into memory 59 | print(f"Downloading '{getname}'") 60 | res = requests.get(url, stream=True) 61 | res.raise_for_status() 62 | total_size = int(res.headers.get("content-length", 0)) 63 | with tqdm(total=total_size, **tqdm_settings) as pbar: 64 | with open(getname, "wb") as fid: 65 | for data in res.iter_content(block_size): 66 | datasize = fid.write(data) 67 | pbar.update(datasize) 68 | 69 | # Step 2: Extract (first decompress, then inflate tar) 70 | print( 71 | f"Decompressing and inflating into '{outpath}' ... ", 72 | end="", 73 | flush=True, 74 | ) 75 | with gzip.open(getname, "rb") as fin: 76 | with open(tmptar, "wb") as fout: 77 | shutil.copyfileobj(fin, fout) 78 | tar = tarfile.open(tmptar, "r:") 79 | tar.extractall() 80 | tar.close() 81 | print("done!") 82 | 83 | except Exception: 84 | if os.path.exists(getname): 85 | shutil.rmtree(getname) 86 | if os.path.exists(tmptar): 87 | shutil.rmtree(tmptar) 88 | raise 89 | 90 | finally: 91 | if os.path.exists(getname): 92 | os.remove(getname) 93 | if os.path.exists(tmptar): 94 | os.remove(tmptar) 95 | else: 96 | print(f"The folder '{outpath}' already exists! Will not overwrite.") 97 | 98 | 99 | def main(): 100 | """ 101 | Run the examples/templates downloader 102 | """ 103 | helptext = ( 104 | "Download templates and/or examples for BASTA to current working directory." 105 | ) 106 | parser = argparse.ArgumentParser(description=helptext) 107 | 108 | # Argument: How much to download 109 | # --> Only these grids are supported 110 | allowed_cases = [ 111 | "simple", 112 | "full", 113 | ] 114 | parser.add_argument( 115 | "case", 116 | help=( 117 | f"What to download. Allowed cases: {allowed_cases}" 118 | " -- Selecting the simple case will download the template script for " 119 | "creating an input file for BASTA. " 120 | "Selecting the full case will download the entire examples directory" 121 | ), 122 | ) 123 | 124 | # Optional arguments 125 | parser.add_argument( 126 | "--force", action="store_true", help="Overwrite existing file(s)?" 127 | ) 128 | 129 | parser.add_argument( 130 | "--version", 131 | type=str, 132 | help="Get a specific version of the examples (default is to get current)", 133 | ) 134 | 135 | # Parse and check 136 | args = parser.parse_args() 137 | if args.case not in allowed_cases: 138 | raise ValueError(f"Unknown instruction! Select from: {allowed_cases}") 139 | 140 | # Obtain the template input file or the full suite of examples 141 | if args.case == "simple": 142 | outfilename = "create_inputfile.py" 143 | if os.path.isfile(outfilename) and not args.force: 144 | print(f"The file {outfilename} already exists! Aborting...") 145 | return 146 | 147 | print(f"Downloading {outfilename} ...", end=" ") 148 | url = "https://raw.githubusercontent.com/BASTAcode/BASTA/refs/heads/main/examples/create_inputfile.py" 149 | req = requests.get(url) 150 | open(outfilename, "wb").write(req.content) 151 | print("done!") 152 | else: 153 | if args.version: 154 | version = args.version 155 | else: 156 | version = __version__ 157 | get_bundle(version=version, force=args.force) 158 | -------------------------------------------------------------------------------- /src/basta/plots.mplstyle: -------------------------------------------------------------------------------- 1 | # This is the standard settings for plots made with BASTA. 2 | # This way we can make global changes to all plots. 3 | # Settings for seaborn poster 4 | figure.figsize: 12.8, 8.8 5 | axes.labelsize: 17.6 6 | axes.titlesize: 14 7 | xtick.labelsize: 14 8 | ytick.labelsize: 14 9 | legend.fontsize: 12 10 | 11 | grid.linewidth: 1.6 12 | lines.linewidth: 1.4 #2.8 13 | patch.linewidth: 0.48 14 | lines.markersize: 11.2 15 | lines.markeredgewidth: 0 # Markers without fill dissappear! 16 | 17 | xtick.major.width: 1.6 18 | ytick.major.width: 1.6 19 | xtick.minor.width: 0.8 20 | ytick.minor.width: 0.8 21 | 22 | xtick.major.pad: 11.2 23 | ytick.major.pad: 11.2 24 | 25 | # Colours of background and fonts 26 | figure.facecolor: white 27 | text.color: .15 28 | axes.facecolor: white 29 | axes.edgecolor: .15 30 | axes.labelcolor: .15 31 | 32 | # Other font settings 33 | font.family: sans-serif 34 | font.sans-serif: Arial, Liberation Sans, DejaVu Sans, Bitstream Vera Sans, sans-serif 35 | 36 | # Use scientific notation if log10 of the axis range is smaller than the first or larger than the second 37 | axes.formatter.limits: -4, 4 38 | axes.ymargin: .04 39 | 40 | # Legend settings 41 | legend.frameon: False 42 | legend.numpoints: 1 43 | legend.scatterpoints: 1 44 | 45 | # Grid settings 46 | grid.color: .8 47 | axes.axisbelow: True # Draw axis gridlines and ticks below patches 48 | axes.grid: False 49 | grid.linestyle: - 50 | 51 | # Lines 52 | lines.solid_capstyle: round 53 | axes.linewidth: 1.25 54 | 55 | # Ticks 56 | xtick.top: True 57 | xtick.bottom: True 58 | ytick.left: True 59 | ytick.right: True 60 | xtick.major.size: 6 61 | ytick.major.size: 6 62 | xtick.minor.size: 3 63 | ytick.minor.size: 3 64 | 65 | xtick.direction: inout 66 | ytick.direction: inout 67 | xtick.color: .15 68 | ytick.color: .15 69 | 70 | # Seaborn colorblind palette 71 | # Consider changing this to Tableau10 or Tableau20, if you want more colours 72 | # (http://tableaufriction.blogspot.com/2012/11/finally-you-can-use-tableau-data-colors.html). 73 | axes.prop_cycle: cycler('color', ['0072B2', '009E73', 'D55E00', 'CC79A7', 'F0E442', '56B4E9']) 74 | patch.facecolor: 0072B2 75 | -------------------------------------------------------------------------------- /src/basta/priors.py: -------------------------------------------------------------------------------- 1 | """ 2 | Definition of priors 3 | 4 | Define any prior functions here that you want to use in BASTA!! 5 | 6 | The prior function must be of the form: 7 | PRIOR = PRIORFUN(LIBITEM, INDEX) 8 | 9 | Any prior defined here can be used from an .xml input file. 10 | """ 11 | 12 | import numpy as np 13 | from basta import utils_general as util 14 | 15 | 16 | def salpeter1955(libitem, index): 17 | """ 18 | Initial mass function from Salpeter (1955) 19 | https://ui.adsabs.harvard.edu/abs/1955ApJ...121..161S 20 | """ 21 | return libitem["massini"][index] ** (-2.35) 22 | 23 | 24 | def millerscalo1979(libitem, index): 25 | """ 26 | Initial mass function from Miller & Scalo (1979) 27 | https://ui.adsabs.harvard.edu/abs/1979ApJS...41..513M 28 | The global normalisation is not needed as we normalise later. 29 | """ 30 | m = libitem["massini"][index] 31 | ms = [0.1, 1, 10, 100] 32 | alphas = [-1.4, -2.5, -3.3] 33 | ks = util.normfactor(alphas, ms) 34 | if (ms[0] <= m) & (m < ms[1]): 35 | return ks[0] * m ** alphas[0] 36 | elif (ms[1] <= m) & (m < ms[2]): 37 | return ks[1] * m ** alphas[1] 38 | elif (ms[2] <= m) & (m < ms[3]): 39 | return ks[2] * m ** alphas[2] 40 | else: 41 | print("Mass outside range of IMF prior") 42 | return 0 43 | 44 | 45 | def kennicutt1994(libitem, index): 46 | """ 47 | Initial mass function from Kennicutt et al. 1994 48 | https://ui.adsabs.harvard.edu/abs/1994ApJ...435...22K 49 | The global normalisation is not needed as we normalise later. 50 | """ 51 | m = libitem["massini"][index] 52 | ms = [0.1, 1, 100] 53 | alphas = [-1.4, -2.5] 54 | ks = util.normfactor(alphas, ms) 55 | if (ms[0] <= m) & (m < ms[1]): 56 | return ks[0] * m ** alphas[0] 57 | elif (ms[1] <= m) & (m < ms[2]): 58 | return ks[1] * m ** alphas[1] 59 | else: 60 | print("Mass outside range of IMF prior") 61 | return 0 62 | 63 | 64 | def scalo1998(libitem, index): 65 | """ 66 | Initial mass function from Scalo (1998) 67 | https://ui.adsabs.harvard.edu/abs/1998ASPC..142..201S 68 | The global normalisation is not needed as we normalise later. 69 | """ 70 | m = libitem["massini"][index] 71 | ms = [0.1, 1, 10, 100] 72 | alphas = [-1.2, -2.7, -2.3] 73 | ks = util.normfactor(alphas, ms) 74 | if (ms[0] <= m) & (m < ms[1]): 75 | return ks[0] * m ** alphas[0] 76 | elif (ms[1] <= m) & (m < ms[2]): 77 | return ks[1] * m ** alphas[1] 78 | elif (ms[2] <= m) & (m < ms[3]): 79 | return ks[2] * m ** alphas[2] 80 | else: 81 | print("Mass outside range of IMF prior") 82 | return 0 83 | 84 | 85 | def kroupa2001(libitem, index): 86 | """ 87 | Initial mass function from Kroupa (2001) 88 | https://ui.adsabs.harvard.edu/abs/2001MNRAS.322..231K 89 | https://ui.adsabs.harvard.edu/abs/2002Sci...295...82K 90 | The global normalisation is not needed as we normalise later. 91 | """ 92 | m = libitem["massini"][index] 93 | ms = [0.01, 0.08, 0.5, 1, 150] 94 | alphas = [-0.3, -1.3, -2.3] 95 | ks = util.normfactor(alphas, ms) 96 | if (ms[0] <= m) & (m < ms[1]): 97 | return ks[0] * m ** alphas[0] 98 | elif (ms[1] <= m) & (m < ms[2]): 99 | return ks[1] * m ** alphas[1] 100 | # This case and the last case are identical with these values 101 | elif (ms[2] <= m) & (m < ms[4]): 102 | return ks[2] * m ** alphas[2] 103 | else: 104 | print("Mass outside range of IMF prior") 105 | return 0 106 | 107 | 108 | def baldryglazebrook2003(libitem, index): 109 | """ 110 | Initial mass function from Baldry & Glazebrook (2003) 111 | https://ui.adsabs.harvard.edu/abs/2003ApJ...593..258B 112 | The global normalisation is not needed as we normalise later. 113 | """ 114 | m = libitem["massini"][index] 115 | ms = [0.1, 0.5, 120] 116 | alphas = [-1.5, -2.2] 117 | ks = util.normfactor(alphas, ms) 118 | if (ms[0] <= m) & (m < ms[1]): 119 | return ks[0] * m ** alphas[0] 120 | elif (ms[1] <= m) & (m < ms[2]): 121 | return ks[1] * m ** alphas[1] 122 | else: 123 | print("Mass outside range of IMF prior") 124 | return 0 125 | 126 | 127 | def chabrier2003(libitem, index): 128 | """ 129 | Initial mass function from Chabrier (2003) 130 | https://ui.adsabs.harvard.edu/abs/2003PASP..115..763C/abstract 131 | Note that this is in linear mass space, hence the (1/m) 132 | """ 133 | m = libitem["massini"][index] 134 | ks = [0.158, 0.0443] 135 | if m < 1: 136 | return ( 137 | ks[0] 138 | * (1 / m) 139 | * np.exp(-0.5 * ((np.log10(m) - np.log10(0.079)) / 0.69) ** 2) 140 | ) 141 | else: 142 | return ks[1] * m ** (-2.3) 143 | -------------------------------------------------------------------------------- /src/basta/run.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | import numpy as np 4 | from subprocess import run 5 | import multiprocessing as mp 6 | from contextlib import contextmanager 7 | 8 | from basta.xml_run import run_xml 9 | 10 | 11 | @contextmanager 12 | def cd(newdir: str): 13 | """Change directory""" 14 | prevdir = os.getcwd() 15 | os.chdir(os.path.expanduser(newdir)) 16 | try: 17 | yield 18 | finally: 19 | os.chdir(prevdir) 20 | 21 | 22 | def _process_xmldir( 23 | rundir: str, nproc: int = 4, seed: int | None = None, debug: bool = False 24 | ): 25 | """ 26 | Run BASTA on all files in a given directory. Multi-threaded version. 27 | 28 | Parameters 29 | ---------- 30 | rundir : str 31 | Path to fully prepared validation run directory 32 | 33 | nproc : int, optional 34 | Number of cpus to use in the multiprocessing 35 | 36 | debug : bool, optional 37 | Add --debug option for BASTA 38 | 39 | seed : int, optional 40 | Initialise using a specific seed for BASTA 41 | 42 | Returns 43 | ------- 44 | None 45 | 46 | """ 47 | print( 48 | "~~~~~~ RUNNING BASTA ON {0} WITH {1} THREADS NOW ~~~~~~\n".format( 49 | rundir, nproc 50 | ) 51 | ) 52 | with cd(rundir): 53 | # Construct list of XML files in the directory and then process them in parallel 54 | bastatasks = [] 55 | for filename in next(os.walk("."))[2]: 56 | if filename.endswith(".xml"): 57 | cmd = ["BASTArun", filename] 58 | if debug: 59 | cmd.append("--debug") 60 | if seed: 61 | cmd.append("--seed") 62 | cmd.append(str(seed)) 63 | bastatasks.append((cmd,)) 64 | with mp.Pool(processes=nproc) as pool: 65 | pool.starmap(run, bastatasks) 66 | print("\n~~~~~~ DONE! ~~~~~~\n") 67 | 68 | 69 | def main(): 70 | """Main""" 71 | # Setup argument parser 72 | helptext = "BASTA -- Run the BAyesian STellar Algorithm" 73 | parser = argparse.ArgumentParser(description=helptext) 74 | 75 | # Add positional argument (name of inputfile) 76 | parser.add_argument("inputfile", help="The XML input file to run") 77 | 78 | # Add optional argument: Debugging output 79 | parser.add_argument( 80 | "--debug", action="store_true", help="Additional output for debugging." 81 | ) 82 | 83 | # Add optional argument: Extra text output for debugging 84 | parser.add_argument( 85 | "--verbose", 86 | action="store_true", 87 | help="Print additional text output. A lot!" " Combine with the debug flag.", 88 | ) 89 | 90 | # Add optional argument: Experimental features 91 | parser.add_argument( 92 | "--developermode", action="store_true", help="Enable experimental features." 93 | ) 94 | 95 | # Add optional argument: Validation mode 96 | parser.add_argument( 97 | "--validation", 98 | action="store_true", 99 | help="DO NOT USE unless making validation runs.", 100 | ) 101 | 102 | # Add optional argument: Set random seed 103 | parser.add_argument( 104 | "-s", 105 | "--seed", 106 | type=int, 107 | help="Set random seed to ensure deterministic behavior for debugging", 108 | ) 109 | 110 | # Parse the arguments 111 | args = parser.parse_args() 112 | 113 | # Set the random seed if given 114 | if args.seed is not None: 115 | seed = args.seed 116 | else: 117 | seed = np.random.randint(5000) 118 | 119 | np.random.seed(seed) 120 | 121 | # Flag the user if running in validation mode 122 | if args.validation: 123 | print("\n*** Running in VALIDATION MODE ", end="") 124 | 125 | # Call BASTA 126 | run_xml( 127 | vars(args)["inputfile"], 128 | seed=seed, 129 | debug=args.debug, 130 | verbose=args.verbose, 131 | developermode=args.developermode, 132 | validationmode=args.validation, 133 | ) 134 | 135 | 136 | def multi(): 137 | """ 138 | Run BASTA on multiple input files 139 | """ 140 | # Initialise parser and gather arguments 141 | parser = argparse.ArgumentParser(description=("Run BASTA on multiple input files.")) 142 | parser.add_argument( 143 | "xmlpath", help=("Path to the directory with xml files to process.") 144 | ) 145 | parser.add_argument( 146 | "--parallel", 147 | help="Specify number of threads used in multiprocessing." 148 | " If not set, will use max available on system.", 149 | type=int, 150 | ) 151 | parser.add_argument( 152 | "--debug", action="store_true", help="Additional output for debugging." 153 | ) 154 | parser.add_argument( 155 | "-s", 156 | "--seed", 157 | type=int, 158 | help="Set random seed to ensure deterministic behavior for debugging", 159 | ) 160 | args = parser.parse_args() 161 | 162 | if args.parallel: 163 | numthread = args.parallel 164 | else: 165 | numthread = os.cpu_count() 166 | 167 | _process_xmldir( 168 | rundir=os.path.abspath(args.xmlpath), 169 | nproc=numthread, 170 | seed=args.seed, 171 | debug=args.debug, 172 | ) 173 | -------------------------------------------------------------------------------- /src/basta/sd.f95: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | ! 3 | ! SUBROUTINE TO COMPUTE SECOND DIFFERENCES OF OSCILLATION FREQUENCIES 4 | ! -------------------------------------------------------------------------- 5 | ! 6 | ! AUTHOR NAME : KULDEEP VERMA 7 | ! EMAIL ADDRESSES : verma@ice.csic.es, kuldeep@phys.au.dk, 8 | ! kuldeepv89@gmail.com 9 | ! LAST MODIFIED : 12/01/2022 10 | ! 11 | !******************************************************************************* 12 | ! 13 | ! freq : (input) Real array containing the oscillation data 14 | ! (l, n, freq(muHz), err(muHz)) 15 | ! num_of_n : (input) Integer array containing number of modes for each l 16 | ! num_of_l : (input) Number of harmonic degree 17 | ! num_of_mode : (input) Number of modes 18 | ! num_of_dif2 : (input) Number of second differences 19 | ! dif2 : (output) Real array containing the second differences 20 | ! (l, n, freq(muHz), err(muHz), dif2(muHz), err(muHz)) 21 | ! 22 | !******************************************************************************* 23 | 24 | SUBROUTINE SD(freq,num_of_n,num_of_l,num_of_mode,num_of_dif2,dif2) 25 | IMPLICIT NONE 26 | 27 | INTEGER :: num_of_l, num_of_mode, num_of_dif2 28 | INTEGER :: num_of_n(num_of_l) 29 | INTEGER :: i, j, k, l 30 | 31 | REAL*8 :: freq(num_of_mode,4) 32 | REAL*8 :: dif2(num_of_dif2,6) 33 | !f2py intent(in) :: num_of_l, num_of_mode, num_of_dif2, num_of_n, freq 34 | !f2py intent(out) :: dif2 35 | 36 | !Check for missing radial order 37 | k = 0 38 | DO i = 1, num_of_l 39 | IF (num_of_n(i) .EQ. 0) CYCLE 40 | k = k + num_of_n(i) 41 | j = NINT(freq(k,2) - freq(k-num_of_n(i)+1,2) + 1) 42 | IF (j .NE. num_of_n(i)) THEN 43 | WRITE (*,'(A30)') 'ERROR: Missing radial order!' 44 | WRITE (*,'(A10,I2,A6)') 'Check l =', i - 1, 'modes' 45 | STOP 46 | ENDIF 47 | ENDDO 48 | 49 | !Compute second differences (assuming no missing n) 50 | dif2 = 0.d0 !Initialize second differences 51 | k = 0 !run over # of modes 52 | l = 0 !run over # of second differences 53 | DO i = 1, num_of_l 54 | IF (num_of_n(i) .EQ. 0) CYCLE 55 | DO j = 1, num_of_n(i) 56 | IF (j .EQ. 1 .OR. j .EQ. num_of_n(i)) THEN 57 | k = k + 1 58 | CYCLE 59 | ELSE 60 | k = k + 1 61 | l = l + 1 62 | dif2(l,1) = freq(k,1) 63 | dif2(l,2) = freq(k,2) 64 | dif2(l,3) = freq(k,3) 65 | dif2(l,4) = freq(k,4) 66 | dif2(l,5) = freq(k-1,3) - 2.d0*freq(k,3) + freq(k+1,3) 67 | dif2(l,6) = freq(k-1,4)**2 + freq(k+1,4)**2 68 | dif2(l,6) = SQRT(dif2(l,6) + 4.d0*freq(k,4)**2) 69 | ENDIF 70 | ENDDO 71 | ENDDO 72 | 73 | END SUBROUTINE SD 74 | -------------------------------------------------------------------------------- /src/basta/utils_distances.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utility functions for the distance calculation and parallax fitting 3 | """ 4 | 5 | import numpy as np 6 | import matplotlib 7 | 8 | matplotlib.use("Agg") 9 | import matplotlib.pyplot as plt 10 | 11 | 12 | def compute_absmag(m: float, dist: float, A: float) -> float: 13 | """ 14 | Use distance moduli to compute the absolute magnitudes 15 | from distances, apparent magnitudes m, and absorption A. 16 | 17 | Parameters 18 | ---------- 19 | m : float 20 | Apparent magnitude 21 | dist : float 22 | Distances in parsec 23 | A : float 24 | Absorption 25 | 26 | Returns 27 | ------- 28 | M : float 29 | Absolute magnitude 30 | """ 31 | return m - 5 * np.log10(dist / 10) - A 32 | 33 | 34 | def compute_distance_from_mag(m: float, M: float, A: float) -> float: 35 | """ 36 | Compute distance from magnitudes. 37 | 38 | Parameters 39 | ---------- 40 | m : float 41 | Apparent magnitude 42 | M : float 43 | Absolute magnitude 44 | A : float 45 | Absorption 46 | 47 | Returns 48 | ------- 49 | d : float 50 | Distance in parsec 51 | """ 52 | return 10 ** (1 + (m - M - A) / 5.0) 53 | 54 | 55 | def EDSD(libitem: str | None = None, index: int | None = None) -> float: 56 | """ 57 | Exponentially decreasing space density prior 58 | Define characteristic length scale k in kpc 59 | 60 | Parameters 61 | ---------- 62 | libitem : str, None 63 | 64 | index : int, None 65 | 66 | Returns 67 | ------- 68 | k : float 69 | Characteristic length scale in kpc 70 | """ 71 | k = 1.35 72 | return k 73 | 74 | 75 | def loggaussian(x: np.array, mu: float, sigma: float) -> np.array: 76 | """ 77 | Compute the log of a gaussian. 78 | 79 | Parameters 80 | ---------- 81 | x : array-like 82 | Data 83 | mu : float 84 | The mean of x 85 | sigma : float 86 | Standard deviation of x 87 | 88 | Returns 89 | ------- 90 | loggaussian : array 91 | The gaussian data 92 | """ 93 | lnA = -np.log(sigma * np.sqrt(2 * np.pi)) 94 | return lnA - 0.5 * (((x - mu) / sigma) ** 2) 95 | 96 | 97 | def compute_distlikelihoods( 98 | r: np.array, 99 | plxobs: float, 100 | plxobs_err: float, 101 | L: float | None = None, 102 | debug_dirpath: str = "", 103 | debug: bool = False, 104 | ) -> np.array: 105 | """ 106 | Compute the likelihood as the product between a gaussian of the parallax 107 | and the exponentially decreasing volume density prior. 108 | For the unnormalised posterior, see Eq. 18 in Bailer-Jones 2015. 109 | This also works for nonpositive parallaxes. 110 | 111 | Parameters 112 | ---------- 113 | r : float 114 | The distances in pc 115 | plxobs : float 116 | Observed parallax 117 | plsobs_err : float 118 | Uncertainty in observed parallax 119 | L : float 120 | Characteristic scale length of the galaxy 121 | debug : bool 122 | Debug flag, used to trigger certain plots 123 | debug_dirpath : str 124 | Path to where to store debug plots 125 | 126 | """ 127 | if L is None: 128 | L = EDSD(None, None) * 1e3 129 | 130 | lls = loggaussian(1 / r, plxobs, plxobs_err) 131 | lls += 2 * np.log(r) - r / L - np.log(2) - 3 * np.log(L) 132 | lls[r <= 0] = -np.inf 133 | 134 | if debug: 135 | plt.figure() 136 | plt.plot(r, np.exp(lls), "-") 137 | plt.xlabel("Distance (pc)") 138 | plt.ylabel("log PDF") 139 | plt.savefig(debug_dirpath + "_DEBUG_distance_lls.png") 140 | plt.close() 141 | 142 | # Convert from PDF to probability 143 | lls += np.log(np.append(np.diff(r), r[-1] - r[-2])) 144 | assert np.array_equal(r, np.sort(r)) 145 | 146 | lls -= np.amax(lls) 147 | lls -= np.log(np.sum(np.exp(lls))) 148 | return lls 149 | 150 | 151 | def compute_mslikelihoods(ms: np.array, mobs: float, mobs_err: float) -> np.array: 152 | """ 153 | Treat the magnitudes as Gausiians given the observed values and return their likelihoods 154 | 155 | Parameters 156 | ---------- 157 | ms : array-like 158 | Data 159 | mobs : float 160 | The observed apparent magnitude, treated as the mean of ms 161 | mobs_err : float 162 | The observed uncertainty in apparent magnitude, treated as the standard deviation of ms 163 | 164 | Returns 165 | ------- 166 | lls : array 167 | The scaled log-likelihood 168 | """ 169 | lls = loggaussian(ms, mobs, mobs_err) 170 | 171 | # Convert from PDF to probability 172 | lls += np.log(np.append(np.diff(ms), ms[-1] - ms[-2])) 173 | 174 | lls -= np.amax(lls) 175 | lls -= np.log(np.sum(np.exp(lls))) 176 | return lls 177 | -------------------------------------------------------------------------------- /src/basta/utils_xml.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utilities for handling of XML files 3 | """ 4 | 5 | from builtins import str 6 | from xml.dom import minidom 7 | from xml.etree.ElementTree import Element, SubElement, tostring 8 | 9 | import numpy as np 10 | 11 | from basta.constants import parameters 12 | from basta.constants import freqtypes 13 | 14 | 15 | def _get_param(vals, names, param): 16 | """ 17 | Short abbreviation for checking that requested parameter exists in input, 18 | and give meaningfull error if not. 19 | 20 | Parameters 21 | ---------- 22 | vals : list 23 | List of inputted parameter values 24 | names : list 25 | Header with names of the inputted parameters 26 | param : str 27 | The requested parameter from the list 28 | 29 | Returns 30 | ------- 31 | val : float 32 | The value extracted from the input 33 | """ 34 | try: 35 | val = vals[np.where(names == param)[0][0]] 36 | except IndexError: 37 | raise IndexError("%s not found in input" % param) from None 38 | return val 39 | 40 | 41 | def create_xmltag( 42 | main, params, paramvals, fitparams, distparams, freqparams, missingval, intpollim 43 | ): 44 | """ 45 | Creates tags for xml input files 46 | 47 | Parameters 48 | ---------- 49 | main : str 50 | Name of tag added to the xml file. 51 | params : str 52 | Name of the parameters in the ``asciifile`` defined in 53 | :func:`create_xml` 54 | paramvals : int or float or str 55 | Values of the parameters read from the ``asciifile`` in 56 | :func:`create_xml` 57 | fitparams : str 58 | Names of parameters to be fitted in the Bayesian analysis 59 | distparams : str 60 | Additional parameters for the distance calculation 61 | freqparams : str 62 | Additional parameters for the frequency calculation 63 | missingval : int or float or str 64 | Value used to replace missing values in the ascii file 65 | intpollim : list 66 | List of parameters that require values from the stars to set limits 67 | in interpolation. 68 | 69 | Returns 70 | ------- 71 | main : str 72 | Name of the tag added to the xml file 73 | """ 74 | params = np.asarray(params) 75 | starid = _get_param(paramvals, params, "starid") 76 | star = SubElement(main, "star", {"starid": str(starid)}) 77 | 78 | # Special treatment of dnu and numax for frequency fitting 79 | # ++ Make sure to only add them once 80 | nuset = {"dnu": False, "numax": False} 81 | 82 | # Loop over fitting parameters 83 | for param in fitparams: 84 | if param in freqtypes.alltypes: 85 | continue 86 | 87 | # If fitting dnu*, get and save the observed value as simply dnu 88 | param = "dnu" if "dnu" in param else param 89 | paramval = _get_param(paramvals, params, param) 90 | if isinstance(paramval, np.str_) and paramval != missingval: 91 | SubElement(star, param, {"value": str(paramval)}) 92 | if (not isinstance(paramval, np.str_)) and ( 93 | not np.isclose(paramval, missingval) 94 | ): 95 | paramerr = _get_param(paramvals, params, param + "_err") 96 | if not np.isclose(paramerr, missingval): 97 | SubElement( 98 | star, param, {"value": str(paramval), "error": str(paramerr)} 99 | ) 100 | if param in nuset: 101 | nuset[param] = True 102 | 103 | # Handle additional parameters (without errors) 104 | for param in distparams: 105 | paramval = _get_param(paramvals, params, param) 106 | if not np.isclose(paramval, missingval): 107 | SubElement(star, param, {"value": str(paramval)}) 108 | 109 | # Handle the special things for frequency fitting 110 | if freqparams and any(x in fitparams for x in freqtypes.alltypes): 111 | fps = np.asarray(["excludemodes", "nottrustedfile"]) 112 | if any(x in freqparams for x in fps): 113 | x = fps[np.isin(fps, list(freqparams.keys()))][0] 114 | if isinstance(freqparams[x], dict): 115 | if starid in freqparams[x].keys(): 116 | ntf = freqparams[x][starid] 117 | else: 118 | ntf = "None" 119 | SubElement(star, "excludemodes", {"value": ntf}) 120 | elif isinstance(freqparams[x], str): 121 | # Error handling 122 | SubElement(star, "excludemodes", {"value": freqparams[x]}) 123 | else: 124 | raise ValueError("excludemodes is neither a dict or a str") 125 | if "onlyradial" in freqparams: 126 | if freqparams["onlyradial"] in [True, "True", "true"]: 127 | SubElement(star, "onlyradial", {"value": "True"}) 128 | if "onlyls" in freqparams: 129 | assert all(isinstance(x, int) for x in freqparams["onlyls"]) 130 | SubElement( 131 | star, 132 | "onlyls", 133 | {"value": ",".join(map(str, freqparams["onlyls"]))}, 134 | ) 135 | 136 | # Always add dnu and numax for frequency fitting 137 | if not nuset["dnu"]: 138 | dnu = _get_param(paramvals, params, "dnu") 139 | try: 140 | dnu_err = _get_param(paramvals, params, "dnu_err") 141 | SubElement(star, "dnu", {"value": str(dnu), "error": str(dnu_err)}) 142 | except IndexError: 143 | SubElement(star, "dnu", {"value": str(dnu)}) 144 | nuset["dnu"] = True 145 | 146 | if not nuset["numax"]: 147 | numax = _get_param(paramvals, params, "numax") 148 | SubElement(star, "numax", {"value": str(numax)}) 149 | nuset["numax"] = True 150 | 151 | # Handle interpolation parameters (special treatment of dnu; not add if added) 152 | for param in intpollim: 153 | out = {} 154 | gparam = "dnu" if "dnu" in param else param 155 | nucheck = not nuset[gparam] if gparam in nuset else False 156 | if "abstol" in intpollim[param] or nucheck: 157 | paramval = _get_param(paramvals, params, gparam) 158 | if not np.isclose(paramval, missingval): 159 | out["value"] = str(paramval) 160 | if nucheck: 161 | nuset[gparam] = True 162 | if "sigmacut" in intpollim[param]: 163 | paramerr = _get_param(paramvals, params, gparam + "_err") 164 | if not np.isclose(paramerr, missingval): 165 | out["error"] = str(paramerr) 166 | if not nuset[gparam]: 167 | SubElement(star, gparam, out) 168 | 169 | return main 170 | 171 | 172 | def ascii_to_xml(asciifile, outputfile, uncert="quantiles"): 173 | """ 174 | Converts ascii output to XML output 175 | 176 | Parameters 177 | ---------- 178 | asciifile : str 179 | Absolute path to ascii file 180 | outputfile : str 181 | Absolute path to the output XML file 182 | 183 | Returns 184 | ------- 185 | pretty_xml : file 186 | Formatted XML file stored in the ``outputfile`` 187 | """ 188 | 189 | # Load ascii file 190 | results = np.genfromtxt(asciifile, dtype=None, encoding=None, names=True) 191 | if uncert == "quantiles": 192 | params = results.dtype.names[1::3] 193 | else: 194 | params = results.dtype.names[1::2] 195 | if results.ndim == 0: 196 | results = results.reshape(1) 197 | # Prepare list of params 198 | units, shortnames, remarks, _ = parameters.get_keys(params) 199 | 200 | # Make XML magic 201 | stars = Element("stars") 202 | for result in results: 203 | star = SubElement(stars, "star", {"starid": result[0].astype(str)}) 204 | for param, unit, shortname, remark in zip(params, units, shortnames, remarks): 205 | if uncert == "quantiles": 206 | resdict = { 207 | "value": str(result[param]), 208 | "error_plus": str(result[param + "_errp"]), 209 | "error_minus": str(result[param + "_errm"]), 210 | } 211 | else: 212 | resdict = { 213 | "value": str(result[param]), 214 | "error": str(result[param + "_err"]), 215 | } 216 | theparam = SubElement( 217 | star, 218 | param, 219 | resdict, 220 | ) 221 | if unit is not None: 222 | theparam.attrib["unit"] = unit 223 | if remark is not None: 224 | SubElement(theparam, "remarks").text = remark 225 | 226 | pretty_xml = minidom.parseString(tostring(stars)).toprettyxml() 227 | 228 | with open(outputfile, "w") as output: 229 | print(pretty_xml, file=output) 230 | 231 | return pretty_xml 232 | --------------------------------------------------------------------------------