breidablik.interpolate.spectra ============================== .. py:module:: breidablik.interpolate.spectra Attributes ---------- .. autoapisummary:: breidablik.interpolate.spectra._base_path Classes ------- .. autoapisummary:: breidablik.interpolate.spectra.Spectra Module Contents --------------- .. py:data:: _base_path .. py:class:: 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. .. py:attribute:: model_path .. py:attribute:: scalar_path .. py:attribute:: scalar .. py:attribute:: models .. py:attribute:: X .. py:attribute:: relative_error .. py:attribute:: save_num .. py:attribute:: cut_models :value: None .. py:method:: 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. :param wavelength: The wavelengths that correspond to the flux. Needs to be monotonically increasing. :type wavelength: List[Real] or 1darray :param flux: The flux that the abundance will be found for. Needs to be the same length as wavelength. :type flux: List[Real] or 1darray :param flux_err: The error in each flux point. Needs to be the same length as wavelength. :type flux_err: List[Real] or 1darray :param eff_t: The effective temperature of the star. :type eff_t: Real :param surf_g: The log surface gravity of the star. :type surf_g: Real :param met: The metallicity of the star. :type met: Real :param accuracy: The decimal place you want the result to be accurate to. :type accuracy: Real, optional :param method: The method of finding the abundance. Accepted methods are: 'bayes' and 'chisq'. :type method: str, optional :param min_abund: The minimum abundance that the algorithm should search to. :type min_abund: Real, optional :param max_abund: The maximum abundance that the algorithm should search to. :type max_abund: Real, optional :param initial_accuracy: 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. :type initial_accuracy: Real, optional :param abunds: 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'. :type abunds: List[Real], 1darray, optional :param prior: 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. :type prior: List[Real], 1darray, optional :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. :rtype: (float, list) .. py:method:: _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. .. py:method:: _coarse_search(wavelength, flux, flux_err, eff_t, surf_g, met, min_abund, max_abund, accuracy=0.0001, initial_accuracy=0.1) .. py:method:: _calc_bayes_err(abunds, probs) Find the best abundance through bayesian inference and also calculate the error associated with this measurement. .. py:method:: _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. .. py:method:: _p_model_given_data(xdata, ydata, sigma, prior, model) Bayesian inference - probability of data given model. The prior is for the input model. .. py:method:: _chisq(wavelength, flux, flux_err, abunds, eff_t, surf_g, met) Calculates the least squares of the input abundances. .. py:method:: predict_flux(eff_t, surf_g, met, abundance) Predicts the flux for the input stellar parameters and abundances. :param eff_t: The effective temperature of the star. :type eff_t: Real :param surf_g: The log surface gravity of the star. :type surf_g: Real :param met: The metallicity of the star. :type met: Real :param abundance: The lithium abundance of the star. :type abundance: Real :returns: **predicted** -- The predicted flux given the input stellar parameters and lithium abundance. :rtype: 1darray .. py:method:: _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. .. py:method:: _extrapolate(eff_t, surf_g, met, abundance, user_call=False) Give the flux for abundance < -0.5 .. py:method:: _interpolate(eff_t, surf_g, met, abundance, user_call=False) Give the flux for -0.5 <= abundance. .. py:method:: _phi(r) Phi function for distance transform .. py:method:: _dist(r1, r2) L2 distance metric