ffta.hdf_utils package

Module contents

ffta.hdf_utils.analyze_h5 module

Created on Thu Feb 22 13:16:05 2018

@author: Raj

ffta.hdf_utils.analyze_h5.find_FF(h5_path)
Parameters

h5_path (str) – Location of the relevant datasets to be saved/plotted. e.g. h5_rb.name

Returns

tuple (h5_gp, parameters) WHERE [type] h5_gp is… [type] parameters is…

ffta.hdf_utils.analyze_h5.plot_tfps(h5_file, h5_path='/', append='', savefig=True, stdevs=2)

Plots the relevant tfp, inst_freq, and shift values as separate image files

Parameters
  • h5_file (h5Py File) –

  • h5_path (str, optional) – Location of the relevant datasets to be saved/plotted. e.g. h5_rb.name

  • append (str, optional) – A string to include in the saved figure filename

  • savefig (bool, optional) – Whether or not to save the image

  • stdevs (int, optional) – Number of standard deviations to display

ffta.hdf_utils.analyze_h5.process(h5_file, ds='FF_Raw', ref='', clear_filter=False, verbose=True, liveplots=True, **kwargs)

Processes FF_Raw dataset in the HDF5 file

This then saves within the h5 file in FF_Group-processed

This uses the dataset in this priority:

*A relative path specific by ref, e.g. ‘/FF_Group/FF_Avg/FF_Avg’ *A dataset specified by ds, returning the last found, e.g. ‘FF_Raw’ *FF_Group/FF_Raw found via searching from hdf_utils folder

Typical usage: >> import pycroscopy as px >> h5_file = px.io.HDFwriter(‘path_to_h5_file.h5’).file >> from ffta import analyze_h5 >> tfp, shift, inst_freq = analyze_h5.process(h5_file, ref = ‘/FF_Group/FF_Avg/FF_Avg’)

Parameters
  • h5_file (h5Py file or str) – Path to a specific h5 file on the disk or an hdf.file

  • ds (str, optional) – The Dataset to search for in the file

  • ref – A path to a specific dataset in the file. e.g. h5_file[‘/FF_Group/FF_Avg/FF_Avg’]

  • clear_filter (bool, optional) – For data already filtered, calls Line’s clear_filter function to skip FIR/windowing steps

  • verbose (bool, optional,) – Whether to write data to the command line

  • liveplots – Displaying can sometimes cause the window to pop in front of other active windows in Matplotlib. This disables it, with an obvious drawback of no feedback.

Typr ref

str, optional

:type liveplots : bool

Returns

tuple (tfp, shift, inst_freq, h5_if) WHERE ndarray tfp is time-to-first-peak image array ndarray shift is frequency shift image array 2D ndarray inst_freq is instantaneous frequency array, an N x p array of N=rows*cols points

and where p = points_per_signal (e.g. 16000 for 1.6 ms @10 MHz sampling)

USIDataset h5_if is instantaneous frequency

ffta.hdf_utils.analyze_h5.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) – 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, optional) –

ffta.hdf_utils.analyze_h5.save_IF(h5_gp, inst_freq, parm_dict)

Adds Instantaneous Frequency as a main dataset

Parameters
  • h5_gp

  • inst_freq

  • parm_dict (dict) –

Returns

Return type

ffta.hdf_utils.analyze_h5.save_ht_outs(h5_gp, tfp, shift)

Save processed Hilbert Transform outputs

Parameters
  • h5_gp

  • tfp

  • shift

Returns

tuple (tfp_px, shift_px, tfp_fixed_px) WHERE [type] tfp_px is… [type] shift_px is… [type] tfp_fixed_px is…

ffta.hdf_utils.hdf_utils module

Created on Thu Feb 22 14:28:28 2018

@author: Raj

ffta.hdf_utils.hdf_utils.h5_list(h5_file, key)

Returns list of names matching a key in the h5 group passed. This is useful for creating unique keys in datasets This ONLY works on the specific group and is not for searching the HDF5 file folder

e.g. this checks for -processed folder, increments the suffix >> names = hdf_utils.h5_list(hdf.file[‘/FF_Group’], ‘processed’) >> try: >> suffix = names[-1][-4:] >> suffix = str(int(suffix)+1).zfill(4)

Parameters
  • h5_file (h5py File) – hdf.file[‘/Measurement_000/Channel_000’] or similar

  • key (str) – string to search for, e.g. ‘processing’

Returns

Return type

List of str

ffta.hdf_utils.plot_tfp module

Created on Fri Mar 27 14:05:42 2020

@author: Raj

ffta.hdf_utils.plot_tfp.get_scale(target_size, x_size)
Parameters
  • target_size

  • x_size

Returns

Return type

ffta.hdf_utils.plot_tfp.plot_tfps(h5_file, h5_path='/', append='', savefig=True, stdevs=2, scale=None)

Plots the relevant tfp, inst_freq, and shift values as separate image files

Parameters
  • h5_file (h5Py File) –

  • h5_path (str, optional) – Location of the relevant datasets to be saved/plotted. e.g. h5_rb.name

  • append (str, optional) – A string to include in the saved figure filename

  • savefig (bool, optional) – Whether or not to save the image

  • stdevs (int, optional) – Number of standard deviations to display

  • scale (float, optional) – Scale bar size, in microns

Returns

tuple (fig, ax) WHERE [type] fig is… [type] ax is…

ffta.hdf_utils.process module

Created on Tue Feb 11 18:07:06 2020

@author: Raj

class ffta.hdf_utils.process.FFtrEFM(h5_main, parm_dict={}, can_params={}, pixel_params={}, if_only=False, override=False, process_name='Fast_Free', **kwargs)

Bases: Process

This class processes the deflection data into instantaneous frequency and tFP Implements the pixel-by-pixel processing using ffta.pixel routines Abstracted using the Process class for parallel processing on image dataset

Example usage:

>> from ffta.hdf_utils import process >> data = process.FFtrEFM(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()

impulse_response(can_path, voltage=None, plot=True)

Generates impulse response using simulation with given cantilever parameters file

Parameters
  • can_path (str) – Path to cantilever parameters.txt file

  • voltage – Voltage to simulate the impulse response at

  • plot – Whether the plot the processed instantaneous frequency/Pixel response

reshape(cal=None)

Reshapes the tFP and shift data to be a matrix, then saves that dataset instead of the 1D

Parameters

cal (UNivariateSpline file from ffta.simulation.cal_curve) –

test(pixel_ind=[0, 0])

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]

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 the frequency shift at time t=tfp (i.e. maximum frequency shift)

test_deconv(window, pixel_ind=[0, 0], iterations=10)

Tests the deconvolution by bracketing the impulse around window A reasonable window size might be 100 us pre-trigger to 500 us post-trigger

Parameters
  • window (list) – List of format [left_index, right_index] for impulse

  • 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]

  • iterations (int) – Number of Richardson-Lucy deconvolution iterations

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.hdf_utils.process.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) or the parent Group) –

  • scale_tfp

  • scale_shift

  • threshold

  • kwargs

Returns

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

ffta.hdf_utils.process.save_CSV_from_file(h5_file, h5_path='/', append='', mirror=False, offset=0)

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, optional) –

  • offset (float) – if calculating tFP with a fixed offset for fitting, this subtracts it out