ffta.analysis package

Module contents

ffta.analysis.create_movie

ffta.analysis.create_movie.create_cpd_movie(h5_ds, filename='cpd', size=(10, 6), vscale=[None, None], cmap='inferno', smooth=None, interval=60, repeat_delay=100)
Parameters
  • h5_ds (USID dataset) – The instantaneous frequency data. NOT deflection, this is for post-processed data

  • filename (str) –

  • size (tuple, optional) – figure size

  • vscale (list [float, float], optional) – To hard-code the color scale, otherwise these are automatically generated

  • interval

  • repeat_delay (int) – Used when saving to set the delay for when the mp4 repeats from the start

ffta.analysis.create_movie.create_freq_movie(h5_ds, filename='inst_freq', time_step=50, idx_start=500, idx_stop=100, smooth=None, size=(10, 6), vscale=[None, None], cmap='inferno', interval=60, repeat_delay=100, crop=None)

Creates an animation that goes through all the instantaneous frequency data.

Parameters
  • h5_ds (USID dataset) – The instantaneous frequency data. NOT deflection, this is for post-processed data

  • filename (str) –

  • time_step (int, optional) – 10 @ 10 MHz = 1 us 50 @ 10 MHz = 5 us

  • idx_start (int) – What index to start at. Typically to avoid the Hilbert Transform edge artifacts, you start a little ahead

  • idx_stop (int) – Same as the above,in terms of how many points BEFORE the end to stop

  • smooth (int, optional) – Whether to apply a simple boxcar smoothing kernel to the data

  • size (tuple, optional) – figure size

  • vscale (list [float, float], optional) – To hard-code the color scale, otherwise these are automatically generated

  • cmap (str, optional) –

  • interval

  • repeat_delay (int) – Used when saving to set the delay for when the mp4 repeats from the start

  • crop (int) – Crops the image to a certain line, in case part of the scan is bad

ffta.analysis.create_movie.set_mpeg(path=None)
Parameters

path (str) –

ffta.analysis.create_movie.setup_movie(h5_ds, size=(10, 6), vscale=[None, None], cmap='inferno')
Parameters
  • h5_ds (USID dataset) – The instantaneous frequency data. NOT deflection, this is for post-processed data

  • size (tuple) –

  • vscale (list) –

  • cmap (str) –

Returns

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

ffta.analysis.dist_cluster

ffta.analysis.filtering

Created on Mon Feb 26 17:15:36 2018

@author: Raj

class ffta.analysis.filtering.BandPassFilter(signal_length, samp_rate, f_center, f_width, fir=False, fir_taps=1999)

Bases: FrequencyFilter

get_parms()
Returns

Return type

dict

ffta.analysis.filtering.bandpass(hdf_file, parameters={}, pixelnum=[0, 0], f_center=None, f_width=10000.0, harmonic=None, fir=False)

Interfaces to pycroscopy.processing.fft.BandPassFilter Note that this is effectively a Harmonic Filter of number_harmonics 1, but with finite impulse response option

Parameters
  • hdf_file

  • parameters (dict) –

  • pixelnum (list) – See test_filter below

  • f_center (int) – center frequency for the specific band to pass

  • f_width (int) – width of frequency to pass

  • harmonic (int) – if specified, sets the band to this specific multiple of the drive frequency

  • fir (bool) – uses an Finite Impulse Response filter instead of a normal boxcar

Returns

1D numpy array describing the bandpass filter

Return type

1D numpy array:

ffta.analysis.filtering.fft_filter(h5_main, freq_filts, noise_tolerance=5e-07, make_new=False, verbose=False)

Stub for applying filter above to the entire FF image set

Parameters

h5_main – Dataset to work on, e.g. h5_main = px.hdf_utils.getDataSet(hdf.file, ‘FF_raw’)[0]

:type h5_main : h5py.Dataset object

