ffta.gkpfm package

Submodules

ffta.gkpfm.gkline module

ffta.gkpfm.gkline.cpd_single(ds, params)
Parameters
  • ds

  • params

Returns

Return type

ffta.gkpfm.gkline.cpd_total(ds, params, verbose=False, ncycles=4, smooth=3)
Parameters
  • ds

  • params

  • verbose (bool, optional) –

  • ncycles (int, optional) –

  • smooth

Returns

tuple (cpd_mat, cpd_mat_sm) WHERE [type] cpd_mat is… [type] cpd_mat_sm is…

ffta.gkpfm.gkline.save_cpd(h5_main, cpd_mat, cpd_sm)
Parameters
  • h5_main

  • cpd_mat

  • cpd_mat_sm

Returns

Return type

ffta.gkpfm.gkpixel module

Created on Tue Sep 3 11:55:14 2019

@author: Raj

class ffta.gkpfm.gkpixel.GKPixel(signal_array, params, can_params={}, fit=True, pycroscopy=False, method='hilbert', fit_form='product', filter_amplitude=False, filter_frequency=False, trigger=None, total_time=None, sampling_rate=None, TF_norm=[], exc_wfm=[], periods=2, phase_shift=0)

Bases: Pixel

analyze_cpd(verbose=False, deg=2, use_raw=False, periods=2, overlap=False)

Extracts CPD and capacitance gradient from data.

Parameters
  • verbose (bool) –

  • deg (int) – Degree of polynomial fit. Default is 2, which is a quadratic fit. Unless there’s a good reason, quadratic is correct to use

  • use_raw (bool, optional) – Uses the signal_array instead of the reconstructed force

  • periods (int, optional) – Numer of cantilever cycles to average over for CPD extraction

  • overlap (bool, optional) – If False, each CPD is from a separate part of the signal. If True, shifts signal by 1 pixel and recalculates

dc_response(plot=True)

Extracts the DC response and plots. For noise-free data this will show the expected CPD response

Parameters

plot (bool) –

excitation(exc_params={}, phase=-3.141592653589793)

Generates excitation waveform (AC probing bias) for CPD vs excitation plots

Parameters
  • exc_params (dict, optional) – Specifies parameters for excitation waveform. Relevant keys are ac (in V), dc (in V), phase (in radians), and frequency (in Hz). The default is None, implying an excitation waveform of magnitude 1V, with period 1/drive_freq, and 0 DC offset.

  • phase (float, optional) – Offset of the excitation waveform in radians. Default is pi.

excitation_phase(exc_path, exc_params={}, phase_range=[-3.141592653589793, 3.141592653589793])

Generates the excitation waveform based on the input ibw.

Calculates phase and runs self.excitation until they match. This process is to compensate for the Gage card having a limited input voltage range.

Returns

  • self.exc_wfm

  • param exc_path: .ibw path containing the applied DDS excitation to the cantilever from the experiment

  • type exc_path: string

  • param exc_params: Specifies parameters for excitation waveform. Relevant keys are ac (in V), dc (in V), – phase (in radians), and frequency (in Hz). The default is None, implying an excitation waveform of magnitude 1V, with period 1/drive_freq, and 0 DC offset.

  • type exc_params: dict, optional

  • param phase_range: The start and stop phases to check

  • type phase_range: list, shape 2, optional

excitation_scale(exc_path, exc_params)

Generates the excitation waveform based on the input ibw. Scaled to exc_params

This process is to compensate for the Gage card having a limited input voltage range.

Parameters
  • exc_path (string) – .ibw path containing the applied DDS excitation to the cantilever from the experiment

  • exc_params (dict) – Specifies parameters for excitation waveform. Relevant keys are ac (in V), dc (in V), phase (in radians), and frequency (in Hz). The default is None, implying an excitation waveform of magnitude 1V, with period 1/drive_freq, and 0 DC offset. example : exc_params = {‘ac’: 3, ‘dc’: 3} for 3 Vdc and 3Vac excitation

filter_cpd()

Filters the capacitance based on pixel parameter self.filter_bandwidth (typical is 10 kHz, which is somewhat large)

force_out(plot=False, noise_tolerance=1e-06, phase_shift=0)

Reconstructs force by dividing by transfer function

