Gaussfit: Fit Gaussians to Absorption Features of a Normalized Spectrum

Description Usage Arguments Value Examples

View source: R/gaussfit.R

Description

This function takes a spectrum, which ideally is a high signal-to-noise template spectrum estimated with the estimate_template function, and the absorption features found with the findabsorptionfeatures function and uses nonlinear least-squares to fit Gaussians to the features. This follows the procedure described in Holzer et al. (2020).

Usage

1
Gaussfit(wvl, flx, ftrs, cores = 1, mse_max1 = 0.00014, mse_max2 = 1e-04)

Arguments

wvl

vector of wavelengths of the spectrum

flx

vector of normalized flux of the spectrum

ftrs

a list of length 2 vectors that each give the lower and upper bounds of found absorption features. The wvbounds component of the findabsorptionfeatures function output is designed to be this.

cores

the integer count of cores to parallelize over. If set to 1, no parallelization is done.

mse_max1

the maximum mean squared error required for a fit from one Gaussian to be considered a good fit for an absorption feature

mse_max2

the maximum mean squared error required for a fit of two Gaussians to be considered a good fit for an absorption feature

Value

a list with the following components:

parameters

a dataframe with the wavelength bounds, fitted amplitude, fitted center, fitted spread, and fit type for absorption features with a good fit. A fit type of 0 indicates that the feature had a good fit of a single Gaussian. A fit type of 1 indicates that the feature did not have a good fit with a single Gaussian initially, but after fitting with two it did.

fitted

the vector of fitted values (with the same length as the wvl parameter) using only the features that produced a good fit.

goodfits

a vector of the indices for which rows in the ftrs parameter were well fitted with either 1 or 2 Gaussians at the end

mse

a vector with the mean squared error for each of the features in the ftrs parameter using the final fitted values

Examples

1
2
3
4
5
6
7
8
data(template)
ftrs = findabsorptionfeatures(template$Wavelength,
                              template$Flux,
                              pix_range = 8, gamma = 0.05,
                              alpha = 0.07, minlinedepth = 0.015)
gapp = Gaussfit(template$Wavelength, template$Flux, ftrs)
plot(template$Wavelength, template$Flux)
lines(template$Wavelength, gapp$fitted, col=2)

rvmethod documentation built on Aug. 10, 2020, 5:07 p.m.