caribou_hi
Submodules
caribou_hi.absorption_model
absorption_model.py AbsorptionModel definition
Copyright(C) 2024-2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)
- class caribou_hi.absorption_model.AbsorptionModel(*args, **kwargs)
Bases:
HIModelDefinition of the AbsorptionModel model.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add additional deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_tau_total, prior_tkin_factor])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “absorption”.
- add_priors(prior_tau_total: float = 1.0, prior_tkin_factor: Iterable[float] = [2.0, 2.0], *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_tau_totalfloat, optional
Prior distribution on total optical depth (km s-1), by default 1.0, where tau_total ~ HalfNormal(sigma=prior)
- prior_tkin_factorIterable[float], optional
Prior distribution on kinetic temperature factor, by default [2.0, 2.0], where tkin_factor ~ Beta(alpha=prior[0], beta=prior[1]) tkin = tkin_factor * tkin_max
caribou_hi.absorption_physical_model
absorption_physical_model.py AbsorptionPhysicalModel definition
Copyright(C) 2024-2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)
- class caribou_hi.absorption_physical_model.AbsorptionPhysicalModel(*args, **kwargs)
Bases:
HIPhysicalModelDefinition of the AbsorptionPhysicalModel model.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_NHI_fwhm2_thermal, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “absorption”.
- add_priors(prior_NHI_fwhm2_thermal: float = 1e+20, prior_fwhm2_thermal_fraction: Iterable[float] = [2.0, 2.0], *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_NHI_fwhm2_thermalfloat, optional
Prior distribution on column density / thermal FWHM2 (cm-2 km-2 s2), by default 1.0e20, where NHI_fwhm2_thermal ~ HalfNormal(sigma=prior)
- prior_fwhm2_thermal_fractionIterable[float], optional
Prior distribution on thermal FWHM^2 / total FWHM^2, by default [2.0, 2.0], where fwhm2_thermal_fraction ~ Beta(alpha=prior[0], beta=prior[1])
caribou_hi.emission_absorption_model
emission_absorption_model.py EmissionAbsorptionModel definition
Copyright(C) 2024-2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)
- class caribou_hi.emission_absorption_model.EmissionAbsorptionModel(*args, bg_temp: float = 3.77, **kwargs)
Bases:
HIModelDefinition of the EmissionAbsorptionModel model. SpecData keys must be “emission” and “absorption”.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add additional deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_filling_factor, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “emission” and “absorption”.
- add_priors(prior_filling_factor: Iterable[float] = [2.0, 1.0], prior_TB_fwhm: float = 50.0, prior_tkin_factor: Iterable[float] = [2.0, 2.0], prior_sigma_log10_NHI: float | None = None, *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_filling_factorIterable[float], optional
Prior distribution on filling factor, by default [2.0, 1.0], where filling_factor ~ Beta(alpha=prior[0], beta=prior[1])
- prior_TB_fwhmfloat, optional
Prior distribution on brightness temperature x FWHM (K km s), by default 50.0, where TB_fwhm ~ HalfNormal(sigma=prior)
- prior_tkin_factorIterable[float], optional
Prior distribution on kinetic temperature factor, by default [2.0, 2.0], where tkin_factor ~ Beta(alpha=prior[0], beta=prior[1]) tkin = tkin_factor * tkin_max
- prior_sigma_log10_NHIOptional[float], optional
Shape parameter that defines the prior distribution on absorption weight / filling factor, by default None, where wt/ff ~ LogNormal(mu=-0.5*ln(10)*prior^2, sigma=prior) i.e., assuming the cloud has a log-normal column density distribution with this width If None, then the absorption weight is assumed to be 1 (i.e., same column density probed in emission and absorption)
caribou_hi.emission_absorption_physical_model
emission_absorption_physical_model.py EmissionAbsorptionPhysicalModel definition
Copyright(C) 2024-2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)
- class caribou_hi.emission_absorption_physical_model.EmissionAbsorptionPhysicalModel(*args, bg_temp: float = 3.77, **kwargs)
Bases:
HIPhysicalModelDefinition of the EmissionAbsorptionPhysicalModel model. SpecData keys must be “emission” and “absorption”.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_filling_factor, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “emission” and “absorption”.
- add_priors(prior_filling_factor: Iterable[float] = [2.0, 1.0], prior_ff_NHI: float = 1e+21, prior_fwhm2_thermal_fraction: Iterable[float] = [2.0, 2.0], prior_sigma_log10_NHI: float = 0.5, *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_filling_factorIterable[float], optional
Prior distribution on filling factor, by default [2.0, 1.0], where filling_factor ~ Beta(alpha=prior[0], beta=prior[1])
- prior_ff_NHIfloat, optional
Prior distribution on filling factor * column density (cm-2), by default 1.0e21, where ff_NHI ~ HalfNormal(sigma=prior)
- prior_fwhm2_thermal_fractionIterable[float], optional
Prior distribution on thermal FWHM^2 / total FWHM^2, by default [2.0, 2.0], where fwhm2_thermal_fraction ~ Beta(alpha=prior[0], beta=prior[1])
- prior_sigma_log10_NHIfloat, optional
Shape parameter that defines the prior distribution on absorption weight / filling factor, by default 0.5, where wt/ff ~ LogNormal(mu=-0.5*ln(10)*prior^2, sigma=prior) i.e., assuming the cloud has a log-normal column density distribution with this width
caribou_hi.emission_model
emission_model.py EmissionPhysicalModel definition
Copyright(C) 2024-2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)
- class caribou_hi.emission_model.EmissionModel(*args, bg_temp: float = 3.77, **kwargs)
Bases:
HIModelDefinition of the EmissionModel model.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add additional deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_filling_factor, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “emission”.
- add_priors(prior_filling_factor: Iterable[float] = [2.0, 1.0], prior_TB_fwhm: float = 50.0, prior_tkin_factor: Iterable[float] = [2.0, 2.0], *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_filling_factorIterable[float], optional
Prior distribution on filling factor, by default [2.0, 1.0], where filling_factor ~ Beta(alpha=prior[0], beta=prior[1])
- prior_TB_fwhmfloat, optional
Prior distribution on brightness temperature x FWHM (K km s), by default 50.0, where TB_fwhm ~ HalfNormal(sigma=prior)
- prior_tkin_factorIterable[float], optional
Prior distribution on kinetic temperature factor, by default [2.0, 2.0], where tkin_factor ~ Beta(alpha=prior[0], beta=prior[1]) tkin = tkin_factor * tkin_max
caribou_hi.emission_physical_model
emission_physical_model.py EmissionPhysicalModel definition
Copyright(C) 2024-2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)
- class caribou_hi.emission_physical_model.EmissionPhysicalModel(*args, bg_temp: float = 3.77, **kwargs)
Bases:
HIPhysicalModelDefinition of the EmissionPhysicalModel model.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_filling_factor, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “emission”.
- add_priors(prior_filling_factor: Iterable[float] = [2.0, 1.0], prior_ff_NHI: float = 1e+21, prior_fwhm2_thermal_fraction: Iterable[float] = [2.0, 2.0], *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_filling_factorIterable[float], optional
Prior distribution on filling factor, by default [2.0, 1.0], where filling_factor ~ Beta(alpha=prior[0], beta=prior[1])
- prior_ff_NHIfloat, optional
Prior distribution on filling factor * column density (cm-2), by default 1.0e21, where ff_NHI ~ HalfNormal(sigma=prior)
- prior_fwhm2_thermal_fractionIterable[float], optional
Prior distribution on thermal FWHM^2 / total FWHM^2, by default [2.0, 2.0], where fwhm2_thermal_fraction ~ Beta(alpha=prior[0], beta=prior[1])
caribou_hi.hi_model
hi_model.py HIModel definition
Copyright(C) 2024-2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)
- class caribou_hi.hi_model.HIModel(*args, **kwargs)
Bases:
BaseModelDefinition of the HIModel model. This model is further extended by other models.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
Add additional deterministic quantities to the model.
add_likelihood(*args, **kwargs)Must be defined in inhereted class.
add_priors([prior_fwhm2, prior_log10_nHI, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_deterministics()
Add additional deterministic quantities to the model.
- abstract add_likelihood(*args, **kwargs)
Must be defined in inhereted class.
- add_priors(prior_fwhm2: float = 200.0, prior_log10_nHI: Iterable[float] = [0.0, 1.5], prior_velocity: Iterable[float] = [-10.0, 10.0], prior_log10_n_alpha: Iterable[float] = [-6.0, 1.0], prior_fwhm_L: float | None = None, prior_baseline_coeffs: dict[str, Iterable[float]] | None = None)
Add priors and deterministics to the model
- Parameters:
- prior_fwhm2float, optional
Prior distribution on FWHM^2 (km2 s-2), by default 200.0, where fwhm2 ~ prior * ChiSquared(nu=1) i.e., half-normal on FWHM
- prior_log10_nHIIterable[float], optional
Prior distribution on log10 volume density (cm-3), by default [0.0, 1.5], where log10_nHI ~ Normal(mu=prior[0], sigma=prior[1])
- prior_velocityIterable[float], optional
Prior distribution on centroid velocity (km s-1), by default [-10.0, 10.0], where velocity_norm ~ Beta(alpha=2.0, beta=2.0) velocity ~ prior[0] + (prior[1] - prior[0]) * velocity_norm
- prior_log10_n_alphaIterable[float], optional
Prior distribution on log10 Lyman alpha photon density (cm-3), by default [-6.0, 1.0], where log10_n_alpha ~ Normal(mu=prior[0], sigma=prior[1])
- prior_fwhm_LOptional[float], optional
Prior distribution on the pseudo-Voight Lorentzian profile line width (km/s), by default None, where fwhm_L ~ HalfNormal(sigma=prior_fwhm_L) If None, the line profile is assumed Gaussian.
- prior_baseline_coeffsOptional[dict[str, Iterable[float]]], optional
Width of normal prior distribution on the normalized baseline polynomial coefficients. Keys are dataset names and values are lists of length baseline_degree+1. If None, use [1.0]*(baseline_degree+1) for each dataset, by default None
caribou_hi.hi_physical_model
hi_physical_model.py HIPhysicalModel definition
Copyright(C) 2024-2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)
- class caribou_hi.hi_physical_model.HIPhysicalModel(*args, **kwargs)
Bases:
BaseModelDefinition of the HIPhysicalModel model. This model is further extended by other models.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
Add deterministic quantities to the model.
add_likelihood(*args, **kwargs)Must be defined in inhereted class.
add_priors([prior_fwhm2, prior_velocity, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_deterministics()
Add deterministic quantities to the model.
- abstract add_likelihood(*args, **kwargs)
Must be defined in inhereted class.
- add_priors(prior_fwhm2: float = 200.0, prior_velocity: Iterable[float] = [-10.0, 10.0], prior_log10_n_alpha: Iterable[float] = [-6.0, 1.0], prior_nth_fwhm_1pc: Iterable[float] = [1.75, 0.25], prior_depth_nth_fwhm_power: Iterable[float] = [0.3, 0.1], prior_fwhm_L: float | None = None, prior_baseline_coeffs: dict[str, Iterable[float]] | None = None)
Add priors and deterministics to the model
- Parameters:
- prior_fwhm2float, optional
Prior distribution on FWHM^2 (km2 s-2), by default 200.0, where fwhm2 ~ prior * ChiSquared(nu=1) i.e., half-normal on FWHM
- prior_velocityIterable[float], optional
Prior distribution on centroid velocity (km s-1), by default [-10.0, 10.0], where velocity_norm ~ Beta(alpha=2.0, beta=2.0) velocity ~ prior[0] + (prior[1] - prior[0]) * velocity_norm
- prior_log10_n_alphaIterable[float], optional
Prior distribution on log10 Lyman alpha photon density (cm-3), by default [-6.0, 1.0], where log10_n_alpha ~ Normal(mu=prior[0], sigma=prior[1])
- prior_nth_fwhm_1pcfloat, optional
Prior distribution on non-thermal line width at 1 pc (km/s), by default [1.75, 0.25], where nth_fwhm_1pc ~ TruncatedNormal(mu=prior[0], sigma=prior[1], lower=0.0)
- prior_depth_nth_fwhm_powerfloat, optional
Prior distribution on non-thermal line width vs. depth power law index, by default [0.3, 0.1], where depth_nth_fwhm_power ~ InverseGamma(mu=prior[0], sigma=prior[1])
- prior_fwhm_LOptional[float], optional
Prior distribution on the pseudo-Voight Lorentzian profile line width (km/s), by default None, where fwhm_L ~ HalfNormal(sigma=prior_fwhm_L) If None, the line profile is assumed Gaussian.
- prior_baseline_coeffsOptional[dict[str, Iterable[float]]], optional
Width of normal prior distribution on the normalized baseline polynomial coefficients. Keys are dataset names and values are lists of length baseline_degree+1. If None, use [1.0]*(baseline_degree+1) for each dataset, by default None
caribou_hi.physics
physics.py Physics utilities
Copyright(C) 2024-2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)
- caribou_hi.physics.calc_depth_nonthermal(fwhm_nonthermal: float, nth_fwhm_1pc: float, depth_nth_fwhm_power: float) float
Calculate the line-of-sight depth from the non-thermal line broadening. This is the inverse of calc_nonthermal_fwhm.
- Parameters:
- fwhm_nonthermalfloat
Non-thermal FWHM line width (km s-1)
- nth_fwhm_1pcfloat
Non-thermal line width at 1 pc(km s-1)
- depth_nth_fwhm_powerfloat
Depth vs. non-thermal line width power law index
- Returns:
- float
Line-of-sight depth (pc)
- caribou_hi.physics.calc_kinetic_temp(thermal_fwhm2: float) float
Calculate the kinetic temperature from the thermal line broadening. This is the inverse of calc_thermal_fwhm. (Condon & Ransom eq. 7.35)
- Parameters:
- thermal_fwhm2float
Thermal FWHM^2 (km2 s-2)
- Returns:
- float
Kinetic temperature (K)
- caribou_hi.physics.calc_log10_column_density(tau_total: float, spin_temp: float) float
Calculate the column density.
- Parameters:
- tau_totalfloat
Total optical depth
- spin_tempfloat
Spin temperature (K)
- Returns:
- float
log10 column density (cm-2)
- caribou_hi.physics.calc_log10_density(log10_column_density: float, log10_depth: float)
Calculate the density.
- Parameters:
- log10_column_densityfloat
log10 column density (cm-2)
- log10_depthfloat
log10 depth (pc)
- Returns:
- float
log10 volume density (cm-3)
- caribou_hi.physics.calc_log10_nonthermal_pressure(log10_density, fwhm2_nonthermal)
Calculate the non-thermal pressure.
- Parameters:
- log10_column_densityfloat
log10 column density (cm-2)
- fwhm2_nonthermalfloat
Non-thermal FWHM^2 (km2 s-2)
- Returns:
- float
log10 non-thermal pressure (K cm-3)
- caribou_hi.physics.calc_nonthermal_fwhm(depth: float, nth_fwhm_1pc: float, depth_nth_fwhm_power: float) float
Calculate the non-thermal line broadening assuming a size-linewidth relationship
- Parameters:
- depthfloat
Line-of-sight depth (pc)
- nth_fwhm_1pcfloat
Non-thermal line width at 1 pc(km s-1)
- depth_nth_fwhm_powerfloat
Depth vs. non-thermal line width power law index
- Returns:
- float
Non-thermal FWHM line width (km s-1)
- caribou_hi.physics.calc_pseudo_voigt(velo_axis: Iterable[float], velocity: Iterable[float], fwhm2: Iterable[float], fwhm_L: float) Iterable[float]
Evaluate a pseudo Voight profile in order to aid in posterior exploration of the parameter space. This parameterization includes a latent variable fwhm_L, which can be conditioned on zero to analyze the posterior. We also consider the spectral channelization. We do not perform a full boxcar convolution, rather we approximate the convolution by assuming an equivalent FWHM for the boxcar kernel of 4 ln(2) / pi * channel_width ~= 0.88 * channel_width
- Parameters:
- velo_axisIterable[float]
Observed velocity axis (km s-1; length S)
- velocityIterable[float]
Cloud center velocity (km s-1; length N)
- fwhm2Iterable[float]
Cloud FWHM^2 line widths (km2 s-2; length N)
- fwhm_Lfloat
Latent pseudo-Voigt profile Lorentzian FWHM (km s-1)
- Returns:
- Iterable[float]
Line profile (MHz-1; shape S x N)
- caribou_hi.physics.calc_spin_temp(kinetic_temp: float, density: float, n_alpha: float) float
Calculate the spin temperature following Kim et al. (2014) eq. 4
- Parameters:
- kinetic_tempfloat
Kinetic temperature (K)
- densityfloat
HI volume density (cm-3)
- n_alphafloat
Lyman alpha photon density (cm-3)
- Returns:
- float
Spin temperature (K)
- caribou_hi.physics.calc_tau_total(column_density: float, spin_temp: float) float
Calculate the total optical depth.
- Parameters:
- column_densityfloat
Column density (cm-2)
- spin_tempfloat
Spin temperature (K)
- Returns:
- float
total optical depth
- caribou_hi.physics.calc_thermal_fwhm2(kinetic_temp: float) float
Calculate the thermal line broadening assuming a Maxwellian velocity distribution (Condon & Ransom eq. 7.35)
- Parameters:
- kinetic_tempfloat
Kinetic temperature (K)
- Returns:
- float
Thermal FWHM^2 line width (km2 s-2)
- caribou_hi.physics.gaussian(x: float, center: float, fwhm: float) float
Evaluate a normalized Gaussian function
- Parameters:
- xfloat
Position at which to evaluate
- centerfloat
Gaussian centroid
- fwhmfloat
Gaussian FWHM line width
- Returns:
- float
Gaussian evaluated at x
- caribou_hi.physics.lorentzian(x: float, center: float, fwhm: float) float
Evaluate a normalized Lorentzian function
- Parameters:
- xfloat
Position at which to evaluate
- centerfloat
Centroid
- fwhmfloat
FWHM
- Returns:
- float
Lorentzian evaluated at x
- caribou_hi.physics.radiative_transfer(tau: Iterable[float], tspin: Iterable[float], filling_factor: Iterable[float], bg_temp: float) Iterable[float]
Evaluate the radiative transfer to predict the emission spectrum. The emission spectrum is ON - OFF, where ON includes the attenuated emission of the background and the clouds, and the OFF is the emission of the background. Order of N clouds is assumed to be [nearest, …, farthest]. The contribution of each cloud is diluted by the filling factor, a number between zero and one.
- Parameters:
- tauIterable[float]
Optical depth spectra (shape S x N)
- tspinIterable[float]
Spin temperatures (K) (shape N)
- filling_factorIterable[float]
Filling factor (between zero and one) (shape N)
- bg_tempfloat
Assumed background temperature
- Returns:
- Iterable[float]
Predicted emission brightness temperature spectrum (K) (length S)
Module contents
- class caribou_hi.AbsorptionModel(*args, **kwargs)
Bases:
HIModelDefinition of the AbsorptionModel model.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add additional deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_tau_total, prior_tkin_factor])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “absorption”.
- add_priors(prior_tau_total: float = 1.0, prior_tkin_factor: Iterable[float] = [2.0, 2.0], *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_tau_totalfloat, optional
Prior distribution on total optical depth (km s-1), by default 1.0, where tau_total ~ HalfNormal(sigma=prior)
- prior_tkin_factorIterable[float], optional
Prior distribution on kinetic temperature factor, by default [2.0, 2.0], where tkin_factor ~ Beta(alpha=prior[0], beta=prior[1]) tkin = tkin_factor * tkin_max
- class caribou_hi.AbsorptionPhysicalModel(*args, **kwargs)
Bases:
HIPhysicalModelDefinition of the AbsorptionPhysicalModel model.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_NHI_fwhm2_thermal, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “absorption”.
- add_priors(prior_NHI_fwhm2_thermal: float = 1e+20, prior_fwhm2_thermal_fraction: Iterable[float] = [2.0, 2.0], *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_NHI_fwhm2_thermalfloat, optional
Prior distribution on column density / thermal FWHM2 (cm-2 km-2 s2), by default 1.0e20, where NHI_fwhm2_thermal ~ HalfNormal(sigma=prior)
- prior_fwhm2_thermal_fractionIterable[float], optional
Prior distribution on thermal FWHM^2 / total FWHM^2, by default [2.0, 2.0], where fwhm2_thermal_fraction ~ Beta(alpha=prior[0], beta=prior[1])
- class caribou_hi.EmissionAbsorptionModel(*args, bg_temp: float = 3.77, **kwargs)
Bases:
HIModelDefinition of the EmissionAbsorptionModel model. SpecData keys must be “emission” and “absorption”.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add additional deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_filling_factor, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “emission” and “absorption”.
- add_priors(prior_filling_factor: Iterable[float] = [2.0, 1.0], prior_TB_fwhm: float = 50.0, prior_tkin_factor: Iterable[float] = [2.0, 2.0], prior_sigma_log10_NHI: float | None = None, *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_filling_factorIterable[float], optional
Prior distribution on filling factor, by default [2.0, 1.0], where filling_factor ~ Beta(alpha=prior[0], beta=prior[1])
- prior_TB_fwhmfloat, optional
Prior distribution on brightness temperature x FWHM (K km s), by default 50.0, where TB_fwhm ~ HalfNormal(sigma=prior)
- prior_tkin_factorIterable[float], optional
Prior distribution on kinetic temperature factor, by default [2.0, 2.0], where tkin_factor ~ Beta(alpha=prior[0], beta=prior[1]) tkin = tkin_factor * tkin_max
- prior_sigma_log10_NHIOptional[float], optional
Shape parameter that defines the prior distribution on absorption weight / filling factor, by default None, where wt/ff ~ LogNormal(mu=-0.5*ln(10)*prior^2, sigma=prior) i.e., assuming the cloud has a log-normal column density distribution with this width If None, then the absorption weight is assumed to be 1 (i.e., same column density probed in emission and absorption)
- class caribou_hi.EmissionAbsorptionPhysicalModel(*args, bg_temp: float = 3.77, **kwargs)
Bases:
HIPhysicalModelDefinition of the EmissionAbsorptionPhysicalModel model. SpecData keys must be “emission” and “absorption”.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_filling_factor, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “emission” and “absorption”.
- add_priors(prior_filling_factor: Iterable[float] = [2.0, 1.0], prior_ff_NHI: float = 1e+21, prior_fwhm2_thermal_fraction: Iterable[float] = [2.0, 2.0], prior_sigma_log10_NHI: float = 0.5, *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_filling_factorIterable[float], optional
Prior distribution on filling factor, by default [2.0, 1.0], where filling_factor ~ Beta(alpha=prior[0], beta=prior[1])
- prior_ff_NHIfloat, optional
Prior distribution on filling factor * column density (cm-2), by default 1.0e21, where ff_NHI ~ HalfNormal(sigma=prior)
- prior_fwhm2_thermal_fractionIterable[float], optional
Prior distribution on thermal FWHM^2 / total FWHM^2, by default [2.0, 2.0], where fwhm2_thermal_fraction ~ Beta(alpha=prior[0], beta=prior[1])
- prior_sigma_log10_NHIfloat, optional
Shape parameter that defines the prior distribution on absorption weight / filling factor, by default 0.5, where wt/ff ~ LogNormal(mu=-0.5*ln(10)*prior^2, sigma=prior) i.e., assuming the cloud has a log-normal column density distribution with this width
- class caribou_hi.EmissionModel(*args, bg_temp: float = 3.77, **kwargs)
Bases:
HIModelDefinition of the EmissionModel model.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add additional deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_filling_factor, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “emission”.
- add_priors(prior_filling_factor: Iterable[float] = [2.0, 1.0], prior_TB_fwhm: float = 50.0, prior_tkin_factor: Iterable[float] = [2.0, 2.0], *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_filling_factorIterable[float], optional
Prior distribution on filling factor, by default [2.0, 1.0], where filling_factor ~ Beta(alpha=prior[0], beta=prior[1])
- prior_TB_fwhmfloat, optional
Prior distribution on brightness temperature x FWHM (K km s), by default 50.0, where TB_fwhm ~ HalfNormal(sigma=prior)
- prior_tkin_factorIterable[float], optional
Prior distribution on kinetic temperature factor, by default [2.0, 2.0], where tkin_factor ~ Beta(alpha=prior[0], beta=prior[1]) tkin = tkin_factor * tkin_max
- class caribou_hi.EmissionPhysicalModel(*args, bg_temp: float = 3.77, **kwargs)
Bases:
HIPhysicalModelDefinition of the EmissionPhysicalModel model.
- Attributes:
baseline_deterministicsGet the deterministic baseline parameter names.
baseline_freeRVsGet the free baseline parameter names.
cloud_deterministicsGet the deterministic cloud parameter names.
cloud_freeRVsGet the free cloud parameter names.
hyper_deterministicsGet the deterministic hyper parameter names.
hyper_freeRVsGet the free hyper parameter names.
labellerGet the arviz labeller.
unique_solutionCheck if posterior samples suggest a unique solution.
Methods
add_baseline_priors([prior_baseline_coeffs])Add baseline priors to the model.
add_deterministics()Add deterministic quantities to the model.
Add likelihood to the model.
add_priors([prior_filling_factor, ...])Add priors and deterministics to the model
bic([chain, solution])Calculate the Bayesian information criterion at the mean point estimate.
fit([n, draws, rel_tolerance, ...])Approximate posterior distribution using Variational Inference (VI).
graph()Generate visualization of the model graph.
mean_lnlike([chain, solution])Evaluate mean log-likelihood over posterior samples.
null_bic()Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)
predict_baseline([baseline_params])Predict the un-normalized baseline model.
reset_results()Reset results and convergence checks.
sample([init, n_init, chains, init_kwargs, ...])Sample posterior distribution using MCMC.
sample_posterior_predictive([solution, thin])Generate posterior predictive samples
sample_prior_predictive([samples])Generate prior predictive samples
sample_smc(**kwargs)Sample posterior distribution using Sequential Monte Carlo.
solve(**kwargs)Identify unique solutions and break the labeling degeneracy.
- add_likelihood()
Add likelihood to the model. SpecData key must be “emission”.
- add_priors(prior_filling_factor: Iterable[float] = [2.0, 1.0], prior_ff_NHI: float = 1e+21, prior_fwhm2_thermal_fraction: Iterable[float] = [2.0, 2.0], *args, **kwargs)
Add priors and deterministics to the model
- Parameters:
- prior_filling_factorIterable[float], optional
Prior distribution on filling factor, by default [2.0, 1.0], where filling_factor ~ Beta(alpha=prior[0], beta=prior[1])
- prior_ff_NHIfloat, optional
Prior distribution on filling factor * column density (cm-2), by default 1.0e21, where ff_NHI ~ HalfNormal(sigma=prior)
- prior_fwhm2_thermal_fractionIterable[float], optional
Prior distribution on thermal FWHM^2 / total FWHM^2, by default [2.0, 2.0], where fwhm2_thermal_fraction ~ Beta(alpha=prior[0], beta=prior[1])