Parameters
  • freq_filts (list) – List of frequency filters usually generated in test_line above

  • noise_tolerance – Level below which data are set to 0. Higher values = more noise (more tolerant)

:type noise_tolerance : float, optional

Parameters
  • make_new (bool, optional) – Allows for re-filtering the data by creating a new folder

  • verbose (bool, optional) –

Returns

Filtered dataset within latest -FFT_Filtering Group

Return type

Dataset

ffta.analysis.filtering.harmonic(hdf_file, parameters={}, pixelnum=[0, 0], first_harm=1, bandwidth=None, num_harmonics=5)

Interfaces with px.processing.fft.HarmonicFilter

Parameters
  • hdf_file

  • parameters (dict) –

  • pixelnum (list) – See test_filter below

  • first_harm (int) – The first harmonic based on the drive frequency to use For G-KPFM this should be explicitly set to 2

  • bandwidth (int) – bandwidth for filtering. For computational purposes this is hard-set to 2500 (2.5 kHz)

  • num_harmonics (int) – The number of harmonics to use (omega, 2*omega, 3*omega, etc)

Returns

Return type

ffta.analysis.filtering.lowpass(hdf_file, parameters={}, pixelnum=[0, 0], f_cutoff=None)

Interfaces to px.pycroscopy.fft.LowPassFilter

Parameters
  • hdf_file

  • parameters (dict) –

  • pixelnum (list) – See test_filter below

  • f_cutoff (int) – frequency to cut off. Defaults to 2*drive frequency rounded to nearest 100 kHz

Returns

Return type

ffta.analysis.filtering.noise_filter(hdf_file, parameters={}, pixelnum=[0, 0], centers=[10000.0, 50000.0, 100000.0, 150000.0, 200000.0], widths=[20000.0, 1000.0, 1000.0, 1000.0, 1000.0])

Interfaces with pycroscopy.processing.fft.NoiseBandFilter

Parameters
  • hdf_file

  • parameters (dict) –

  • pixelnum (list) – See test_filter below

  • centers (list) – List of Frequencies to filter out

  • widths (list) – List of frequency widths for each filter. e,g. in default case (10 kHz center, 20 kHz width) is from 0 to 20 kHz

Returns

Return type

ffta.analysis.filtering.test_filter(hdf_file, freq_filts, parameters={}, pixelnum=[0, 0], noise_tolerance=5e-07, show_plots=True, check_filter=True)

Applies FFT Filter to the file at a specific line and displays the result

Parameters
  • hdf_file (h5Py file or Nx1 NumPy array (preferred is NumPy array)) – hdf_file to work on, e.g. hdf.file[‘/FF-raw’] if that’s a Dataset if ndarray, uses passed or default parameters Use ndarray.flatten() to ensure correct dimensions

  • freq_filts (list of FrequencyFilter class objects) – Contains the filters to apply to the test signal

  • parameters (dict, optional) – Contains parameters in FF-raw file for constructing filters. Automatic if a Dataset/File Must contain num_pts and samp_rate to be functional

  • pixelnum (int, optional) – For extracting a specific pixel to do FFT Filtering on

  • noise_tolerance (float 0 to 1) – Amount of noise below which signal is set to 0

  • show_plots – Turns on FFT plots from Pycroscopy

:type show_plots : bool, optional

Returns

tuple (filt_line, freq_filts, fig_filt, axes_filt) WHERE numpy.ndarray filt_line is filtered signal of hdf_file list freq_filts is the filter parameters to be passed to SignalFilter matplotlib controls fig_filt, axes_filt - Only functional if show_plots is on

ffta.analysis.mask_utils

Created on Thu Mar 22 18:43:21 2018

@author: Raj

ffta.analysis.mask_utils.averagemask(CPDarr, mask, rows=128, nan_flag=1, avg_flag=0)

Returns an averaged CPD trace given the Igor mask

