jar¶
This module contains general purpose functions that are used throughout PBjam.
- pbjam.jar.attenuation(f, nyq)[source]¶
The sampling attenuation
Determine the attenuation of the PSD due to the discrete sampling of the variability.
- Parameters:
f (np.array) – Frequency axis of the PSD.
nyq (float) – The Nyquist frequency of the observations.
- Returns:
eta – The attenuation at each frequency.
- Return type:
np.array
- class pbjam.jar.bibliography[source]¶
A class for managing references used when running PBjam.
This is inherited by session and star.
- bibfile¶
The pathname to the pbjam references list.
- Type:
str
- _reflist¶
List of references that is updated when new functions are used.
- Type:
list
- bibdict¶
Dictionary of bib items from the PBjam reference list.
- Type:
dict
- class pbjam.jar.constants(nu_to_omega: float = 6.283185307179587e-06, c: float = 299792.458)[source]¶
A dataclass for storing astrophysical constants and conversion factors.
- nu_to_omega¶
Conversion factor from frequency (muHz) to angular frequency (radians/muHz). Default is 2 * jnp.pi / 1e6.
- Type:
float
- pbjam.jar.envelope(nu, env_height, numax, env_width, **kwargs)[source]¶
Power of the seismic p-mode envelope
Computes the power at frequency nu in the oscillation envelope from a Gaussian distribution. Used for computing mode heights.
- Parameters:
nu (float) – Frequency (in muHz).
hmax (float) – Height of p-mode envelope (in SNR).
numax (float) – Frequency of maximum power of the p-mode envelope (in muHz).
width (float) – Width of the p-mode envelope (in muHz).
- Returns:
h – Power at frequency nu (in SNR)
- Return type:
float
- pbjam.jar.gaussian(x, A, mu, sigma)[source]¶
Computes the Gaussian function.
- Parameters:
x (array-like) – Input array of x values.
A (float) – Amplitude of the Gaussian.
mu (float) – Mean (center) of the Gaussian.
sigma (float) – Standard deviation (width) of the Gaussian.
- Returns:
The computed Gaussian function values.
- Return type:
array-like
- class pbjam.jar.generalModelFuncs[source]¶
A class containing general model functions for various models in PBjam.
This class in inherited by the model classes.
- addAddObsLike(thetaU)[source]¶
Add the additional probabilities to likelihood
Adds the additional observational data likelihoods to the PSD likelihood.
- Parameters:
p (list) – Sampling parameters.
- Returns:
lnp – The likelihood of a sample given the parameter PDFs.
- Return type:
float
- chi_sqr(mod)[source]¶
Chi^2 2 dof likelihood
Evaluates the likelihood of observing the data given the model.
- Parameters:
mod (jax device array) – Spectrum model.
- Returns:
L – Likelihood of the data given the model
- Return type:
float
- getMedianModel(samplesU=None, rint=None, N=30)[source]¶
Computes the median model from a set of N samples drawn from the posterior.
- Parameters:
samplesU (dict, optional) – A dictionary of samples where each key corresponds to a parameter and each value is a list of sample values for that parameter. If None, it uses self.samples unpacked using self.unpackSamples.
rint (array-like, optional) – Indices to select specific samples. If None, N indices are randomly chosen without replacement.
N (int, optional) – The number of samples to use for computing the median model. Default is 30.
- Returns:
The median background model computed from the samples.
- Return type:
ndarray
- lnlikelihood(theta)[source]¶
Calculate the log likelihood of the model given parameters and data.
- Parameters:
theta (numpy.ndarray) – Parameter values.
nu (numpy.ndarray) – Array of frequency values.
- Returns:
Log-likelihood value.
- Return type:
float
- obsOnlylnlikelihood(theta)[source]¶
Computes the log-likelihood using just the obs parameters.
This ignores all spectrum information.
- Parameters:
theta (array-like) – Parameter vector.
- Returns:
lnlike – Log-likelihood value.
- Return type:
float
- setAddObs(keys)[source]¶
Set attribute containing additional observational data
Additional observational data other than the power spectrum goes here.
Can be Teff or bp_rp color, but may also be additional constraints on e.g., numax, dnu.
- Parameters:
keys (list) – List of keys for additional observational data.
- setLabels(addPriors, modelParLabels)[source]¶
Set parameter labels and categorize them based on priors.
- Parameters:
priors (dict) – Dictionary containing prior information for specific parameters.
Notes
Initializes default PCA and additional parameter lists.
- Checks if parameters are marked for PCA and not in priors; if so,
adds to PCA list.
Otherwise, adds parameters to the additional list.
Combines PCA and additional lists to create the final labels list.
- Identifies parameters that use a logarithmic scale and adds them to
logpars list.
- unpackSamples(samples=None)[source]¶
Unpack a set of parameter samples into a dictionary of arrays.
- Parameters:
samples (array-like) – A 2D array of shape (n, m), where n is the number of samples and m is the number of parameters.
- Returns:
S – A dictionary containing the parameter values for each parameter label.
- Return type:
dict
Notes
This method takes a 2D numpy array of parameter samples and unpacks each sample into a dictionary of parameter values. The keys of the dictionary are the parameter labels and the values are 1D numpy arrays containing the parameter values for each sample.
Examples
>>> class MyModel: ... def __init__(self): ... self.labels = ['a', 'b', 'c'] ... def unpackParams(self, theta): ... return {'a': theta[0], 'b': theta[1], 'c': theta[2]} ... def unpackSamples(self, samples): ... S = {key: np.zeros(samples.shape[0]) for key in self.labels} ... for i, theta in enumerate(samples): ... theta_u = self.unpackParams(theta) ... for key in self.labels: ... S[key][i] = theta_u[key] ... return S ... >>> model = MyModel() >>> samples = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> S = model.unpackSamples(samples) >>> print(S) {'a': array([1., 4., 7.]), 'b': array([2., 5., 8.]), 'c': array([3., 6., 9.])}
- pbjam.jar.getCurvePercentiles(x, y, cdf=None, percentiles=None)[source]¶
Compute percentiles of value along a curve
Computes the cumulative sum of y, normalized to unit maximum. The returned percentiles values are where the cumulative sum exceeds the requested percentiles.
- Parameters:
x (array) – Support for y.
y (array) – Array
percentiles (array)
- Returns:
percs – Values of y at the requested percentiles.
- Return type:
array
- pbjam.jar.getNormalPercentiles(X, nsigma=2, **kwargs)[source]¶
Get percentiles of an distribution
Compute the percentiles corresponding to sigma=1,2,3.. including the median (50th), of an array.
- Parameters:
X (numpy.array()) – Array to find percentiles of
sigma (int, optional.) – Sigma values to compute the percentiles of, e.g. 68% 95% are 1 and 2 sigma, etc. Default is 2.
kwargs (dict) – Arguments to be passed to numpy.percentile
- Returns:
percentiles – Numpy array of percentile values of X.
- Return type:
numpy.array()
- pbjam.jar.lor(nu, nu0, h, w)[source]¶
Lorentzian to describe an oscillation mode.
- Parameters:
nu0 (float) – Frequency of lorentzian (muHz).
h (float) – Height of the lorentizan (SNR).
w (float) – Full width of the lorentzian (muHz).
- Returns:
mode – The SNR as a function frequency for a lorentzian.
- Return type:
ndarray
- pbjam.jar.modeUpdoot(result, sample, key, Nmodes)[source]¶
Updates the result dictionary with summary statistics and samples for a given key.
- Parameters:
result (dict) – The result dictionary to be updated. It should contain ‘summary’ and ‘samples’ sub-dictionaries.
sample (ndarray) – The sample data to be added to the result. It is an array of shape (Nsamples, Nmodes).
key (str) – The key under which the summary statistics and samples are to be stored in the result dictionary.
Nmodes (int) – The number of modes (columns) in the sample array.
- pbjam.jar.normal(x, mu, sigma)[source]¶
Evaluate logarithm of normal distribution (not normalized!!)
Evaluates the logarithm of a normal distribution at x.
Inputs¶
- xfloat
Values to evaluate the normal distribution at.
- mufloat
Distribution mean.
- sigmafloat
Distribution standard deviation.
- returns:
y – Logarithm of the normal distribution at x
- rtype:
float
- pbjam.jar.smryStats(y)[source]¶
Computes summary statistics (median and uncertainty) for a given array of samples.
- Parameters:
y (array-like) – The input array of samples.
- Returns:
An array containing the median and the average absolute deviation.
- Return type:
ndarray
Notes
The function computes percentiles corresponding to the 16th, 50th, and 84th percentiles.
The uncertainty is the mean of the differences between the median and the 16th and 84th percentiles.
- pbjam.jar.to_log10(x, xerr)[source]¶
Transform to value to log10
Takes a value and related uncertainty and converts them to logscale.
Approximate.
- Parameters:
x (float) – Value to transform to logscale
xerr (float) – Value uncertainty
- Returns:
logval – logscaled value and uncertainty
- Return type:
list
- pbjam.jar.updatePrior(ID, R, addObs)[source]¶
Updates the prior data by adding a new entry based on the provided results and additional observations.
- Parameters:
ID (str) – The identifier for the new entry.
R (dict) – A dictionary containing the results. Keys should correspond to parameter names, and values are typically arrays or lists where the first element is used.
addObs (dict) – A dictionary containing additional observational data, such as ‘teff’ and ‘bp_rp’.
- Returns:
A pandas DataFrame containing the updated prior data.
- Return type:
DataFrame
Notes
The function reads the existing prior data from pbjam/data/prior_data.csv.
It filters out certain keys from the results that are not meant to be updated.
It applies a log10 transformation to certain parameters in the results before updating the prior data.
The new entry is then added to the prior DataFrame and returned.
- pbjam.jar.visell1(emm, inc)[source]¶
Computes the visibility for l=1 modes based on the azimuthal order (m) and inclination angle.
- Parameters:
emm (int) – Absolute value of the azimuthal order (m).
inc (float) – Inclination angle in radians.
- Returns:
Visibility for the l=1 modes.
- Return type:
float
- pbjam.jar.visell2(emm, inc)[source]¶
Computes the visibility for l=2 modes based on the azimuthal order (m) and inclination angle.
- Parameters:
emm (int) – Absolute value of the azimuthal order (m).
inc (float) – Inclination angle in radians.
- Returns:
Visibility for the l=2 modes.
- Return type:
float
- pbjam.jar.visell3(emm, inc)[source]¶
Computes the visibility for l=3 modes based on the azimuthal order (m) and inclination angle.
- Parameters:
emm (int) – Absolute value of the azimuthal order (m).
inc (float) – Inclination angle in radians.
- Returns:
Visibility for the l=3 modes.
- Return type:
float
- pbjam.jar.visibility(ell, m, inc)[source]¶
Computes the visibility of a mode based on its degree (l), azimuthal order (m), and inclination angle.
- Parameters:
ell (int) – The degree of the mode.
m (int) – The azimuthal order of the mode.
inc (float) – The inclination angle in radians.
- Returns:
Visibility for the given mode.
- Return type:
float