ffta.pixel_utils package¶
Module contents¶
ffta.pixel_utils.badpixels¶
Created on Fri May 22 15:00:13 2015
@author: Raj
- ffta.pixel_utils.badpixels.find_bad_pixels(signal_array, threshold=2, iterations=1)¶
Uses Median filter to find ‘hot’ pixels
- Parameters
signal_array –
threshold –
iterations –
- Returns
tuple (fixed_array, bad_pixels_total) WHERE [type] fixed_array is… [type] bad_pixels_total is…
- ffta.pixel_utils.badpixels.fix_array(path, threshold=10, israte=False)¶
Wrapper function to find and remove ‘hot’ pixels. This version uses a path to specify a file
- Parameters
path (str) –
threshold –
israte (bool) –
- Returns
tuple (fixed_array, bad_pixel_list) WHERE [type] fixed_array is… [type] bad_pixel_list is…
- ffta.pixel_utils.badpixels.load_csv(path)¶
- Parameters
path –
- Returns
- Return type
- ffta.pixel_utils.badpixels.remove_bad_pixels(signal_array, filtered_array, bad_pixel_list)¶
Removes bad pixels from the array
- Parameters
signal_array –
filtered_array –
bad_pixel_list –
- Returns
- Return type
ffta.pixel_utils.dwavelet¶
dwavelet.py: contains functions used in DWT calculations.
- ffta.pixel_utils.dwavelet.dwt_denoise(signal, fLow, fHigh, sampling_rate)¶
Uses Discrete Wavelet Transform to denoise signal around a desired frequency band.
- Parameters
signal –
fLow (float) – frequency below which DWT coefficients zeroed
fHigh (float) – frequency above which DWT coefficients zeroed
sampling_rate (float) – Sample rate of signal in Hz
- Returns
tuple (denoised, coeffs, frequencies) WHERE [type] denoised is… [type] coeffs is… [type] frequencies is…
- ffta.pixel_utils.dwavelet.dwt_scalogram(coeffs)¶
- Parameters
coeffs –
- Returns
- Return type
ffta.pixel_utils.fitting¶
fitting.py: Routines for fitting cantilever data to extract tFP/shift
- ffta.pixel_utils.fitting.cut_exp(t, A, y0, tau)¶
Uses a single exponential for the case of no drive
- Parameters
t –
A –
y0 –
tau –
- Returns
- Return type
- ffta.pixel_utils.fitting.ddho_freq_product(t, A, tau1, tau2)¶
Uses a product of exponentials as the functional form
- Parameters
t –
A –
tau1 –
tau2 –
- Returns
- Return type
- ffta.pixel_utils.fitting.ddho_freq_sum(t, A1, A2, tau1, tau2)¶
Uses a sum of exponentials as the functional form
- Parameters
t –
A1 –
A2 –
tau1 –
tau2 –
- Returns
- Return type
- ffta.pixel_utils.fitting.ddho_phase(t, A, tau1, tau2)¶
- Parameters
t –
A –
tau1 –
tau2 –
- Returns
- Return type
- ffta.pixel_utils.fitting.fit_exp(t, inst_freq)¶
- Parameters
t –
inst_freq –
- Returns
- Return type
- ffta.pixel_utils.fitting.fit_phase(Q, drive_freq, t, phase)¶
- Parameters
Q –
drive_freq –
t –
phase –
- Returns
- Return type
- ffta.pixel_utils.fitting.fit_product(Q, drive_freq, t, inst_freq)¶
- Parameters
Q –
drive_freq –
t –
inst_freq –
- Returns
- Return type
- ffta.pixel_utils.fitting.fit_product_unbound(Q, drive_freq, t, inst_freq)¶
Fit without any bound constraints
- Parameters
Q –
drive_freq –
t –
inst_freq –
- Returns
- Return type
- ffta.pixel_utils.fitting.fit_ringdown(t, cut)¶
- Parameters
t –
cut –
- Returns
- Return type
- ffta.pixel_utils.fitting.fit_sum(Q, drive_freq, t, inst_freq)¶
Fit without any bound constraints
- Parameters
Q –
drive_freq –
t –
inst_freq –
- Returns
- Return type
ffta.pixel_utils.load¶
load.py: Includes routines for loading data and configuration files.
- ffta.pixel_utils.load.cantilever_params(path, asDataFrame=False)¶
Reads an experimental Parameters file describing the cantilever. Cantilever parameters should contain an Initial, Final, and Differential column for describing an excited cantilever
- Parameters
path (str) – Path to the parameters file
asDataFrame (bool) – Returns Pandas dataframe instead of a dictionary
- Returns
- Return type
dict
- ffta.pixel_utils.load.configuration(path)¶
Reads an ASCII file with relevant parameters for processing.
- Parameters
path (string) – Path to ASCII file
- Returns
tuple (n_pixels, parameters) WHERE int n_pixels is number of pixels in the image. dict parameters is the list of parameters:
trigger = float (in seconds) total_time = float (in seconds) sampling_rate = int (in Hz) drive_freq = float (in Hz) Q = float (default: 500)
roi = float (in seconds) window = string (see documentation of scipy.signal.get_window) bandpass_filter = int (0: no filtering, 1: FIR filter, 2: IIR filter) filter_bandwidth = float (in Hz) n_taps = integer (default: 999) wavelet_analysis = bool (0: Hilbert method, 1: Wavelet Method) wavelet_parameter = int (default: 5) recombination = bool (0: FF-trEFMm, 1: Recombination) phase_fitting = bool (0: frequency fitting, 1: phase fitting) EMD_analysis = bool (0: Hilbert method, 1: Hilbert-Huang fitting)
fit_form = string (EXP, PRODUCT, SUM for type of fit function)
- ffta.pixel_utils.load.signal(path, skiprows=0)¶
Loads .ibw or ASCII files and return it as a numpy.ndarray.
- Parameters
path (string) – Path to signal file.
skiprows (int, optional) –
- Returns
2D real-valued signal array loaded from given .ibw file.
- Return type
(n_points, n_signals) array_like
ffta.pixel_utils.noise¶
noise.py: Includes functions for reducing noise in a pixel.
- ffta.pixel_utils.noise.pca_discard(signal_array, k)¶
Discards noisy signals using Principal Component Analysis and Mahalonobis distance.
- Parameters
signal_array ((n_points, n_signals), array_like) – 2D real-valued signal array.
k (int) – Number of eigenvectors to use, can’t be bigger than n_signals.
- Returns
indices of noisy signals.
- Return type
array
- ffta.pixel_utils.noise.phase_lock(signal_array, tidx, cidx)¶
Aligns signals of a pixel on the rising edge of first zeros, if they are not aligned due to phase jitter of analog-to-digital converter.
- Parameters
signal_array ((n_points, n_signals), array_like) – 2D real-valued signal array.
tidx (int) – Time to trigger from the start of signals as index.
cidx (int) – Period of the signal as number of points, i.e. drive_freq/sampling_rate
- Returns
tuple (new_signal_array, tidx) WHERE array_like new_signal_array is phase-locked signal array in format (n_points, n_signals) int tidx is index of trigger after phase-locking.
ffta.pixel_utils.parab¶
parab.py: Parabola fit around three points to find a true vertex.
- ffta.pixel_utils.parab.fit_2d(f, p, dx)¶
Uses solution to parabola to fit peak and two surrounding points This assumes there is a peak (i.e. parabola second deriv is negative).
This is a broadcast version for speed purposes
- Parameters
f (2D array) – 2D array f(x) of size (3 , samples)
p (1D array) – peak positions for f
dx (1D array) – frequency (x values) of f
- Returns
tuple (findex, yindex, xindex) WHERE [type] findex is… [type] yindex is… [type] xindex is…
- ffta.pixel_utils.parab.fit_peak(f, x)¶
Uses solution to parabola to fit peak and two surrounding points This assumes there is a peak (i.e. parabola second deriv is negative)
- If interested, this is educational to see with sympy
import sympy y1, y2, y3 = sympy.symbols(‘y1 y2 y3’) A = sympy.Matrix([[(-1)**2, -1, 1],[0**2, 0, 1],[(1)**2,1,1]]) C = sympy.Matrix([[y1],[y2],[y3]]) D = A.inv().multiply(C) D contains the values of a, b, c in ax**2 + bx + c Peak position is at x = -D[1]/(2D[0])
- Parameters
f (array) – array of f(x)
x (array) – array of indices corresponding to f
- Returns
tuple (findex, yindex, xindex) WHERE [type] findex is… [type] yindex is… [type] xindex is…
- ffta.pixel_utils.parab.fit_peak_old(f, x)¶
Uses parabola equation to fit to the peak and two surrounding points
- Parameters
f (array) –
x – index of peak, typically just argmax
- Returns
tuple (xindex, yindex) WHERE [type] xindex is… [type] yindex is…
- ffta.pixel_utils.parab.ridge_finder(spectrogram, freq_bin)¶
Uses parabolda to fit peak and two surrounding points This takes a spectrogram and the frequency bin spacing and wraps parab.fit_2d
- Parameters
spectrogram (ndarray) – Returned by scipy.signal.spectrogram or stft or cwt Arranged in (frequencies, times) shape
freq_bin (ndarray) – arrays corresponding the frequencies in the spectrogram
- Returns
tuple (xindex, yindex) WHERE ndarray xindex is 1D array of the frequency bins returned by parabolic approximation ndarray yindex is 1D array of the peak values at the xindices supplied
ffta.pixel_utils.peakdetect¶
- ffta.pixel_utils.peakdetect.get_peaks(x)¶
- Parameters
x –
- Returns
tuple (maxpeaks[0], minpeaks[0]) WHERE [type] maxpeaks[0] is… [type] minpeaks[0] is…
ffta.pixel_utils.tfp_calc¶
tfp.py: Routines for fitting the frequency/phase/amplitude to extract tFP/shift
- ffta.pixel_utils.tfp_calc.find_minimum(pix, cut)¶
Finds when the minimum of instantaneous frequency happens using spline fitting
- Parameters
pix (ffta.pixel.Pixel object) – pixel object to analyze
cut (ndarray) – The slice of frequency data to fit against
- Returns
pix.tfp (float) – tFP value
pix.shift (float) – frequency shift value at time t=tfp
pix.best_fit (ndarray) – Best-fit line calculated from spline function
- ffta.pixel_utils.tfp_calc.fit_freq_exp(pix, cut, t)¶
Fits the frequency shift to a single exponential in the case where there is no return to 0 Hz offset (if drive is cut).
- Parameters
pix (ffta.pixel.Pixel object) – pixel object to analyze
cut (ndarray) – The slice of frequency data to fit against
t (ndarray) – The time-array (x-axis) for fitting
- Returns
pix.tfp (float) – tFP value
pix.shift (float) – frequency shift value at time t=tfp
pix.popt (ndarray) – The fit parameters for the function fitting.fit_exp
pix.best_fit (ndarray) – Best-fit line calculated from popt and fit function
- ffta.pixel_utils.tfp_calc.fit_freq_product(pix, cut, t)¶
Fits the frequency shift to an approximate functional form using an analytical fit with bounded values.
- Parameters
pix (ffta.pixel.Pixel object) – pixel object to analyze
cut (ndarray) – The slice of frequency data to fit against
t (ndarray) – The time-array (x-axis) for fitting
- Returns
pix.tfp (float) – tFP value
pix.shift (float) – frequency shift value at time t=tfp
pix.rms (float) – fitting error
pix.popt (ndarray) – The fit parameters for the function fitting.fit_product
pix.best_fit (ndarray) – Best-fit line calculated from popt and fit function
- ffta.pixel_utils.tfp_calc.fit_freq_sum(pix, cut, t)¶
Fits the frequency shift to an approximate functional form using an analytical fit with bounded values.
- Parameters
pix (ffta.pixel.Pixel object) – pixel object to analyze
cut (ndarray) – The slice of frequency data to fit against
t (ndarray) – The time-array (x-axis) for fitting
- Returns
pix.tfp (float) – tFP value
pix.shift (float) – frequency shift value at time t=tfp
pix.rms (float) – fitting error
pix.popt (ndarray) – The fit parameters for the function fitting.fit_sum
pix.best_fit (ndarray) – Best-fit line calculated from popt and fit function
- ffta.pixel_utils.tfp_calc.fit_phase(pix, cut, t)¶
Fits the phase to an approximate functional form using an analytical fit with bounded values.
- Parameters
pix (ffta.pixel.Pixel object) – pixel object to analyze
cut (ndarray) – The slice of frequency data to fit against
t (ndarray) – The time-array (x-axis) for fitting
- Returns
pix.tfp (float) – tFP value
pix.shift (float) – frequency shift value at time t=tfp
pix.popt (ndarray) – The fit parameters for the function fitting.fit_phase
pix.best_fit (ndarray) – Best-fit line calculated from popt and fit function for the frequency data
pix.best_phase (ndarray) – Best-fit line calculated from popt and fit function for the phase data
- ffta.pixel_utils.tfp_calc.fit_ringdown(pix, cut, t)¶
Fits the amplitude to determine Q from single exponential fit.
- Parameters
pix (ffta.pixel.Pixel object) – pixel object to analyze
cut (ndarray) – The slice of amplitude data to fit against
t (ndarray) – The time-array (x-axis) for fitting
- Returns
pix.tfp (float) – Q calculated from ringdown equation
pix.ringdown_Q (float) – Same as tFP. This is the actual variable, tFP is there for code simplicity
pix.shift (float) – amplitude of the single exponential decay
pix.popt (ndarray) – The fit parameters for the function fitting.fit_ringdown
pix.best_fit (ndarray) – Best-fit line calculated from popt and fit function