Parameters
  • plot (bool, optional) – Generates plot of reconstructed force. The default is False.

  • noise_tolerance (float, optional) – Use to determine noise_floor, The default is 1e-6

  • phase_shift (float, optional) – Desired phase shift in radians

generate_tf(can_params_dict={}, plot=False)

Uses the cantilever simulation to generate a tune as the transfer function

Parameters
  • can_params_dict (Dict) – use ffta.pixel_utils.load.cantilever_params()

  • plot (bool) – Plots the time-dependent tune

load_tf(tf_path, tf_excitation_path=[], remove_dc=False, adjust_tf_length=False)

Process transfer function and broadband excitation from supplied file This function does not check shape or length

If no tf_excitation_path is provided, this will generate one via SciPy chirp

Parameters
  • tf_path (str) –

  • tf_excitation_path (list) –

  • remove_dc (bool, optional) – Removes the DC peak from the FFT

  • adjust_tf_length (bool, optional) –

min_phase(phases_to_test=[2.0708, 2.1208, 2.1708], noise_tolerance=1e-06, verbose=True)

Determine the optimal phase shift due to cable lag

Parameters
  • phases_to_test (list, optional) – Which phases to shift the signal with. The default is [2.0708, 2.1208, 2.1708], which is 0.5, 0.55, 0.5 + pi/2

  • noise_tolerance – Use to determine noise_floor, The default is 1e-6

:type noise_tolerance : float, optional

min_phase_fft(signal)
Parameters

signal

Returns

Return type

noise_filter(bw=1000.0, plot=True, noise_tolerance=1e-06)

Denoising filter for 50 kHz harmonics (electrical noise in the system)

Parameters
  • bw (float, optional) – Bandwidth for the notch filters

  • plot (bool, optional) – Generates plot of reconstructed force. The default is False.

  • noise_tolerance (float, optional) – Use to determine noise_floor, The default is 1e-6

plot_cpd(smooth=None)

Plots the CPD response

Parameters

smooth (int, optional) – Boxcar smoothign kernel. Value of 3 is reasonable

Returns

Return type

matplotlib figure axis object

plot_response()

Plots the transfer function and calculated force in frequency space

process_tf(resonances=2, width=20000.0, exc_floor=10, plot=False)
Parameters
  • resonances (int, optional) – Number of resonances to fit SHO to. The default is 2.

  • width (int, optional) – Width of resonance peaks to fit against. The default is 20e3.

  • exc_floor (float, optional) – Sets the floor for the transfer function, below that is ignored. The default is 10

  • plot (bool, optional) – Displays fits. The default is False

ffta.gkpfm.gkpixel.cost_func(resp_wfm, signal)
Parameters
  • resp_wfm

  • signal

Returns

Return type

ffta.gkpfm.gkpixel.gen_chirp(f_center=500000.0, f_width=450000.0, length=0.01, sampling_rate=10000000.0)

Generates a single broad-frequency signal using scipy chirp, writes to name.dat

Parameters
  • f_center (float) – Central frequency for the signal

  • f_width – The single-sided width of the chirp. Generates signal from f_center - f_width to f_center + f_width

:type f_width : float

Parameters
  • length (float) – the timescale of the signal. Keep this length in mind for data acquisition; if your chirp is longer than your data acquisition, you will miss many of the frequencies

  • sampling_rate (int) – Sampling rate of the chirp, based on length/sampling_rate number of steps This rate must be consistent on the wave generator or the frequencies will be off

Returns

Return type

ffta.gkpfm.gkpixel.poly2(t, a, b, c)
Parameters
  • t (float) –

  • a (float) –

  • b (float) –

  • c

Returns

Return type

float

ffta.gkpfm.gkpixel.tf_fit_mat(drive_freq, resonances=2, width=20000.0)
Parameters
  • drive_freq

  • resonances (int) –

  • width (float) –

Returns

Return type

numpy nd.array

ffta.gkpfm.gkprocess module

Created on Tue Feb 11 18:07:06 2020

@author: Raj

class ffta.gkpfm.gkprocess.GKPFM(h5_main, parm_dict={}, can_params={}, pixel_params={}, TF_norm=[], exc_wfm=[], periods=2, tip_response='', tip_excitation='', exc_wfm_file='', override=False, exc_floor=10, noise_tolerance=0.0001, **kwargs)

Bases: FFtrEFM

Implements the pixel-by-pixel processing using ffta.pixel routines Abstracted using the Process class for parallel processing

Example usage:

