EDIBLES Reference¶
Subpackages¶
- edibles.data package
- edibles.utils package
- edibles.utils.VoigtClass module
- edibles.utils.atomic_line_tool module
- edibles.utils.edibles_oracle module
- edibles.utils.edibles_spectrum module
- edibles.utils.file_search module
- edibles.utils.functions module
- edibles.utils.local_continuum_spline module
- edibles.utils.voigt module
- edibles.utils.voigt_profile module
edibles.models module¶
-
class
edibles.models.ContinuumModel(n_anchors, independent_vars=['x'], prefix='', nan_policy='raise', verbose=0, **kwargs)[source]¶ Bases:
lmfit.model.ModelA model that puts a cubic spline through a small number (max 10) of evenly spaced anchor points, specified by
n_anchors. Only the y value of the anchor points is fit.Parameters: - n_anchors (int) – number of anchor points to fit spline through.
- independent_vars – [‘x’] Arguments to func that are independent variables.
- prefix (str) – optional, String to prepend to parameter names, needed to add two Models that have parameter names in common.
- nan_policy (str) – optional, How to handle NaN and missing values in data. Must be one of: ‘raise’ (default), ‘propagate’, or ‘omit’. See Notes below.
- **kwargs – optional, Keyword arguments to pass to
Model.
Notes
1. nan_policy sets what to do when a NaN or missing value is seen in the data. Should be one of: - ‘raise’ : Raise a ValueError (default) - ‘propagate’ : do nothing - ‘omit’ : drop missing data
-
class
edibles.models.VoigtModel(independent_vars=['x'], prefix='', nan_policy='raise', **kwargs)[source]¶ Bases:
lmfit.model.ModelA model of the astronomical Voigt function.
-
edibles.models.guess_voigt(model, data, x)[source]¶ Estimate parameters of voigtAbsorptionLine, create params
Parameters: - model – VoigtModel
- data – flux data
- x – wavelength data
Returns: Guessed parameters of voigt line
Return type: lmfit.Parameters
- TODO: This function could be extended in the future to guess peak
- parameters of multiple types of models.
edibles.sightline module¶
-
class
edibles.sightline.Sightline(Spectrum, init_cont=True, n_anchors=4)[source]¶ Bases:
objectA model of the sightline between the telescope and the target star.
Parameters: - Spectrum (EdiblesSpectrum) – The input spectrum object
- n_anchors (int) – Optional, The number of anchors in the ContinuumSpline
-
add_line(name, source=None, pars=None, guess_data=None)[source]¶ Adds a new line to a given absorption source. If no source is given, a new one will be created.
Parameters: - name (str) – The name of the line
- source (str) – the name of the source this line will belong to
- pars (dict) – user input parameters
- guess_data (1darray) – flux data to guess with
-
add_source(name, similar=None)[source]¶ Adds a new source of absorption to the sightline.
- The purpose of a source is to hold multiple line models
- together, sometiimes with similar parameters
Parameters: - name (str) – The name of the absorption source
- similar (dict) – A dict of parameters that change with the source, not the specific line, default: None, example: similar={‘b’: 3}
-
fit(data=None, old=False, x=None, report=False, plot=False, weights=None, method='leastsq', **kwargs)[source]¶ Fits a model to the sightline data given by the EdiblesSpectrum object.
Parameters: - data (1darray) – Flux data to fit
- params (lmfit.parameter.Parameters) – Initial parameters to fit
- model (lmfit.model.CompositeModel) – The model to fit, default: self.complete_model
- x (1darray) – Wavelength data to fit
- report (bool) – default False: If true, prints the report from the fit.
- plot (bool) – default False: If true, plots the data and the fit model.
- method (str) – The method of fitting. default: leastsq
-
freeze(pars=None, prefix=None, freeze_cont=True, unfreeze=False)[source]¶ - Freezes the current params, so you can still add to the
- model but the ‘old’ parameters will not change
Parameters: - prefix (str) – Prefix of parameters to freeze, default: None, example: ‘Telluric’
- freeze_cont (bool) – Freeze the continuum or not, default: True
- unfreeze (bool) – unfreezes all parameters except x values of spline anchors, default=False
-
separate(data, x, old=False, plot=True)[source]¶ Separate the sources that were added to Sightline.
Parameters: - data (1darray) – FLux data to use for separation
- x (1darray) – Wavelength array to use
- old (bool) – If true, uses the older, second-most recent model and parameters
- plot (bool) – If true, plots separted spectrum
edibles.continuum module¶
The Continuum class is a tool that was developed for creating continuum models, and saving and accessing continuum data in the form of csv files.
Note
The only method available currently is a spline fit through the spectrum to a number of anchor points.
Warning
Continuum.add_to_csv() saves the data LOCALLY in the ediblesdr4 GitHub repository. For any saved data to be reflected online, you must push your changes manually.
Example:
# Create the spectrun using EdiblesSpectrum
sp = EdiblesSpectrum("/HD23466/BLUE_346/HD23466_w346_blue_20180731_O11.fits")
sp.getSpectrum(xmin=3270, xmax=3305)
# build a 4 anchor points spline
cont = Continuum(sp, method="spline", n_anchors=4, plot=False, verbose=2)
# Guess the model parameters
params = cont.model.guess(sp.flux, x=sp.wave)
# Fit the model
result = cont.model.fit(data=sp.flux, params=params, x=sp.wave)
# Get the output of the fit model
out = result.eval(params=result.params, x=sp.wave)
# Print the result parameters
print(result.params)
# Plot
plt.plot(sp.wave, sp.flux)
plt.plot(sp.wave, out)
plt.show()
# Add the model parameters to a csv file
cont.add_to_csv(
user="Mario", comments="Test of 4 anchor points spline"
)
# reinitialize the edibles spectrum class, to get the continuum_filename in it
cont = Continuum(sp)
cont.prebuilt_model(chosen_save_num=None, plot=True, verbose=1)
-
class
edibles.continuum.Continuum(Spectrum, method='None', plot=False, verbose=0, *args, **kwargs)[source]¶ Bases:
objectA class that has multiple methods for fitting different types of continua.
Parameters: - Spectrum (EdiblesSpectrum) – The input EiblesSpectrum data
- method (str) – The method of fitting
- plot (bool) – If true, plots the continuum fit
- verbose (int) – If > 0, display more status messages
-
add_to_csv(user, comments)[source]¶ A function that saves the continuum model parameters to a csv file.
Each save appears as follows:
####### method=spline# n_anchors=4# datetime=2020-10-06 10:56:02.192865# user=First Last# comments=This is a comment.x1, x2, x3, x4y1, y2, y3, y4Parameters: - user (str) – The name of the person adding the data
- comments (str) – Any comments the user wishes to make about the data to be saved
Note
The data is saved to the ediblesdr4 github repository, with the same filepath as the original FITS file.
-
alphashape()[source]¶ A function that uses alphashape to find a continuum.
Note
Currently not implemented
-
polynomial()[source]¶ A function that uses a polynomial to find a continuum.
Note
Currently not implemented
-
prebuilt_model(chosen_save_num=None, plot=False, verbose=0)[source]¶ A function that generates continua based on data saved in csv files.
Parameters: - chosen_save_num (int) – The ‘save number’ of the continuum data, default=None. If None, the function will create all saved models and (possibly) plot them.
- plot (bool) – If True, plot the model(s) once it is created
- verbose (int) – If > 0, print more information about the data