asterion#
Fitting acoustic glitches to the mode frequencies of solar-like oscillators.
Warning
This module is a work-in-progress, use with caution.
Subpackages#
Submodules#
Package Contents#
- class GlitchModel(nu_max, delta_nu, teff=None, epsilon=None, seed=0, window_width='full')[source]#
Bases:
ModelAsteroseismic glitch model.
\[\nu_\mathrm{obs} \sim \mathcal{GP}(m(n), k(n, n') + \sigma^2\mathcal{I})\]Where the mean function is,
\[\begin{split}m(n) &= \nu_\mathrm{bkg} + \delta_\mathrm{He} + \delta_\mathrm{CZ},\\ \nu_\mathrm{bkg} &= f_\mathrm{bkg}(n),\\ \delta_\mathrm{He} &= f_\mathrm{He}(\nu_\mathrm{bkg}),\\ \delta_\mathrm{CZ} &= f_\mathrm{CZ}(\nu_\mathrm{bkg}),\end{split}\]and the kernel function is,
\[k(n, n') = \sigma_k^2 \exp\left( - \frac{(n' - n)^2}{l^2} \right).\]- Parameters
n (array_like) – Radial order of model observations.
nu_max (dist_like) – Prior on the frequency at maximum power.
delta_nu (dist_like) – Prior on the large frequency separation.
teff (dist_like, optional) – Prior on the effective temperature. This is used for estimating a prior on the glitch acoustic depths. If None (default), a prior of Normal(5000, 700) is assumed.
epsilon (dist_like, optional) – Prior on the asymptotic phase parameter.
num_pred (int) – The number of points in radial order for which to make predictions.
seed (int) – The seed used to generate samples from the prior on the glitch periods (acoustic depths) tau_he and tau_cz.
window_width (float) – The number of delta_nu either side of nu_max over which to average the helium glitch amplitude for the parameter ‘he_amplitude’.
- n#
Radial order of model observations.
- Type
- n_pred#
Radial order of model predictions.
- Type
- class GlitchModelComparison(nu_max, delta_nu, teff=None, epsilon=None, seed=0, window_width='full')[source]#
Bases:
GlitchModelAsteroseismic glitch model comparison. Compare the glitch model with a glitchless model. The frequencies are modelled using a GP with the same kernel function but different mean functions.
The glitch model is the same as
GlitchModel. The glitchless model is the same except that the mean function is,\[m_0(n) = f_\mathrm{bkg}(n),\]The two models are compared using the Bayes’ factor,
\[K = \frac{p(\nu_\mathrm{obs} \mid \mathcal{GP}_1)} {p(\nu_\mathrm{obs} \mid \mathcal{GP}_0)}\]where \(\mathcal{GP}_0\) is the glitchless model and \(\mathcal{GP}_1\) is the glitch model.
- Parameters
n (array_like) – Radial order of model observations.
nu_max (dist_like) – Prior on the frequency at maximum power.
delta_nu (dist_like) – Prior on the large frequency separation.
teff (dist_like, optional) – Prior on the effective temperature. This is used for estimating a prior on the glitch acoustic depths. If None (default), a prior of Normal(5000, 700) is assumed.
epsilon (dist_like, optional) – Prior on the asymptotic phase parameter.
num_pred (int) – The number of points in radial order for which to make predictions.
seed (int) – The seed used to generate samples from the prior on the glitch periods (acoustic depths) tau_he and tau_cz.
window_width (float) – The number of delta_nu either side of nu_max over which to average the helium glitch amplitude for the parameter ‘he_amplitude’.
- n#
Radial order of model observations.
- Type
- n_pred#
Radial order of model predictions.
- Type
- class Inference(model, *, n, nu, nu_err=None, seed=0)[source]#
Perform inference on a given model.
- Parameters
model (Model) – Model which predicts the asteroseismic mode frequencies.
nu (array_like) – Asteroseismic mode frequencies.
nu_err (array_like, optional) – Observational uncertainty on the asteroseismic mode frequencies.
seed (int) – Seed for pseudo-random number generation.
Example
from asterion import Model, Inference n = [9, 10, 11, 12, 13] nu = [111.1, 122.2, 133.3, 144.4, 155.5] nu_err = 0.01 model = Model(...) # Construct the model here infer = Inference(model, n=n, nu=nu, nu_err=nu_err, seed=42) # Sample from prior predictive infer.prior_predictive(num_samples=2000) # Sample from posterior infer.sample() # Sample from posterior predictive infer.posterior_predictive() # Get data from inference data = infer.get_data() # Save data data.to_netcdf('inference_data.nc')
- nu#
Observed mode frequencies.
- Type
- nu_err#
Uncertainty on observed mode frequencies.
- Type
numpy.ndarray, optional
- find_map(self, num_steps=10000, handlers=None, reparam='auto', svi_kwargs={})[source]#
EXPERIMENTAL: find MAP.
- Parameters
num_steps (int) – [description]. Defaults to 10000.
handlers (list, optional) – [description]. Defaults to None.
reparam (str, or numpyro.handlers.reparam) – [description]. Defaults to ‘auto’.
svi_kwargs (dict) – [description]. Defaults to {}.
- get_circ_var_names(self)[source]#
[summary]
- Returns
Circular variable names in the model.
- Return type
- get_trace(self, pred=False)[source]#
[summary]
- Parameters
pred (bool) – Whether to trace the predictive model or not. Default is False.
- Returns
Model trace.
- Return type
OrderedDict
- init_mcmc(self, model, num_warmup=1000, num_samples=1000, num_chains=1, sampler='NUTS', sampler_kwargs={}, **kwargs)[source]#
Initialises the MCMC sampler.
- Parameters
model (callable) – [desc]
num_warmup (int) – [description]. Defaults to 1000.
num_samples (int) – [description]. Defaults to 1000.
num_chains (int) – [description]. Defaults to 1.
sampler (str, or numpyro.infer.mcmc.MCMCKernel) – Choose one of [‘NUTS’], or pass a numpyro mcmc kernel.
sampler_kwargs (dict) – Keyword arguments to pass to the chosen sampler.
**kwargs – Keyword arguments to pass to mcmc instance.
- init_nested(self, model, num_live_points=50, max_samples=50000, sampler='multi_ellipsoid', **kwargs)[source]#
[summary]
- Parameters
- Returns
[description]
- Return type
- map_predictive(self, **kwargs)[source]#
EXPERIMENTAL: Get predictive from MAP.
- Parameters
- Returns
[description]
- Return type
- posterior_predictive(self, **kwargs)[source]#
[summary]
- Parameters
**kwargs – Keyword arguments to pass to Predictive instance.
- prior_predictive(self, num_samples=1000, **kwargs)[source]#
[summary]
- Parameters
num_samples (int) – Number of samples to take from the prior.
**kwargs – Keyword arguments to pass to Predictive instance.
- run_mcmc(self, model, num_warmup=1000, num_samples=1000, num_chains=1, sampler='NUTS', sampler_kwargs={}, extra_fields=(), init_params=None, **kwargs)[source]#
Runs MCMC for a given set of model arguments.
- Parameters
model (callable) – [desc]
num_warmup (int) – [description]. Defaults to 1000.
num_samples (int) – [description]. Defaults to 1000.
num_chains (int) – [description]. Defaults to 1.
sampler (str) – Choose one of [‘NUTS’]
sampler_kwargs (dict) – Keyword arguments to pass to the chosen sampler.
extra_fields (tuple) – Extra fields to report in sample_stats. Defaults to ().
init_params (dict) – Initial parameter values prior to sampling. Defaults to None.
**kwargs – Keyword arguments to pass to mcmc instance.
- Returns
[description]
- Return type
- run_nested(self, model, num_live_points=50, num_samples=1000, max_samples=50000, sampler='multi_ellipsoid', **kwargs)[source]#
[summary]
- Parameters
model (Model) – [description]
num_live_points (int) – [description]. Defaults to 100.
num_samples (int) – [description]. Defaults to 1000.
max_samples (int) – [description]. Defaults to 100000.
sampler (str) – [description]. Defaults to “multi_ellipsoid”.
**kwargs – Keyword arguments to pass to nested sampler instance.
- sample(self, num_samples=1000, method='nested', handlers=None, reparam='auto', **kwargs)[source]#
[summary]
- Parameters
num_samples (int) – Number of samples after warmup.
method (str) – Sampling method, choose from [‘mcmc’, ‘nested’].
handlers (list, optional) – Handlers to apply to the model during inference.
reparam (str, or numpyro.infer.reparam.Reparam) – Default is ‘auto’ will automatically reparameterise the model to improve sampling during MCMC.
**kwargs – Keyword arguments to pass to the sampling method.
- get_dims(data, group='posterior')[source]#
Get available dimension groups for a given inference data group.
- Parameters
data (arviz.InferenceData) – Inference data object.
group (str) – Inference data group.
- Returns
[description]
- Return type
- get_labeller(data, group='posterior', var_names=None)[source]#
Get labeller for use with arviz plotting. This automatically searches variable metadata (contained in their attrs dictionary) for its ‘symbol’ and ‘unit’ if available.
- Parameters
data (arviz.InferenceData) – Inference data object.
group (str) – Inference data group for which to map labels.
var_names (list[str], optional) – Variable names for which to map labels.
- Returns
Label map.
- Return type
- get_summary(data, group='posterior', var_names=None, **kwargs)[source]#
Get a summary of the inference data for a chosen group.
- Parameters
data (arviz.InferenceData) – Inference data object.
group (str) – [description]. Defaults to ‘posterior’.
var_names (list, optional) – [description]. Defaults to None (all variable names)
**kwargs – Keyword arguments to pass to
arviz.summary().
- Returns
Summary of inference data.
- Return type
See also
arviz.summary(): The function for which this wraps.
- get_table(data, *, dims, group='posterior', var_names=None, fmt='pandas', round_to='auto', **kwargs)[source]#
Get a table of results for parameters in data corresponding to a chosen model dimension. Two-dimensional tables
- Parameters
data (arviz.InferenceData) – Inference data object.
dims (tuple[str]) – The parameter dimensions for the table. E.g. pass () to return a table of 0-dimensional parameters in data, or pass (‘n’,) for 1-dimensional parameters along dimension ‘n’.
group (str) – Group in data to tabulate. Defaults to ‘posterior’.
var_names (list[str], optional) – Variable names in data to show in table. By default all variables along the chosen dim are shown. Defaults to None.
fmt (str) – Table format, one of [‘pandas’, ‘astropy’]. Defaults to ‘pandas’.
round_to (str, or int) – Precision of table data. Defaults to ‘auto’ which chooses the precision for each variable based on the error on the mean.
**kwargs – Keyword arguments to pass to
get_summary().
- Returns
[description]
- Return type
- get_var_names(data, group='posterior', dims='all')[source]#
Get var names for a given group and dimensions.
- Parameters
data (arviz.InferenceData) – Inference data object.
group (str) – Inference data group.
dims (str, or tuple[str]) – Dimensions by which to group variables. If ‘all’, returns variable names for all model dimensions. If a tuple of dimension names, returns variable names in that dimension group.
- Returns
Variable names for a given group and dimensions.
- Return type
- plot_corner(data, group='posterior', var_names=None, quantiles=None, labeller='auto', **kwargs)[source]#
A wrapper for
corner.corner()with automatic labelling and custom default arguments specified below.- Parameters
data (arviz.InferenceData) – Inference data object.
group (str) – Inference data group from which to take samples. Defaults to ‘posterior’.
var_names (List[str], optional) – Variable names to plot. Defaults to plotting all available variables.
quantiles (iterable, optional) – Quantiles to plot as dashed lines in the marginals. If None, defaults to the 68% confidence interval. Pass an empty list to plot no confidence intervals.
labeller (str, or MapLabeller) – Labeller which maps variable names to their axis labels. Defaults to ‘auto’.
**kwargs – Keyword arguments to pass to
corner.corner().
- Returns
Figure object.
- Return type
See also
corner.corner(): The function for which this wraps.
- plot_echelle(data, group='posterior', kind='full', delta_nu=None, quantiles=None, observed='auto', use_alpha=True, ax=None, **kwargs)[source]#
Plot an echelle diagram of the data.
Choose to plot the full mode, background model or glitchless model. This is compatible with data from inference on models like
GlitchModel.- Parameters
data (az.InferenceData) – Inference data object.
group (str) – On of [‘posterior’, ‘prior’]. Defaults to ‘posterior’.
kind (str) – One of [‘full’, ‘glitchless’, ‘background’]. Defaults to ‘full’ which plots the full model for nu. Use ‘glitchless’ to plot the model without the glitch components. Use ‘background’ to plot the background component of the model.
delta_nu (float, optional) – Large frequency separation to modulo by. If None, the median value from
data['group']is used.quantiles (iterable, optional) – Quantiles to plot as confidence intervals. If None, defaults to the 68% confidence interval. Pass an empty list to plot no confidence intervals.
observed (bool or str) – Whether to plot observed data. Default is “auto” which will plot observed data when group is “posterior”.
use_alpha (bool) – Whether to use alpha channel for transparency. If False, will shade with lightened solid color.
ax (matplotlib.axes.Axes) – Axis on which to plot the echelle.
**kwargs – Keyword arguments to pass to
matplotlib.pyplot.plot().
- Raises
ValueError – If kind is not valid.
- Returns
Axis on which the echelle is plot.
- Return type
- plot_glitch(data, group='posterior', kind='full', x_var='n', quantiles=None, observed='auto', use_alpha=True, ax=None, **kwargs)[source]#
Plot the glitch from either the prior or posterior predictive contained in inference data.
- Parameters
data (arviz.InferenceData) – Inference data object.
group (str) – One of [‘posterior’, ‘prior’].
kind (str) – Kind of glitch to plot. One of [‘full’, ‘helium’, ‘BCZ’].
x_var (str) – Variable name for x-axis. One of [‘n’, ‘nu’]. If ‘nu’, the median value of ‘nu’ in
data['group']is used.quantiles (iterable, optional) – Quantiles to plot as confidence intervals. If None, defaults to the 68% confidence interval. Pass an empty list to plot no confidence intervals.
observed (bool or str) – Whether to plot observed data. Default is “auto” which will plot observed data when group is “posterior”.
use_alpha (bool) – Whether to use alpha channel for transparency. If False, will shade with lightened solid color.
ax (matplotlib.axes.Axes) – Axis on which to plot the glitch.
**kwargs – Keyword arguments to pass to
matplotlib.pyplot.plot().
- Raises
ValueError – If kind is not valid.
- Returns
Axis on which the glitch is plot.
- Return type