>> from ffta.hdf_utils import process >> data = process.GKPFM(h5_main) >> data.test([1,2]) # tests on pixel 1,2 in row, column >> data.compute() >> data.reshape() # reshapes the tFP, shift data >> process.save_CSV_from_file(data.h5_main.file, data.h5_results_grp.name) >> process.plot_tfp(data)

To reload old data:

>> data = FFtrEFM() >> data._get_existing_datasets()

process_tf(exc_floor=10)

Generates a Transfer Function using GKPixel function

Parameters

exc_floor (float) –

reshape()

Currently unimplemented. See ffta.hdf_utils.process.FFtrEFM for an example

test(pixel_ind=[0, 0], phases_to_test=[2.0708, 2.1208, 2.1708], smooth=None)

Test the Pixel analysis of a single pixel

Parameters
  • pixel_ind (uint or list) – Index of the pixel in the dataset that the process needs to be tested on. If a list it is read as [row, column]

  • phases_to_test (list, optional) – Which phases to shift the signal with. The default is [2.0708, 2.1208, 2.1708], which is 0.5, 0.55, 0.5 + pi/2

  • smooth

Returns

List [inst_freq, tfp, shift] WHERE array inst_freq is the instantaneous frequency array for that pixel float tfp is the time to first peak float shift shift is the frequency shift at time t=tfp (i.e. maximum frequency shift)

update_parm(**kwargs)

Update the parameters, see ffta.pixel.Pixel for details on what to update e.g. to switch from default Hilbert to Wavelets, for example

Parameters

**kwargs

ffta.gkpfm.gkprocess.plot_tfp(ffprocess, scale_tfp=1000000.0, scale_shift=1, threshold=2, **kwargs)
Quickly plots the tfp and shift data. If there’s a height image in the h5_file associated

with ffprocess, will plot that as well

Parameters
  • ffprocess (FFtrEFM class object (inherits Process)) –

  • scale_tfp

  • scale_shift

  • threshold

  • **kwargs

Returns

tuple (fig, a) WHERE figure object fig is… axes object a is…

ffta.gkpfm.gkprocess.save_CSV_from_file(h5_file, h5_path='/', append='', mirror=False)

Saves the tfp, shift, and fixed_tfp as CSV files

Parameters
  • h5_file (H5Py file of FFtrEFM class) – Reminder you can always type: h5_svd.file or h5_avg.file for this

  • h5_path (str, optional) – specific folder path to search for the tfp data. Usually not needed.

  • append (str, optional) – text to append to file name

  • mirror (bool) –

ffta.gkpfm.load_excitation module

loadHDF5.py: Includes routines for loading into HDF5 files.

ffta.gkpfm.load_excitation.load_exc(ibw_folder='', pixels=64, scale=1, offset=1, verbose=False)

Loads excitation files into a single .h5 file

Parameters
  • ibw_folder (string, optional) – The folder containing the excitation files to load

  • pixels (int, optional) – How many pixels per line to divide the excitation ibw

  • scale (float, optional) – The AC signal scaling, assuming the input excitation is wrong

  • offset (float, optional) – The DC offset for the excitation

  • verbose (bool, optional) –

Returns

Return type

str

ffta.gkpfm.transfer_func module

Created on Mon Aug 19 12:10:38 2019

@author: Raj

ffta.gkpfm.transfer_func.Y_calc(h5_main, transfer_func=None, resampled=True, ratios=None, verbose=False, noise_floor=0.001, phase=-3.141592653589793, plot=False, scaling=1)

Divides the response by the transfer function

Parameters
  • h5_main (h5py dataset of USIDataset) –

  • transfer_func (transfer function, optional) – This can be supplied or use the calculated version For best results, use the “normalized” transfer function “None” will default to /Transfer_Function folder

  • resampled (bool, optional) – Whether to use the upsampled Transfer Function or the original

  • ratios (array, optional) – Array of the size of h5_main (1-D) with the transfer function data If not given, it’s found via the test_Y_calc function

  • verbose (bool, optional) – Gives user feedback during processing

  • noise_floor (float, optional) – For calculating what values to filter as the noise floor of the data 0 or None circumvents this

  • phase (float, optional) – Practically any value between -pi and +pi works

  • plot (bool, optional) –

  • scaling – scales the transfer function by this number if, for example, the TF was acquired on a line and you’re dividing by a point (or vice versa)’

