emocodes.analysis.features

Module Contents

Classes

SummarizeVideoFeatures

This class produces a summary report of video features to help users judge the suitability of each feature for

Functions

pairwise_ips(features, column_names='all')

This function computes the pair-wise instantaneous phase synchrony (IPS) between columns in a dataframe. It returns

pairwise_corr(features, column_names='all')

Computes the pair-wise Spearman correlation coefficient for a set of features.

vif_collinear(features, column_names='all')

Wraps the pliers variance inflation factor command. Computes the variance inflation factor for the specified

hrf(time, time_to_peak=5, undershoot_dur=12)

This function creates a hemodynamic response function timeseries.

hrf_convolve_features(features, column_names='all', time_col='index', units='s', time_to_peak=5, undershoot_dur=12)

This function convolves a hemodynamic response function with each column in a timeseries dataframe.

class emocodes.analysis.features.SummarizeVideoFeatures

This class produces a summary report of video features to help users judge the suitability of each feature for regression analysis. After running the class, a PDF, markdown, and HTML version of the report are saved in the output folder along with a folder of figures.

>>> import emocodes as ec
>>> codes = 'video_features.csv' # DataFrame saved as CSV with feature timeseries
>>> output = './report' # directory to save the report in
>>> report = ec.SummarizeVideoFeatures()
>>> report.compile(codes, output)
compile(self, features, out_dir, convolve_hrf=True, column_names='all', sampling_rate=10, units='s', time_col='index')

This function runs the methods to create a features report.

Parameters
  • features (filepath) – A CSV containing a dataframe object with timeseries data for each feature you want to include in the report

  • out_dir (filepath) – The full or relative path to the folder where you want the report saved to.

  • convolve_hrf (bool) – Setting to convolve each feature with a double-gamma hemodynamic response function (HRF) before reporting

  • column_names (list) – The columns to include in the feature analysis

  • sampling_rate (float) – Sampling rate in Hz (samples per second) of the input data

  • units (str) – Must be ‘s’, ‘ms’, ‘m’, or ‘h’ indicating seconds, milliseconds, minutes, or hours respectively. The units that the time variable (index) is in.

  • time_col (str) – The name of the column to use as time if not the index.

compute_plot_corr(self)
compute_plot_ips(self)
compute_plot_vif(self)
plot_features(self)
emocodes.analysis.features.pairwise_ips(features, column_names='all')

This function computes the pair-wise instantaneous phase synchrony (IPS) between columns in a dataframe. It returns both the mean IPS in a NxN matrix as well as a numpy array that is size NxNxT containing the pair-wise IPS at each time point.

Parameters
  • features (DataFrame) – The dataframe with signals to be analyzed.

  • column_names (list) – List of columns to compare pairwise in the ratings DataFrame. Default is ‘all’.

Returns

  • mean_ips_df (DataFrame) – NxN DataFrame with pairwise feature mean phase synchrony

  • ips_series (numpy array) – NxNxT (feature x feature x time) array with the instantaneous phase synchrony at each timepoint, pairwise

emocodes.analysis.features.pairwise_corr(features, column_names='all')

Computes the pair-wise Spearman correlation coefficient for a set of features.

Parameters
  • features (DataFrame) – DataFrame with signals to be analyzed.

  • column_names (list) – List of columns to compare pairwise in the ratings DataFrame. Default is ‘all’.

Returns

corr_mat_df – Pairwise Spearman correlations organized into a Pandas DataFrame.

Return type

DataFrame

emocodes.analysis.features.vif_collinear(features, column_names='all')

Wraps the pliers variance inflation factor command. Computes the variance inflation factor for the specified columns in a set of features.

Parameters
  • features (DataFrame) – DataFrame with signals to be analyzed.

  • column_names (list) – List of columns to compare pairwise in the ratings DataFrame. Default is ‘all’.

Returns

vif_scores – Pandas Series object containing the VIF scores for each column in column_names.

Return type

Series

emocodes.analysis.features.hrf(time, time_to_peak=5, undershoot_dur=12)

This function creates a hemodynamic response function timeseries.

Parameters
  • time (numpy array) – a 1D numpy array that makes up the x-axis (time) of our HRF in seconds

  • time_to_peak (int) – Time to HRF peak in seconds. Default is 5 seconds.

  • undershoot_dur (int) – Duration of the post-peak undershoot. Default is 12 seconds.

Returns

hrf_timeseries – The y-values for the HRF at each time point

Return type

numpy array

emocodes.analysis.features.hrf_convolve_features(features, column_names='all', time_col='index', units='s', time_to_peak=5, undershoot_dur=12)

This function convolves a hemodynamic response function with each column in a timeseries dataframe.

Parameters
  • features (DataFrame) – A Pandas dataframe with the feature signals to convolve.

  • column_names (list) – List of columns names to use. Default is “all”

  • time_col (str) – The name of the time column to use if not the index. Default is “index”.

  • units (str) – Must be ‘ms’,’s’,’m’, or ‘h’ to denote milliseconds, seconds, minutes, or hours respectively.

  • time_to_peak (int) – Time to peak for HRF model. Default is 5 seconds.

  • undershoot_dur (int) – Undershoot duration for HRF model. Default is 12 seconds.

Returns

convolved_features – The HRF-convolved feature timeseries

Return type

DataFrame