breidablik.interpolate.spectra
Attributes
Classes
Interpolation class for spectra. Used to interpolate between the stellar parameters. Can find the abundance of an input flux given the stellar parameters. Can also predict a flux from the stellar parameters and abundance. |
Module Contents
- breidablik.interpolate.spectra._base_path
- class breidablik.interpolate.spectra.Spectra(model_path=None, scalar_path=None, save_num=1)
Interpolation class for spectra. Used to interpolate between the stellar parameters. Can find the abundance of an input flux given the stellar parameters. Can also predict a flux from the stellar parameters and abundance.
- model_path
- scalar_path
- scalar
- models
- X
- relative_error
- save_num
- cut_models = None
- find_abund(wavelength, flux, flux_err, eff_t, surf_g, met, accuracy=0.0001, method='bayes', min_abund=-0.5, max_abund=4, initial_accuracy=0.1, abunds=None, prior=None)
Finds the abundance of the spectrum.
- Parameters:
wavelength (List[Real] or 1darray) – The wavelengths that correspond to the flux. Needs to be monotonically increasing.
flux (List[Real] or 1darray) – The flux that the abundance will be found for. Needs to be the same length as wavelength.
flux_err (List[Real] or 1darray) – The error in each flux point. Needs to be the same length as wavelength.
eff_t (Real) – The effective temperature of the star.
surf_g (Real) – The log surface gravity of the star.
met (Real) – The metallicity of the star.
accuracy (Real, optional) – The decimal place you want the result to be accurate to.
method (str, optional) – The method of finding the abundance. Accepted methods are: ‘bayes’ and ‘chisq’.
min_abund (Real, optional) – The minimum abundance that the algorithm should search to.
max_abund (Real, optional) – The maximum abundance that the algorithm should search to.
initial_accuracy (Real, optional) – The initial accuracy that the algorithm starts searching through. If ‘bayes’ is returning warnings try decreasing the initial accuracy. Note that this does make the algorithm run slower.
abunds (List[Real], 1darray, optional) – Determine the abundances you want the probability caculated over. Overrides the min_abund and max_abund parameters. This parameter is ignored if prior is not set. Only used if method is ‘bayes’.
prior (List[Real], 1darray, optional) – Set the prior to the abundances specified via abunds. This parameter is ignored if abunds is not set. Only used if method is ‘bayes’. If method is ‘bayes’ but no prior is set, uses uniform prior + gaussian with sigma=1 below -0.5. Needs to be the same length as abunds.
- Returns:
(abundance, error) – The abundance that matches best with the input flux and the error value associated with the abundance. The error list has 2 values, left is the negative error, right is the positive error. The error can be None if the method is ‘chisq’ or if abunds and prior were given but error cannot be calculated.
- Return type:
(float, list)
- _window_search(wavelength, flux, flux_err, eff_t, surf_g, met, accuracy=0.0001, min_abund=-0.5, max_abund=4, initial_accuracy=0.1)
An algorithm that finds the minimum - variation of ternary search. Used to make finding the abundances faster. Only for chisq method.
- _coarse_search(wavelength, flux, flux_err, eff_t, surf_g, met, min_abund, max_abund, accuracy=0.0001, initial_accuracy=0.1)
- _calc_bayes_err(abunds, probs)
Find the best abundance through bayesian inference and also calculate the error associated with this measurement.
- _bayesian_inference(wavelength, flux, flux_err, eff_t, surf_g, met, abunds, prior=None)
Use Bayesian optimisation to find the probability of the model (abundance) given data.
- _p_model_given_data(xdata, ydata, sigma, prior, model)
Bayesian inference - probability of data given model. The prior is for the input model.
- _chisq(wavelength, flux, flux_err, abunds, eff_t, surf_g, met)
Calculates the least squares of the input abundances.
- predict_flux(eff_t, surf_g, met, abundance)
Predicts the flux for the input stellar parameters and abundances.
- Parameters:
eff_t (Real) – The effective temperature of the star.
surf_g (Real) – The log surface gravity of the star.
met (Real) – The metallicity of the star.
abundance (Real) – The lithium abundance of the star.
- Returns:
predicted – The predicted flux given the input stellar parameters and lithium abundance.
- Return type:
1darray
- _predict_flux(eff_t, surf_g, met, abundance, user_call=False)
Same as predict_flux. This is the hidden version without asserts for improved performance. The flux is only predicted in the region of the cut_models (where cut_models are determined by the input observed spectrum).
Also, you can call this version with a list of abundances. It’s faster if you call this function with a list of abundances vs calling the user visible one with a for-loop over abundances. Vroom vroom.
user_call : If the user calls this function, it will always predict the full spectrum, instead of using the cut section.
- _extrapolate(eff_t, surf_g, met, abundance, user_call=False)
Give the flux for abundance < -0.5
- _interpolate(eff_t, surf_g, met, abundance, user_call=False)
Give the flux for -0.5 <= abundance.
- _phi(r)
Phi function for distance transform
- _dist(r1, r2)
L2 distance metric