Metadata-Version: 2.4
Name: BYOST
Version: 0.0.14
Summary: BYOST (Build Your Own Spectral Template)
Project-URL: Homepage, https://github.com/DeerWhale/BYOST
Project-URL: Documentation, https://deerwhale.github.io/BYOST/
Author-email: Jing Lu <lujingeve158@gmail.com>
License: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Astronomy
Requires-Python: <3.14,>=3.11
Requires-Dist: astropy
Requires-Dist: h5py
Requires-Dist: matplotlib
Requires-Dist: numpy
Requires-Dist: onnxruntime<1.24,>=1.19
Requires-Dist: pandas
Requires-Dist: scikit-learn
Requires-Dist: scipy>=1.9
Requires-Dist: seaborn
Requires-Dist: tqdm
Provides-Extra: dev
Requires-Dist: jupyter-book<2,>=1.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Description-Content-Type: text/markdown

# BYOST (Build Your Own Spectral Template)

Using Principal Component analysis (PCA) and Gaussian Process Regression (GPR) to build a spectral template based on two conditions (such as time and light-curve-shape parameter). 
This work is initially developped to construct the NIR spectral template of type Ia supernovae using the data obtained by CSP-II, see our [publication](https://ui.adsabs.harvard.edu/abs/2023ApJ...948...27L/abstract) for details. 

But it does NOT need to be limited to spectroscopic data, you can use this for other modeling purposes as long as the dataset and attached conditions show correlations (all value need to be finite).  The major process is:
- Apply PCA on the dataset to reduce the dimension to a small subspace
- Moeling the subspace (PC projection values) dependence on the given conditons using GPR 
- Inverse PCA transformation using the predicted PC from GPR given disired condition

## Installation

**Option 1 — install from PyPI with pip:**

```bash
pip install BYOST
```

**Option 2 — install from source with uv:**

```bash
git clone https://github.com/DeerWhale/BYOST.git
cd BYOST
uv sync
```

Use `uv run python` (or `uv run pytest`) to run commands in the project environment. For tests and docs: `uv sync --extra dev`.
## Quick guide

#### 1. General useage of this packge
For general useage of the this packge, please see the [documentation page](https://deerwhale.github.io/BYOST/BYOST_quick_guide.html).


#### 2. NIR spectral template for Type Ia Supernovae from [Lu et al. 2023](https://ui.adsabs.harvard.edu/abs/2023ApJ...948...27L/abstract)

The Lu et al. 2023 NIR template building blocks ship with the package (`BYOST/files/NIR_template_buildingblocks.h5`). No extra download is required:

```python
from BYOST.template import get_Lu2023_NIR_template

epoch = 10   # rest-frame days since B-band maximum
sBV = 0.9    # color stretch

wave, flux = get_Lu2023_NIR_template(epoch, sBV)
# wave: wavelength in Angstroms; flux: template flux (arbitrary units)
```

`epoch` and `sBV` must be single numbers (not lists). Optional keyword `GPR_score_threshold` (default `0.2`) controls which principal components are included in the reconstruction.


## Citations
If you used this package for your research work, please kindly cite [our paper](https://ui.adsabs.harvard.edu/abs/2023ApJ...948...27L/abstract), much appriciated! :)