scaling : int, optional

Returns

tuple (Yout, yout) WHERE [type] Yout is… [type] yout is…

ffta.gkpfm.transfer_func.check_phase(h5_main, transfer_func, phase_list=[-3.141592653589793, -1.5707963267948966, 0], plot=True, noise_tolerance=1e-06, samp_rate=10000000.0)

Uses the list of phases in phase_list to plot the various phase offsets relative to the driving excitation

Parameters
  • h5_main (h5py dataset of USIDataset) –

  • transfer_func (transfer function, optional) – This can be supplied or use the calculated version For best results, use the “normalized” transfer function “None” will default to /Transfer_Function folder

  • phase_list (List of float) –

  • plot (bool, optional) –

  • noise_tolerance

  • samp_rate

ffta.gkpfm.transfer_func.check_response(h5_main, pixel=0, ph=0)
Parameters
  • h5_main (h5py dataset of USIDataset) –

  • pixel

  • ph

ffta.gkpfm.transfer_func.params_list(path='', psd_freq=1000000.0, lift=50)

Reads in a Parameters file as saved in Igor as a dictionary

For use in creating attributes of transfer Function

Parameters
  • path (str) –

  • psd_freq

  • lift

Returns

parameters dictionary

Return type

dict

ffta.gkpfm.transfer_func.resample_tf(h5_file, psd_freq=1000000.0, sample_freq=10000000.0)

Resamples the Transfer Function based on the desired target frequency

This is important for dividing the transfer function elements together

Parameters
  • h5_file

  • psd_freq (float) – The maximum range of the Power Spectral Density. For Asylum Thermal Tunes, this is often 1 MHz on MFPs and 2 MHz on Cyphers

  • sample_freq (float) – The desired output sampling. This should match your data.

Returns

tuple (TFN_RS, FQ_RS) WHERE [type] TFN_RS is… [type] FQ_RS is…

ffta.gkpfm.transfer_func.save_Yout(h5_main, Yout, yout)

Writes the results to teh HDF5 file

Parameters
  • h5_main (h5py dataset of USIDataset) –

  • Yout

  • yout

ffta.gkpfm.transfer_func.test_Ycalc(h5_main, pixel_ind=[0, 0], transfer_func=None, resampled=True, ratios=None, verbose=True, noise_floor=0.001, phase=-3.141592653589793, plot=False, scaling=1)

Divides the response by the transfer function

Parameters
  • h5_main (h5py dataset of USIDataset) –

  • pixel_ind (list) –

  • transfer_func (transfer function, optional) – This can be the resampled or normal transfer function For best results, use the “normalized” transfer function “None” will default to /Transfer_Function folder

  • resampled (bool, optional) – Whether to use the upsampled Transfer Function or the original

  • ratios

  • verbose (bool, optional) – Gives user feedback during processing

  • noise_floor (float, optional) – For calculating what values to filter as the noise floor of the data 0 or None circumvents this

  • phase (float, optional) – Practically any value between -pi and +pi works

  • plot (bool, optional) –

  • scaling (int, optional) – scales the transfer function by this number if, for example, the TF was acquired on a line and you’re dividing by a point (or vice versa)’

Returns

tuple (TFratios, Yout, yout) WHERE [type] TFratios is… [type] Yout is… [type] yout is…

ffta.gkpfm.transfer_func.transfer_function(h5_file, tf_file='', params_file='', psd_freq=1000000.0, offset=0.0016, sample_freq=10000000.0, plot=False)

Reads in the transfer function .ibw, then creates two datasets within a parent folder ‘Transfer_Function’

This will destructively overwrite an existing Transfer Function in there

  1. TF (transfer function)

  2. Freq (frequency axis for computing Fourier Transforms)

Parameters
  • h5_file

  • tf_file (ibw) – Transfer Function .ibw File

  • params_file (string) – The filepath in string format for the parameters file containing Q, AMPINVOLS, etc.

  • psd_freq (float) – The maximum range of the Power Spectral Density. For Asylum Thermal Tunes, this is often 1 MHz on MFPs and 2 MHz on Cyphers

  • offset (float) – To avoid divide-by-zero effects since we will divide by the transfer function when generating GKPFM data

  • sample_freq (float) – The desired output sampling. This should match your data.

  • plot (bool, optional) –

Returns

the Transfer Function group

Return type

Module contents