Instrumental (Gaussian kernel) broadening

PyAstronomy.pyasl.broadGaussFast(x, y, sigma, edgeHandling=None, maxsig=None)

Apply Gaussian broadening.

This function broadens the given data using a Gaussian kernel.

Parameters
x, yarrays

The abscissa and ordinate of the data.

sigmafloat

The width (i.e., standard deviation) of the Gaussian profile used in the convolution.

edgeHandlingstring, {None, “firstlast”}, optional

Determines the way edges will be handled. If None, nothing will be done about it. If set to “firstlast”, the spectrum will be extended by using the first and last value at the start or end. Note that this is not necessarily appropriate. The default is None.

maxsigfloat, optional

The extent of the broadening kernel in terms of standard deviations. By default, the Gaussian broadening kernel will be extended over the entire given spectrum, which can cause slow evaluation in the case of large spectra. A reasonable choice could, e.g., be five.

Returns
Broadened dataarray

The input data convolved with the Gaussian kernel.

PyAstronomy.pyasl.instrBroadGaussFast(wvl, flux, resolution, edgeHandling=None, fullout=False, maxsig=None, equid=False)

Apply Gaussian instrumental broadening.

This function broadens a spectrum assuming a Gaussian kernel. The width of the kernel is determined by the resolution. In particular, the function will determine the mean wavelength and set the Full Width at Half Maximum (FWHM) of the Gaussian to (mean wavelength)/resolution.

Parameters
wvlarray

The wavelength

fluxarray

The spectrum

resolutionint

The spectral resolution.

edgeHandlingstring, {None, “firstlast”}, optional

Determines the way edges will be handled. If None, nothing will be done about it. If set to “firstlast”, the spectrum will be extended by using the first and last value at the start or end. Note that this is not necessarily appropriate. The default is None.

fulloutboolean, optional

If True, also the FWHM of the Gaussian will be returned.

maxsigfloat, optional

The extent of the broadening kernel in terms of standard deviations. By default, the Gaussian broadening kernel will be extended over the entire given spectrum, which can cause slow evaluation in the case of large spectra. A reasonable choice could, e.g., be five.

equidboolean, optional

If True, linear interpolation will be used to obtain an intermediate spectrum with uniformly sampled wavelength grid to carry out the broadening.

Returns
Broadened spectrumarray

The input spectrum convolved with a Gaussian kernel.

FWHMfloat, optional

The Full Width at Half Maximum (FWHM) of the used Gaussian kernel.

Example of usage

from __future__ import print_function, division
from PyAstronomy import pyasl
import matplotlib.pylab as plt
import numpy as np

# Set up an input spectrum
x = np.linspace(5000.0, 5100.0, 1000)
y = np.ones(x.size)

# Introduce some delta-peaked lines
y[165] = 0.7
y[187] = 0.3
y[505] = 0.1
y[610] = 0.1
y[615] = 0.7

# Apply Gaussian instrumental broadening, setting the resolution to 10000.
r, fwhm = pyasl.instrBroadGaussFast(x, y, 10000,
                                    edgeHandling="firstlast", fullout=True)

# Apply Gaussian instrumental broadening, setting the resolution to 10000.
# Limit the extent of the Gaussian broadening kernel to five standard
# deviations.
r2, fwhm = pyasl.instrBroadGaussFast(x, y, 10000,
                                     edgeHandling="firstlast", fullout=True, maxsig=5.0)

print("FWHM used for the Gaussian kernel: ", fwhm, " A")

# Plot the output
plt.plot(x, r, 'r--p', label="Broadened curve (full)")
plt.plot(x, r2, 'k:', label="Broadened curve (5 stds)")
plt.plot(x, y, 'b-', label="Input")
plt.legend(loc=4)
plt.show()