Shift¶
@filename shift.py
Shift a target spectrum onto a reference spectrum.
-
specmatchemp.shift.
bootstrap_shift
(targ, ref_list, store=None)¶ Shift a target spectrum using a bootstrapping approach.
First performs a cross-correlation of the target spectrum in a fixed wavelength region against each of the provided references. The reference spectrum which gives the highest median cross-correlation peak is used to shift the rest of the target spectrum.
Parameters: - targ (spectrum.Spectrum) – Target spectrum
- ref_list (list of spectrum.Spectrum) – List of reference spectra
- store (dict-like object, optional) – h5 file or dict to record diagnostic data.
Returns: Shifted and flattened spectrum.
Return type: shifted (Spectrum)
-
specmatchemp.shift.
correlate
(a, v, lowfilter=0)¶ Custom function to perform 1-dimensional cross-correlation
Parameters: - a (np.ndarray) – Input sequence
- v (np.ndarray) – Input sequence
- lowfilter (int) – Filter out components with wavelength above this number of pixels
Returns: Symmetric cross-correlation array
Return type: np.ndarray
-
specmatchemp.shift.
flatten
(w, s, serr=None, mask=None, w_ref=None, wavlim=None)¶ Flattens a given 2-D spectrum into a 1-D array. Merges overlapped points by taking the mean. If w_ref is given, fills values that don’t occur in the 2D spectrum with np.nan
Parameters: - w (np.ndarray) – Wavelength array
- s (np.ndarray) – Spectrum
- serr (np.ndarray, optional) – Uncertainty in spectrum
- mask (np.ndarray, optional) – Boolean mask
- w_ref (np.nadarray, optional) – Reference, 1-D wavelength array
- wavlim (2-element iterable, optional) – Wavelength limits
Returns: Wavelength, spectrum and uncertainty in spectrum
Return type:
-
specmatchemp.shift.
rescale_w
(s, serr, w, m, w_ref)¶ Place the given spectrum on the wavelength scale specified by w_ref
Parameters: - serr, w (s,) – The spectrum and original wavelength scale.
- w_ref – The desired wavelength scale
Returns: The spectrum and associated error on the desired scale.
-
specmatchemp.shift.
save_shift_to_fits
(outpath, shifted, unshifted, shift_data, clobber=False)¶ Saves the complete shift data to a FITS file.
Parameters: - outpath (str) – Path to save output file
- shifted (Spectrum) – Shifted spectrum
- unshifted (HiresSpectrum) – Raw spectrum
- shift_data (dict) – Shift data
- clobber (bool) – Overwrite existing file at destination
-
specmatchemp.shift.
shift
(targ, ref, store=None, lowfilter=20)¶ Shifts the given spectrum by placing it on the same wavelength scale as the specified reference spectrum, then solves for shifts between the two spectra through cross-correlation.
Parameters: Returns: Adjusted and flattened spectrum
Return type: shifted (Spectrum)
-
specmatchemp.shift.
shift_data_to_hdu
(shift_data)¶ Saves the shift data to a BinTableHDU.
Parameters: shift_data (dict) – Shift data output from shift()
-
specmatchemp.shift.
solve_for_shifts
(s, mask, s_ref, mask_ref, lowfilter=20)¶ Solve for the pixel shifts required to align two spectra that are on the same wavelength scale.
Correlates the two spectra, then fits a quadratic to the peak in order to solve for sub-pixel shifts.
Parameters: - s – The target spectrum array
- mask – Mask array for the target spectrum
- s_ref – The reference spectrum
- mask_ref – Mask array for the reference spectrum
Returns: The pixel shift, the lag and correlation data