Match

class specmatchemp.match.Match(target, reference, mode='default', opt='nelder')

The Match class used for matching two spectra

target

Spectrum – Target spectrum

reference

Spectrum – Reference spectrum

modified

Spectrum – Modified reference, after broadening and fitting a spline to correct for continuum differences

spl

np.ndarray – Spline used to fit continuum level

best_params

lmfit.Parameters – Parameters used to create the best match.

best_chisq

float – Chi-squared from the best match

Parameters:
  • target (Spectrum) – Target spectrum
  • reference (Spectrum) – Reference spectrum
  • mode – default (unnormalized chi-square), normalized (normalized chi-square)
  • opt – lm (Levenberg-Marquadt optimization), nelder (Nelder-Mead)
best_fit(params=None)

Calculates the best fit model by minimizing over the parameters: - spline fitting to the continuum - rotational broadening

best_residuals()

Returns the residuals between the target spectrum and best-fit spectrum.

Returns:np.ndarray
broaden(vsini, spec)

Applies a broadening kernel to the given spectrum (or error)

Parameters:
  • vsini (float) – vsini to determine width of broadening
  • spec (Spectrum) – spectrum to broaden
Returns:

Broadened spectrum

Return type:

broadened (Spectrum)

create_model(params)

Creates a tweaked model based on the parameters passed, based on the reference spectrum. Stores the tweaked model in spectra.s_mod and serr_mod.

get_spline_positions()

Wrapper function for getting spline positions

Returns:knotx (np.ndarray)
load_params(params)

Method to create a model based on pre-determined parameters, storing it as the best fit model.

objective(params)

Objective function evaluating goodness of fit given the passed parameters.

Parameters:params
Returns:Reduced chi-squared value between the target spectra and the model spectrum generated by the parameters
classmethod read_hdf(infile)

Reads the Match object from an HDF file.

Parameters:infile (str or h5 file) – Input path or file handle.
to_hdf(outfile)

Saves the Match object to an hdf file.

Parameters:outfile (str or h5 file) – Output path or file handle.
class specmatchemp.match.MatchLincomb(target, refs, vsini, mode='default', ref_chisq=None)

MatchLincomb class used to match a linear combination of spectra to match a target spectrum.

target

Spectrum – Target spectrum

refs

list of Spectrum – List of reference spectra

vsini

np.ndarray – Array of vsini used to broaden the reference spectra.

spl

np.ndarray – Spline used for continuum fitting.

modified

Spectrum – Best linear combination of spectra.

best_params

lmfit.Parameters – Parameters used to create the best match.

best_chisq

floatt – Chi-squared from the best match.

Parameters:
  • target (Spectrum) – Target spectrum
  • refs (list of Spectrum) – Array of reference spectra
  • vsini (np.ndarray) – array containing vsini broadening for each reference spectrum
best_fit()

Calculates the best fit model by minimizing over the parameters: - Coefficients of reference spectra - spline fitting to the continuum - rotational broadening

create_model(params)

Creates a tweaked model based on the parameters passed, based on the reference spectrum. Stores the tweaked model in spectra.s_mod and serr_mod.

get_lincomb_coeffs()

Wrapper function to get lincomb coefficients from MatchLincomb object

Returns:coeffs (np.ndarray)
get_vsini()

Wrapper function to get vsini list from MatchLincomb object

Returns:vsini (np.ndarray)
objective(params)

Objective function evaluating goodness of fit given the passed parameters.

Parameters:params
Returns:Reduced chi-squared value between the target spectra and the model spectrum generated by the parameters
classmethod read_hdf(infile)

Reads the Match object from an HDF file.

Parameters:infile (str or h5 file) – Input path or file handle.
to_hdf(outfile)

Saves the Match object to an hdf file.

Parameters:outfile (str or h5 file) – Output path or file handle.