Useful math functions for LWA work.
Regrid data from x,y onto newx. If allow_extrapolation is True, extrapolation is attempted if the method supports it. Supported methods are:
- linear
- spline
Use of this function may require the scipy extension package.
Downsample (i.e. co-add consecutive numbers) a vector by an integer factor. Trims the input timeseries to be a multiple of the downsample factor, if needed. If rescale == True, then divides each sum by factor to produce a mean value, otherwise just adds the values in the vector.
Smooth the data using a window with requested size. Stolen from SciPy Cookbook at http://www.scipy.org/Cookbook/SignalSmooth
This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.
>>> from numpy import *
>>> t=linspace(-2,2,0.1)
>>> x=sin(t)+randn(len(t))*0.1
>>> y=smooth(x)
See also
numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve scipy.signal.lfilter
TODO: the window parameter could be the window itself if an array instead of a string
Return the polar magnitudes of complex values.
Return the polar phases of complex values as radians.
Return the polar (magnitude, phase) representation of complex values (real, imaginary). The return value is an array of shape (N,2), where N is the length of the cmplx input array.
Return the rectilinear (real, imaginary) representation of complex values (magnitude, phase).
Return the real rectilinear component from complex values expressed in polar form (magnitude, phase).
Return the imaginary rectilinear component from complex values expressed in polar form (magnitude, phase).
Convert from linear units to decibels.
Convert from decibels to linear units.
Given a list of times and a list of data values, compute a non-uniform discrete Fourier transform (NDFT) of the data. Returns a two element tuple of frequency and the complex NDFT result.
Smooth (and optionally differentiate) data with a Savitzky-Golay filter. The Savitzky-Golay filter removes high frequency noise from data. It has the advantage of preserving the original shape and features of the signal better than other types of filtering approaches, such as moving averages techhniques.
Notes: The Savitzky-Golay is a type of low-pass filter, particularly suited for smoothing noisy data. The main idea behind this approach is to make for each point a least-square fit with a polynomial of high order over a odd-sized window centered at the point.
>>> t = numpy.linspace(-4, 4, 500)
>>> y = numpy.exp( -t**2 ) + numpy.random.normal(0, 0.05, t.shape)
>>> ysg = savitzky_golay(y, window_size=31, order=4)
>>> import matplotlib.pyplot as plt
>>> plt.plot(t, y, label='Noisy signal')
>>> plt.plot(t, numpy.exp(-t**2), 'k', lw=1.5, label='Original signal')
>>> plt.plot(t, ysg, 'r', label='Filtered signal')
>>> plt.legend()
>>> plt.show()
Return a function that generates a 1-D gaussian with the specified height, mean, and standard deviation.
>>> height = 1
>>> center = 5.0
>>> width = 2.1
>>> gauFnc = guassian1d(height, center, width)
>>> value = gauFnc(numpy.arange(0, 100))
Based on: http://code.google.com/p/agpy/source/browse/trunk/agpy/gaussfitter.py
Return a function that generates a 2-D gaussian with the specified height, mean (for both X and Y), standard deviation (for both major and minor axes), and rotation angle from the X axis in degrees.
Based on: http://code.google.com/p/agpy/source/browse/trunk/agpy/gaussfitter.py
Estimate the parameters (height, center, width) for a gaussian. The return order is:
1-D: height, center, width 2-D: height, center x, center y, width x, width y, position angle
Note
The 2-D fits always return a position angle of zero since the routine decomposes the process into two 1-D fits.
Decompose a spherical or semi-spherical data set into spherical harmonics.
degrees keyword is set * alt: 2-D numpy array of altitude coordinates in radian or degrees if the degrees keyword is set * data: 2-D numpy array of the data to be fit. If the data array is purely real, then the realOnly keyword can be set which speeds up the decomposition * lmax: integer setting the maximum order harmonic to fit
are in degrees or not * realOnly: boolean of whether or not the input data is purely real or not. If the data are real, only coefficients for modes >=0 are computed.
Returned is a 1-D complex numpy array with the spherical harmonic coefficients packed packed in order of increasing harmonic order and increasing mode, i.e., (0,0), (1,-1), (1,0), (1,1), (2,-2), etc. If the realOnly keyword has been set, the negative coefficients for the negative modes are excluded from the output array.
Note
sphfit was designed to fit the LWA dipole response pattern as a function of azimuth and elevation. Elevation angles are mapped to theta angles by adding pi/2 so that an elevation of 90 degrees corresponds to a theta of 180 degrees. To fit in terms of spherical coordianates, subtract pi/2 from the theta values before running.
Evaluate a set of spherical harmonic coefficents at a specified set of azimuth and altitude coordinates.
degrees keyword is set * alt: 2-D numpy array of altitude coordinates in radian or degrees if the degrees keyword is set
are in degrees or not * realOnly: boolean of whether or not the input data is purely real or not. If the data are real, only coefficients for modes >=0 are computed.
Returns a 2-D numpy array of the harmoics evalated and summed at the given coordinates.
Note
sphfit was designed to fit the LWA dipole response pattern as a function of azimuth and elevation. Elevation angles are mapped to theta angles by adding pi/2 so that an elevation of 90 degrees corresponds to a theta of 180 degrees. To spherical harmonics in terms of spherical coordianates, subtract pi/2 from the theta values before running.