Parameters
  • CPDarr – the CPD of n-by-samples, typically 8192 x 128 (8192 pixels, 128 CPD points) Rows = 128 is default of 128x64 images

  • mask (ndarray 2D (rows, columns)) – The mask to process into various new masks

  • rows (int) –

  • nan_flag (int, 0 or 1) – what value in the mask to set to NaN. These are IGNORED 1 is “transparent” in Igor mask 0 is “opaque/masked off” in Igor mask

  • avg_flag – what values in mask to average.

Returns

the averaged CPD of those pixels

Return type

ffta.analysis.mask_utils.load_mask_txt(path, rows=64, flip=False)

Loads mask from text

Parameters
  • path (str) – Filepath to disk location of the mask

  • rows (int, optional) – Sets a hard limit on the rows of the mask, due to Igor images being larger (rowwise) than the typical G-Mode/FF-trEFM Mask size

  • flip (bool, optional) – Whether to flip the mask left-to-right to match CPD

Returns

the mask itself

ffta.analysis.mask_utils.load_masks(mask)

Outputs several useful mask versions

For reference:

NaNs = 1s in the mask = transparent in display 0s = 0s in the mask = opaque in display (i.e., are exluded/masked)

Parameters

mask (ndarray 2D (rows, columns)) – The mask to process into various new masks

Returns

tuple (mask_nan, mask_on_1D, mask_off_1D) WHERE 2D ndarray mask_nan - all 1s are NaNs, primarily for image display. (rows, columns) 1D ndarray mask_on_1D - non-NaN pixels as a 1D list for distance calculation (rows*columns) 1D ndarray mask_off_1D - NaN pixels as a 1D list for CPD masking (rows*columns)

ffta.analysis.svd

Created on Wed Mar 7 22:04:39 2018

@author: Raj

ffta.analysis.svd.plot_svd(h5_main, savefig=False, num_plots=16, **kwargs)

Replots the SVD showing the skree, abundance maps, and eigenvectors. If h5_main is the results group, then it will plot the values for that group. If h5_main is a Dataset, it will default to the most recent SVD group.

Parameters
  • h5_main (USIDataset or h5py Dataset or h5py Group) –

  • savefig (bool, optional) – Saves the figures to disk

  • num_plots (int) – Default number of eigenvectors and abundance plots to show

  • kwargs (dict, optional) – keyword arguments for svd filtering

ffta.analysis.svd.svd_filter(h5_main, clean_components=None)

Filters data given the array clean_components

Parameters
  • h5_main (h5py) – Dataset to be filtered and reconstructed. This must be the same as where SVD was performed

  • clean_components – Clean_components has 2 components will filter from start to finish Clean_components has 3+ components will use those individual components

Returns

Return type

ffta.analysis.svd.test_svd(h5_main, num_components=128, show_plots=True, override=True, verbose=True)
Parameters
  • h5_main (h5Py Dataset) – Main dataset to filter

  • num_components (int, optional) – Number of SVD components. Increasing this lenghtens computation

  • show_plots (bool, optional) – If True displays skree, abundance_maps, and data loops

  • override (bool, optional) – Force SVD.Compute to reprocess data no matter what

  • verbose (bool, optional) – Print out component ratio values

Returns

Group containing the h5_svd data

Return type

h5Py Group

ffta.analysis.test_pixel

Created on Thu Mar 8 13:17:12 2018

@author: Raj

ffta.analysis.test_pixel.test_pixel(h5_file, param_changes={}, pxls=1, showplots=True, verbose=True, clear_filter=False)

Takes a random pixel and does standard processing.

Parameters
  • h5_file (h5Py File, path, Dataset) – H5 file to process

  • param_changes (dict, optional) –

  • pxls (int, optional) – Number of random pixels to survey

  • showplots (bool, optional) – Whether to create a new plot or not.

  • verbose – To print to command line. Currently for future-proofing

:type verbose : bool , optional

Parameters

clear_filter (bool, optional) – Whether to do filtering (FIR) or not