Skip to content

module video

Basic video tracking and behavior class that houses data

Global Variables

  • global_config
  • FEATURE_MAKERS
  • UNIT_DICT

function create_metadata

create_metadata(tracking_files: list, **kwargs) → dict

Prepare a metadata dictionary for defining a ExperimentDataFrame.

Only required argument is list of pose tracking file names.

Any other keyword argument must be either a non-iterable object (e.g. a scalar parameter, like FPS) that will be copied and tagged to each of the pose tracking files, or an iterable object of the same length of the list of pose tracking files. Each element in the iterable will be tagged with the corresponding pose-tracking file.

Args:

  • tracking_files: List of pose tracking files
  • **kwargs: described as above

Returns: Dictionary whose keys are pose-tracking file names, and contains a dictionary with key,values containing the metadata provided


function create_dataset

create_dataset(
    input: dict = None,
    part_renamer: dict = None,
    animal_renamer: dict = None,
    video: list = None,
    labels: list = None,
    **kwargs
) → DataFrame

Creates DataFrame that houses pose-tracking data and behavior annotations, along with relevant metadata, features and behavior annotation labels.

Args:

  • input: String OR list of strings with path(s) to tracking file(s). OR Dictionary whose keys are pose tracking files, and value is a dictionary of associated metadata for that video (see create_metadata if using this construction option)
  • part_renamer: Default None. Dictionary that can rename body parts from tracking files if needed (for feature creation, e.g.)
  • animal_renamer: Default None. Dictionary that can rename animals from tracking files if needed
  • **kwargs: Any other data to associate with each of the tracking files. This includes label files, and other metadata. Any list-like arguments of appropriate length are zipped (associated) with each tracking file. See How To guide for more information.

Returns: DataFrame object. This is a pandas DataFrame with additional metadata and methods.


function load_experiment

load_experiment(fn_in: str) → DataFrame

Load DataFrame from file.

Args:

  • fn_in: path to file to load

Returns: DataFrame object from pickle file


function get_sample_openfield_data

get_sample_openfield_data()

Load a sample dataset of 1 mouse in openfield setup. The video is the sample that comes with DLC.

Returns: DataFrame with the corresponding tracking and behavior annotation files


function add_randomforest_predictions

add_randomforest_predictions(df: DataFrame)

Perform cross validation of a RandomForestClassifier to predict behavior based on activated features. Can be useful to assess model performance, and if you have enough data.

Args:

  • df: Dataframe housing features and labels to perform classification. Will perform leave-one-video-out cross validation hence dataframe needs at least two videos to run.

Returns: None. Modifies df in place, adding column 'prediction' with model predictions in it.


class EthologyMetadataAccessor

method __init__

__init__(pandas_obj: DataFrame)

property details


property label_key


property n_videos


property reverse_label_key


property videos


class EthologyFeaturesAccessor

method __init__

__init__(pandas_obj: DataFrame)

property active


method activate

activate(name: str) → list

Add already present columns in data frame to the feature set.

Args:

  • name: string for pattern matching -- any feature that starts with this string will be added

Returns: List of matched columns (may include columns that were already activated).


method add

add(
    feature_maker: Any,
    featureset_name: str = None,
    add_to_features=True,
    required_columns=[],
    **kwargs
) → list

Compute features to dataframe using Feature object. 'featureset_name' will be prepended to new columns, followed by a double underscore.

Args:

  • featuremaker: A Feature object that houses the feature-making function to be executed and a list of required columns that must in the dataframe for this to work
  • featureset_name: Name to prepend to the added features
  • add_to_features: Whether to add to list of active features (i.e. will be returned by the .features property)

Returns: List of new columns that are computed


method deactivate

deactivate(name: str) → list

Remove columns from the feature set.

Args:

  • name: string for pattern matching -- any feature that starts with this string will be removed

Returns: List of removed columns.


method deactivate_cols

deactivate_cols(col_names: list) → list

Remove provided columns from set of feature columns.

Args:

  • col_names: list of column names

Returns: The columns that were removed from those designated as features.


method regex

regex(pattern: str) → list

Return a list of column names that match the provided regex pattern.

Args:

  • pattern: a regex pattern to match column names to

Returns: list of column names


class EthologyPoseAccessor

method __init__

__init__(pandas_obj: DataFrame)

property animal_setup


property animals


property body_parts


property raw_track_columns


class EthologyMLAccessor

method __init__

__init__(pandas_obj: DataFrame)

property features


property fold_cols


property folds


property group


property label_cols


property labels


property splitter


class EthologyIOAccessor

method __init__

__init__(pandas_obj: DataFrame)

method load

load(fn_in: str) → DataFrame

Load ExperimentDataFrame object from pickle file.

Args:

  • fn_in: path to load pickle file from.

Returns: None. Data in this object is populated with contents of file.


method save

save(fn_out: str) → None

Save ExperimentDataFrame object with pickle.

Args:

  • fn_out: location to write pickle file to

Returns: None. File is saved to path.


method save_movie

save_movie(
    label_columns: list,
    path_out: str,
    video_filenames: list = None
) → None

Given columns indicating behavior predictions or whatever else, make a video with these predictions overlaid.

ExperimentDataFrame metadata must have the keys 'video_file', so that the video associated with each set of pose tracks is known.

Args:

  • label_columns: list or dict of columns whose values to overlay on top of video. If dict, keys are the columns and values are the print-friendly version.
  • path_out: the directory to output the videos too
  • video_filenames: list or string. The set of videos to use. If not provided, then use all videos as given in the metadata.

Returns: None. Videos are saved to 'path_out'


method to_dlc_csv

to_dlc_csv(base_dir: str, save_h5_too: bool = False) → None

Save ExperimentDataFrame tracking files to DLC csv format.

Only save tracking data, not other computed features.

Args:

  • base_dir: base_dir to write DLC csv files to
  • save_h5_too: if True, also save the data as an h5 file

Returns: None. Files are saved to path.


This file was automatically generated via lazydocs.