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.
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 phases of complex values as radians.
See also
Take the robust mean of an array, normally a small section of a spectrum, over which the mean can be assumed to be constant. Makes two passes discarding outliers >3 sigma ABOVE (not below) the mean.
See also
lsl.statistics.robust.robustMean()
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
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.