A Bayesian CN Hyperfine Spectral Model
Project description
bayes_cn_hfs
A Bayesian CN Hyperfine Spectral Model
bayes_cn_hfs
implements models to infer the physics of the interstellar medium from hyperfine spectral observations as well as the carbon isotopic ratio from observations of CN and 13CN.
- Installation
- Notes on Physics & Radiative Transfer
- Models
- Syntax & Examples
- Issues and Contributing
- License and Copyright
Installation
Basic Installation
Install with pip
in a conda
virtual environment:
conda create --name bayes_cn_hfs -c conda-forge pymc pip
conda activate bayes_cn_hfs
pip install bayes_cn_hfs
Development installation
Alternatively, download and unpack the latest release, or fork the repository and contribute to the development of bayes_cn_hfs
!
Install in a conda
virtual environment:
conda env create -f environment.yml
conda activate bayes_cn_hfs-dev
pip install -e .
Notes on Physics & Radiative Transfer
All models in bayes_cn_hfs
apply the same physics and equations of radiative transfer.
The hyperfine transition upper state column density is derived from the total column density and temperature assuming detailed balance and constant excitation temperature (Magnum & Shirley, 2015, equation 31). For the HFS anomaly models HFSAnomalyModel
and CNRatioAnomalyModel
, the excitation temperature is allowed to vary between components, but the average cloud excitation temperature is used for the detailed balance calculation.
The transition optical depth is taken from Magnum & Shirley (2015) equation 29.
The radiative transfer is calculated explicitly assuming an off-source background temperature bg_temp
(see below) similar to Magnum & Shirley (2015) equation 23. By default, the clouds are ordered from nearest to farthest, so optical depth effects (i.e., self-absorption) may be present.
Notably, since these are forward models, we do not make assumptions regarding the optical depth or the Rayleigh-Jeans limit. These effects are predicted by the model. There is one exception: the ordered
argument, described below.
Models
The models provided by bayes_cn_hfs
are implemented in the bayes_spec
framework. bayes_spec
assumes that the source of spectral line emission can be decomposed into a series of "clouds", each of which is defined by a set of model parameters. Here we define the models available in bayes_cn_hfs
.
HFSModel
The basic model is HFSModel
, a general purpose model for modelling any hyperfine spectral data. The model assumes that the emission can be explained by the radiative transfer of emission through a series of isothermal, homogeneous clouds (in local thermodynamic equilibrium, LTE) as well as a polynomial spectral baseline. The following diagram demonstrates the relationship between the free parameters (empty ellipses), deterministic quantities (rectangles), model predictions (filled ellipses), and observations (filled, round rectangles). Many of the parameters are internally normalized (and thus have names like _norm
). The subsequent tables describe the model parameters in more detail.
Cloud Parametervariable |
Parameter | Units | Prior, where ($p_0, p_1, \dots$) = prior_{variable} |
Defaultprior_{variable} |
---|---|---|---|---|
log10_N |
Total column density | cm-2 |
$\log_{10}N \sim {\rm Normal}(\mu=p_0, \sigma=p_1)$ | [14.0, 1.0] |
log10_tex |
Excitation temperature | K |
$\log_{10}T_{\rm ex} \sim {\rm Normal}(\mu=p_0, \sigma=p_1)$ | [1.0, 0.1] |
log10_fwhm |
FWHM line width | km s-1 |
$\Delta V \sim {\rm HalfNormal}(\sigma=p)$ | 1.0 |
velocity |
Velocity (same reference frame as data) | km s-1 |
$V \sim {\rm Normal}(\mu=p_0, \sigma=p_1)$ | [0.0, 10.0] |
Hyper Parametervariable |
Parameter | Units | Prior, where ($p_0, p_1, \dots$) = prior_{variable} |
Defaultprior_{variable} |
---|---|---|---|---|
rms |
Spectral rms noise | K |
${\rm rms} \sim {\rm HalfNormal}(\sigma=p)$ | 0.01 |
baseline_coeffs |
Normalized polynomial baseline coefficients | `` | $\beta_i \sim {\rm Normal}(\mu=0.0, \sigma=p_i)$ | [1.0]*baseline_degree |
HFSAnomalyModel
HFSAnomalyModel
is like HFSModel
, except that it allows for the excitation temperature of individual hyperfine components to deviate from the average cloud excitation temperature. The following table describes the additional parameters (in addition to those in HFSModel
).
Cloud Parametervariable |
Parameter | Units | Prior, where ($p_0, p_1, \dots$) = prior_{variable} |
Defaultprior_{variable} |
---|---|---|---|---|
tex_anomaly |
Excitation temperature anomaly | K |
$T_{\rm ex} \sim {\rm Normal}(\mu=T_{\rm ex, cloud}, \sigma=p)$ | 1.0 |
CNRatioModel
bayes_cn_hfs
also implements CNRatioModel
, a model to infer the $^{12}{\rm C}/^{13}{\rm C}$ isotopic ratio from hyperfine observations of ${\rm CN}$ and $^{13}{\rm CN}$. Both species are assumed to be described by the same physical conditions (excitation temperature, line width, etc.).
Cloud Parametervariable |
Parameter | Units | Prior, where ($p_0, p_1, \dots$) = prior_{variable} |
Defaultprior_{variable} |
---|---|---|---|---|
log10_N_12CN |
${\rm CN}$ Column density | cm-2 |
$\log_{10}N_{\rm CN} \sim {\rm Normal}(\mu=p_0, \sigma=p_1)$ | [14.0, 1.0] |
log10_tex |
Excitation temperature | K |
$\log_{10}T_{\rm ex} \sim {\rm Normal}(\mu=p_0, \sigma=p_1)$ | [1.0, 0.1] |
log10_fwhm |
FWHM line width | km s-1 |
$\Delta V \sim {\rm HalfNormal}(\sigma=p)$ | 1.0 |
velocity |
Velocity (same reference frame as data) | km s-1 |
$V \sim {\rm Normal}(\mu=p_0, \sigma=p_1)$ | [0.0, 10.0] |
ratio_13C_12C |
$^{13}{\rm C}/^{12}{\rm C}$ abundance ratio by number | `` | $^{13}{\rm C}/^{12}{\rm C} \sim {\rm HalfNormal}(\sigma=p)$ | 0.01 |
Hyper Parametervariable |
Parameter | Units | Prior, where ($p_0, p_1, \dots$) = prior_{variable} |
Defaultprior_{variable} |
---|---|---|---|---|
rms_12CN |
${\rm CN}$ spectral rms noise | K |
${\rm rms} \sim {\rm HalfNormal}(\sigma=p)$ | 0.01 |
rms_13CN |
$^{13}{\rm CN}$ spectral rms noise | K |
${\rm rms} \sim {\rm HalfNormal}(\sigma=p)$ | 0.01 |
baseline_coeffs |
Normalized polynomial baseline coefficients | `` | $\beta_i \sim {\rm Normal}(\mu=0.0, \sigma=p_i)$ | [1.0]*baseline_degree |
CNRatioAnomalyModel
CNRatioAnomalyModel
is like CNRatioModel
, except that it adds hyperfine anomaly parameters to the $^{12}{\rm CN}$ hyperfine transitions only. The following table describes this new parameter.
Cloud Parametervariable |
Parameter | Units | Prior, where ($p_0, p_1, \dots$) = prior_{variable} |
Defaultprior_{variable} |
---|---|---|---|---|
tex_12CN_anomaly |
CN excitation temperature anomaly | K |
$T_{\rm ex, CN} \sim {\rm Normal}(\mu=T_{\rm ex, cloud}, \sigma=p)$ | 1.0 |
ordered
An additional parameter to set_priors
for these models is ordered
. By default, this parameter is False
, in which case the order of the clouds is from nearest to farthest. Sampling from these models can be challenging due to the labeling degeneracy: if the order of clouds does not matter (i.e., the emission is optically thin), then each Markov chain could decide on a different, equally-valid order of clouds.
If we assume that the emission is optically thin, then we can set ordered=True
, in which case the order of clouds is restricted to be increasing with velocity. This assumption can drastically improve sampling efficiency. When ordered=True
, the velocity
prior is defined differently:
Cloud Parametervariable |
Parameter | Units | Prior, where ($p_0, p_1, \dots$) = prior_{variable} |
Defaultprior_{variable} |
---|---|---|---|---|
velocity |
Velocity (same reference frame as data) | km s-1 |
$V_i \sim p_0 + \sum_0^{i-1} V_i + {\rm Gamma}(\alpha=2, \beta=p_1)$ | [0.0, 10.0] |
Syntax & Examples
See the various tutorial notebooks under docs/source/notebooks. Tutorials and the full API are available here: https://bayes-cn-hfs.readthedocs.io.
Issues and Contributing
Anyone is welcome to submit issues or contribute to the development of this software via Github.
License and Copyright
Copyright (c) 2024 Trey Wenger
GNU General Public License v3 (GNU GPLv3)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bayes_cn_hfs-1.0.0.tar.gz
.
File metadata
- Download URL: bayes_cn_hfs-1.0.0.tar.gz
- Upload date:
- Size: 72.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 965c2c15af630bc049e64395ef7cd639a9f88bd6f5830ede8aed2409fd090064 |
|
MD5 | f326638e7b99f51ef6d93b095cd01265 |
|
BLAKE2b-256 | ab4a65b9ea106971901e9d3a6b6a70c73ad8d7e405305a298ead40d28adbc84a |
File details
Details for the file bayes_cn_hfs-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: bayes_cn_hfs-1.0.0-py3-none-any.whl
- Upload date:
- Size: 44.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eb607fa5237dc3d1e9df4ffa3c12ec8bbfb62076acc4d94fba8dcab25fa2895 |
|
MD5 | 343ab04eebeab05d0f10db20c6c62592 |
|
BLAKE2b-256 | 4374c3cf9995392019ff6f172560cd424efdd40e9f35114e4d302956a497932b |