Spectrum

class Data_Reduction.Spectrum

Bases: Data_Reduction.Observation

Class for spectra

Methods Summary

freq_to_chan(bandwidth, n_chans)

Returns the channel number where a given frequency is to be found.

get_freq_array(bandwidth, n_chans)

Create an array of frequencies for the channels of a backend

get_num_chans(linefreq, bandwidth, max_vel_width)

compute the base 2 number of output channels for the specified resolution

get_smoothed_bandshape([degree, poly_order])

Do a Gaussian smoothing of the spectrum and then fit a polynomial.

reduce_spectrum_channels(refval, refpix, delta)

Reduce the number of channels in the spectrum.

Methods Documentation

freq_to_chan(bandwidth, n_chans)

Returns the channel number where a given frequency is to be found.

:param frequency : frequency of channel in sane units as bandwidth. :type frequency : float

:param bandwidth : upper limit of spectrometer passband :type bandwidth : float

:param n_chans : number of channels in the spectrometer :type n_chans : int

Returns

channel number (int)

get_freq_array(bandwidth, n_chans)

Create an array of frequencies for the channels of a backend

:param bandwidth : bandwidth :type bandwidth : float

:param n_chans : number of channels :type n_chans : int

Returns

frequency of each channel in same units as bandwidth

get_num_chans(linefreq, bandwidth, max_vel_width)

compute the base 2 number of output channels for the specified resolution

get_smoothed_bandshape(degree=None, poly_order=15)

Do a Gaussian smoothing of the spectrum and then fit a polynomial. Optionally, the raw and smoothed data and the fitted polynomial can be plotted.

Note

numpy.polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False) Least squares polynomial fit. Fit a polynomial:

p(x) = p[0] * x**deg + ... + p[deg]

of degree deg to points (x, y). Returns a vector of coefficients p that minimises the squared error.

:param spectrum : input data :type spectrum : list of float

:param degree : number of samples to smoothed (Gaussian FWHM) :type degree : int

:param poly_order : order of the polynomial :type poly_order : int

:param plot : plotting option :type plot : boolean

return

(polynomial_coefficient, smoothed_spectrum)

reduce_spectrum_channels(refval, refpix, delta, num_chan=1024, axis=0)

Reduce the number of channels in the spectrum.

The default option is to reduce the spectrum to a specified number of channels with a default of 1024. The input spectrum is presumed to have 2**N channels so that num_chan/num_chan_in is an integer.

If ‘spectrum’ is an N-D array, then the spectrum axis is given by ‘axis’ which defaults to 0.

‘delta’ is negative for lower sideband or reversed double sideband spectra.

:param spectrum : spectrum values :type spectrum : list or nparray

:param refval : X-axis value at the reference pixel of ‘spectrum’ :type refval : float

:param refpix : reference pixel for ‘spectrum’ :type refpix : int

:param delta : interval between pixels on the X-axis :type delta : float

:param num_chan : optional number of channels to be returned (default: 2^10) :type num_chan : int

Returns

numpy.array