API for TelluricFitter¶

class
TelluricFitter.
TelluricFitter
(debug=False, debug_level=2)¶ 
AdjustValue
(vardict)¶ Adjust the value of a constant parameter. This is useful for something like setting the pressure or the telescope zenith distance, which will be known very well and is important to getting a good fit, but does not need to be varied.
Warning: The variable will be removed from the list of variables to fit, so DO NOT use this to adjust the value of a parameter you want TelFit to adjust!
Parameters: vardict – a dictionary where the key is the parameter name and the value is the value of that parameter. Valid parameter names can be found by invoking DisplayVariables(fitonly=False) Returns: None

DisplayVariables
(fitonly=False)¶ Display the value of each of the parameters, and show whether it is being fit or not
Parameters: fitonly – bool variable. If true, it only shows the variables being fit. Otherwise, it shows all variables. Returns: None

EditAtmosphereProfile
(profilename, profile_height, profile_value)¶ Edits the atmosphere profile for a given parameter. This is just a wrapper for the MakeModel.Modeler method, but the docstring is replicated below:
Parameters:  profilename – A string with the name of the profile to edit. Should be either ‘pressure’, ‘temperature’, or one of the molecules given in the MakeModel.MoleculeNumbers dictionary
 profile_height – A np array with the height in the atmosphere (in km)
 profile_value – A np array with the value of the profile parameter at each height given in profile_height.
Returns: None

Fit
(data=None, resolution_fit_mode='gauss', fit_primary=False, return_resolution=False, adjust_wave='model', continuum_fit_order=7, wavelength_fit_order=3, air_wave=True, fit_source=False, source_fcn=None, source_args=None, source_kwargs=None)¶ The main fitting function. Before calling this, the user MUST
1 call FitVariable at least once, specifying which variables will be fit 2 Set resolution bounds (any other bounds are optional)Parameters:  data – If given, this should be a DataStructures.xypoint instance giving the data you wish to fit. The units of the .x attribute MUST be nanometers!
 resolution_fit_mode – controls which function is used to estimate the resolution. “SVD” is for singlular value decomposition, while “gauss” is for convolving with a gaussian (and fitting the width of the guassian to give the best fit). I have found the ‘gauss’ is best when the telluric lines are pretty weak, such as in much of the optical spectrum. For strong telluric lines, SVD is both faster and more accurate.
 fit_primary – Deprecated. See fit_source
 return_resolution – controls whether the bestfit resolution is returned to the user. One case I have used this for is to fit echelle data of latetype stars by getting all the bestfit parameters from redder orders, and then applying those atmospheric parameters to the rest of the orders.
 adjust_wave – Can be set to either ‘data’ or ‘model’. To wavelength calibrate the data to the telluric lines, set to ‘data’. If you think the wavelength calibration is good on the data (such as ThAr lines in the optical), then set to ‘model’ Note that currently, the vacuum –> air conversion for the telluric model is done in a very approximate sense, so adjusting the data wavelengths may introduce a small (few km/s) offset from what it should be. That is fine for relative RVs, but probably not for absolute RVs.
 continuum_fit_order – The polynomial order with which to fit the continuum. It uses a sigmaclipping algorithm so that the continuum is not strongly affected by stellar lines (either absorption or emission)
 wavelength_fit_order – The polynomial order with which to adjust the wavelength fit. Note that the ‘adjust_wave’ input will determine whether the data or the telluric model is wavelengthadjusted.
 air_wave – Are the wavelengths in air wavelengths? Default is True.
 fit_source – determines whether an attempt to fit the source spectrum (the spectrum of the object you are fitting, not the telluric lines) is made. If true, this function returns both the bestfit model and the source estimate. By default, it fits the source spectrum with a simple smoothing kernel that works well for rapidly rotating stars. However, you can give a custom source fitting function with the ‘source_fcn’ keyword.
 source_fcn – A function that takes a DataStructures.xypoint instance and any number of arguments/keyword arguments after it. This function should expect a spectrum of the source (without telluric lines) and attempt to fit it. Warning: This function will be called in every iteration, so do not use a function that takes more than ~1 second, or the telluric fit will slow down considerably!
 source_args – A list of arguments to give to the source function.
 source_kwargs – A dictionary of keyword arguments to give to the source function.
Returns: The bestfit telluric model, as a DataStructures.xypoint instance where the xaxis is sampled the same as the data (so you should be able to directly divide the two). If fit_source = True, this method also returns the estimate for the source spectrum before the telluric model. If return_resolution is True, it also returns a float with the best resolution fit. The return order is: source_spec, model_spec, resolution

FitVariable
(vardict)¶ Add one or more variables to the list being fit.
Parameters: vardict – a dictionary where the key is the parameter name and the value is the initial guess for that parameter. Valid parameter names can be found by invoking DisplayVariables(fitonly=False) Returns: None

GenerateModel
(pars, nofit=False, separate_source=False, return_resolution=False, broaden=False, model=None)¶ This function does the actual work of generating a model with the given parameters, fitting the continuum, making sure the model and data are well aligned in wavelength, and fitting the detector resolution. In general, it is not meant to be called directly by the user. However, the ‘nofit’ keyword turns this into a wrapper to MakeModel.Modeler().MakeModel() with all the appropriate parameters.
Parameters:  pars – A list of the parameters currently being fit (as given in self.FitVariable).
 nofit – If true, it will not perform a fit to the data and simply return the model.
 separate_source – If true, it will fit the source spectrum as a smoothed version of the residuals. Useful for spectra with broad lines.
 return_resolution – If true, it will return the bestfit resolution.
 broaden – If true and nofit=True, it will broaden the returned model by the expected detector resolution. Ignored if nofit=False
 model – A DataStructures.xypoint instance containing an unbroadened telluric model. If given, it uses this instead of making one.
Returns: The bestfit telluric model, as a DataStructures.xypoint instance where the xaxis is sampled the same as the data (so you should be able to directly divide the two). If separate_source = True, this method also returns the estimate for the source spectrum before the telluric model. If return_resolution is True, it also returns a float with the best resolution fit. The return order is: source_spec, model_spec, resolution

GetValue
(variable)¶ Returns the value of the variable given. Useful to get the fitted value of the parameters

IgnoreRegions
(region)¶  Tells the fitter to ignore certain regions of the spectrum
 in the chisquared calculation. Useful for stellar or interstellar lines.
Parameters: region – Can be either a list of size 2 with the beginning and ending wavelength range to ignore, or a list of lists giving several wavelength ranges at once.

ImportData
(data)¶  Function for the user to give the data. The data should be in the form of
 a DataStructures.xypoint structure, and the xunits must either be an instance of astropy.quantities.Quantity or in nanometers.

SetBounds
(bounddict)¶ Set bounds on one or more parameters.
Parameters: vardict – a dictionary where the key is the parameter name and the value is a list of size 2 containing the lower and upper bounds. You can provide onesided bounds using np.inf or np.inf. Valid parameter names can be found by invoking DisplayVariables(fitonly=False) Returns: None

SetObservatory
(observatory)¶  Set the observatory. Can either give a dictionary with the latitude and altitude,
 or give the name of the observatory. Some names are hardcoded in here.

__init__
(debug=False, debug_level=2)¶ Initialize the TelluricFitter class.
Parameters:  debug – Flag to print a bunch of messages to screen for debugging purposes
 debug_level – An integer from 15 that controls how much gets printed. 1 is the least and 5 is the most.
Returns: An instance of TelluricFitter.
