Specmatch¶

class
specmatchemp.specmatch.
SpecMatch
(target, lib=None, wavlim=(5000, 5900))¶ SpecMatch class to perform the SpecMatch routine.
Begin by using the shift() method to shift the target spectrum onto the library wavelength scale. This uses a bootstrapping approach to find the best reference spectrum to use as a template for shifting.
Next, the match() method runs a match against each library spectrum, computing a chisquared value for each targetlibrary pair.
Finally, use the lincomb() method to interpolate between the best library matches to obtain the final derived parameters, stored in the results dict.
Parameters:  target (spectrum.Spectrum) – Target spectrum and uncertainty
 lib (library.Library) – Library object to match against
 wavlim (tuple, optional) – Wavelength limits to perform matching on.

target
¶ spectrum.Spectrum – Target spectrum object

target_unshifted
¶ spectrum.Spectrum – An unshifted spectrum

shift_ref
¶ spectrum.Spectrum – Reference used to shift the spectrum

shift_results
¶ dict – Dictionary containing results from shifting.

regions
¶ list of tuples – List of wavelength regions used for matching.

match_results
¶ pd.DataFrame – Parameter table including chi_squared and fit_params from single match routine.

lincomb_matches
¶ list of match.MatchLincomb – MatchLincomb objects for final matching to a linear combination of spectra

lincomb_results
¶ list of dicts – Results from each MatchLincomb fit.

results
¶ dict – Dictionary of final stellar parameters produced by SpecMatch. These are derived by taking the average of the detrended parameters from each wavelength region. Keys are elements of library.STAR_PROPS.

lincomb
(num_best=5, regions='all')¶ Interpolate between library spectra to get more accurate parameters.
Takes the best num_best matches obtained in the match() step and creates linear combinations of their spectra. The respective coefficients for each spectrum will be used to take a weighted average of their parameters for use as the final derived parameters.
Parameters:  num_best (int, optional) – Specify the number of best matches to be used to synthesize the linear combinations.
 regions (list of tuples, optional) – Select wavelength regions to perform the matching procedure on. Defaults to ‘all’, which uses all the regions used in the previous match() step.

match
(wavlim=(5000, 5900), wavstep=100, ignore=None)¶ Match the target against the library spectra.
Performs a pairwise match between the target spectrum and every library spectra, fitting for vsini broadening and a spline to the continuum level. For each targetreference pair, a best chisquared value is calculated to assess the match between the two spectra.
The results are stored in
specmatchemp.SpecMatch.match_results
Parameters:  wavlim (tuple or list of tuples, optional) – Wavelength region(s) to use in matching process. Defaults to None  use the entire region overlapped by the target spectrum and library, split into sections specified by wavstep. If a tuple is given, it will be split into sections specified by wavstep. If a list of tuples is given, each tuple is a section to be used for matching.
 wavstep (float, optional) – Length of wavelength regions to be used. Defaults to 100 Angstrom regions. If None, uses the entire region specified in wavlims
 ignore (int, optional) – A library index to ignore. Useful for n1 library test.

plot_best_match_spectra
(region=0, wavlim='all', num_best=None)¶ Plots the reference, modified reference and residuals for each of the best matches.
Parameters:  region (int or tuple) – The region used in matching. If an int is given, refers to the index of the region in self.regions. If a tuple is given, should be present in self.regions.
 wavlim (str or tuple) – The wavelength limits to plot. If ‘all’ is given, plots the entire region.
 num_best (optional [int]) – Number of best spectra to highlight. (default: self.num_best)

plot_chi_squared_surface
(region=0, num_best=None)¶ Plot the chisquared surface from the pairwise matching procedure.
Creates a threecolumn plot of the best chisquared obtained with each library spectrum as a function of the library parameters.
Parameters:  region (int or tuple) – The wavelength region to plot. If an int is given, refers to the index of the region in self.regions. If a tuple is given, should be present in self.regions.
 num_best (optional [int]) – Number of best spectra to highlight. (default: self.num_best)

plot_lincomb
(region=0, wavlim='all')¶ Plots the spectra used to synthesize the linear combination, the synthesized spectrum, and residuals.

plot_references
(region=0, num_best=None, verbose=True)¶ Plots the location of the best references used in the linear combination step.
Parameters:  region (int or tuple) – The region used in matching. If an int is given, refers to the index of the region in self.regions. If a tuple is given, should be present in self.regions.
 num_best (optional [int]) – Number of best spectra to highlight. (default: self.num_best)
 verbose (optional [bool]) – Whether to annotate the points with the lincomb coefficients

plot_shift_lags
(orders='all', legend=True)¶ Plot the lags for each order as a function of pixel number.
Parameters: orders (str or int or list of ints) – ‘all’ (default): Plot all orders int: Plot only given order list of ints: Plot the orders provided.

plot_shifted_spectrum
(wavlim=(5158, 5172))¶ Plot a comparison of the shifted, reference and unshifted spectra.
Parameters: wavlim (tuple or list of tuples, optional) – Wavelength limits to plot.

plot_xcorr
(order=0, highlightpeak=False, legend=True)¶ Plot the correlation array for each section of the given order.
Parameters:  order (int) – Order on chip to plot. Defaults to 0.
 highlightpeak (bool) – Whether to highlight the peak value.

classmethod
read_hdf
(infile, lib)¶ Reads a SpecMatch object from and hdf file.
Parameters:  infile (str or h5 file) – Input path or file handle.
 lib (library.Library) – Library used to create SpecMatch object.

results_to_txt
(outfile, verbose=False)¶ Save final results to text.
Parameters:  outfile (str or file object) – Output file
 verbose (bool) – Whether to only print the final derived results or to also include notdetrended results and list of best matching spectra for each region

shift
()¶ Shift the target spectrum onto the library wavelength scale.
Uses the Mgb triplet region (5120  5200 A), a section of spectrum containing much information, to determine which spectrum to use as the reference for shifting. It does this by initially shifting the target spectrum in that region to the allowed references and comparing the heights of the crosscorrelation peaks. The reference with the highest median peak is used as the reference to shift the entire spectrum.
Returns:  The shifted spectrum, which is also stored in
 self.target
Return type: spectrum.Spectrum

to_fits
(outpath)¶ Saves the current state of the SpecMatch object to a fits file.
Parameters: outpath (str) – Path to store output file.

to_hdf
(outfile)¶ Saves the current state of the SpecMatch object to an hdf file.
Parameters: outfile (str or h5 file) – Output path or file handle.