Module documentation
Take an input wavelength and flux. Ask the user to choose the regions to clip. Define a region in which to perform fiting. By default 100 Å either side of users emission line choice. Compute spline fit using data in the fitting region.s Produce the residual spectrum between the spline and the original spectrum in the fitting region. Compute the mean and variance of the residual spectrum. Sample from a Gaussian distribution with this mean and std dev to create the noise for the selected region. Add noise to the spline in the selected region. Replace the input spectrm in the selected region with the new spectrum.
- emclip.click_regions(event, fig, ax, emlines)
Plots a vertical line at the location of the user’s click. Appends the wavelength of this line to the emlines list.
- Parameters:
event (matplotlib.backend_bases.MouseEvent) – Mouse click event.
fig (matplotlib.figure.Figure) – matplotlib figure on which to draw the lines.
ax (matplotlib.Axes) – matplotlib axis accompanying the matplotlib figure.
emlines (list) – List of emline locations, which will be added to each time this function is used.
- emclip.clip_line(wlen, flux, line_lower, line_upper, emline_list, verbose=False, path=None)
Zoom in to DELTA angstroms either side of the supplied emission line boundaries. Set the region between the bounding lines to NaN. Check whether there are other lines present in the region bounded by bounding lines +/- delta. If there are, set them to NaN. Remove the NaNs with a mask. Fit a cubic spline to the zoomed in, masked flux array. Compute the residuals between the data and the spline fit. Compute the mean and std dev of the residual distribution. Use the mean and std dev of the distribution to generate a noisy spectrum using the spline fit in the region of the emission line. Plot and save figures if verbose==True. Return the new section of flux in the region of the emission line.
- Parameters:
wlen (numpy.ndarray) – Wavelength array. Taken from the input spectrum.
flux (numpy.ndarray) – Flux array. Taken from the input spectrum.
line_lower (float) – The lower wavelength of the line to be removed.
(float) (line_upper) – The upper wavelength of the line to be removed.
emline_list (list) – Full list of emline bounding lines.
verbose (bool, optional) – Flag indicating whether to save a figure of the spectrum near each emission line removal. Defaults to False.
path (str, optional) – Output path for figures. Defaults to None.
- Returns:
The corrected spectrum in the zoomed region around the emission line.
- Return type:
numpy.ndarray
- emclip.clip_lines(wlen, flux, emline_list, *args, **kwargs)
Iterate over the list of emission lines. Call clip_line to remove them. Use the result of clip line to update the flux_clipd vector. Return the clipped spectrum.
- Parameters:
wlen (numpy.ndarray) – Wavelength array. Taken from the input spectrum.
flux – Flux array. Taken from the input spectrum.
emline_list (list) – Full list of emline bounding lines.
- Return flux_clipd:
An array containing the spectrum with emission lines removed.
- Return type:
numpy.ndarray
- emclip.define_regions(wlen, flux)
Creates the plot where the user can double click to set the bounding regions of emission lines.
- Parameters:
wlen (numpy.ndarray) – Wavelength array.
flux (numpy.ndarray) – Flux array.
- Returns:
List of emission line bounding wavelengths.
- Return type:
list
- emclip.find_adjacent_emlines(emline_list, line_lower, line_upper, wlen_zoom, flux_zoom_nan)
Find out if there are other emlines near the emline which is being removed. If there are then set their values to NaN so that they do not affect the fit for the emline in question (mean, stddev etc.).
- Parameters:
emline_list (list) – Full list of emline bounding lines.
line_lower (float) – The lower wavelength of the line to be removed.
line_upper (float) – The upper wavelength of the line to be removed.
wlen_zoom (numpy.ndarray) – An wavelength array 100 Åeither side of the emission line being removed.
flux_zoom_nan (numpy.ndarray) – Spectral flux array corresponding to the wavelengths in wlen_zoom.
- Returns:
An array of fluxes within 100 Åof the emission line in question, where fluxes of other emission lines are set to NaN so they do not impact removal of the line in question.
- Return type:
numpy.ndarray