moseq2_pca.helpers package

Helpers - Data Module

Helper functions for reading and loading PCA data.

moseq2_pca.helpers.data.get_pca_paths(config_data, output_dir)

Helper function for changepoints_wrapper to perform data-path existence checks. Returns paths to saved pre-trained PCA components and PCA Scores files.

Args: config_data (dict): dict of relevant PCA parameters (image filtering etc.) output_dir (str): path to directory to store PCA data

Returns: config_data (dict): updated config_data dict with the pc component and pc score paths pca_file_components (str): path to trained pca file pca_file_scores (str): path to pca_scores file

moseq2_pca.helpers.data.get_pca_yaml_data(pca_yaml)

Reads PCA yaml file and returns enclosed metadata.

Args: pca_yaml (str): path to pca.yaml

Returns: use_fft (bool): indicates whether to use FFT clean_params (dict): dict of image filtering parameters mask_params (dict): dict of mask parameters) missing_data (bool): indicates whether to use mask_params

moseq2_pca.helpers.data.load_pcs_for_cp(pca_file, config_data)

Load computed Principal Components for Model-free Changepoint Analysis.

Args: pca_file (str): path to pca h5 file to read PCs config_data (dict): config parameters

Returns: pca_file (str): path to pca components changepoint_params (dict): dict of relevant changepoint parameters missing_data (bool): Indicates whether to use mask_params for missing data pca mask_params (dict): Mask parameters to use when computing CPs

Helpers - Wrapper Module

Wrapper functions for PCA.

moseq2_pca.helpers.wrappers.apply_pca_wrapper(input_dir, config_data, output_dir, output_file)

Wrapper function to obtain PCA Scores.

Args: input_dir (int): path to directory containing all h5+yaml files config_data (dict): dict of relevant PCA parameters (image filtering etc.) output_dir (str): path to directory to store PCA data output_file (str): pca model filename

Returns: config_data (dict): updated config_data variable to write back in GUI API success (bool): flag to indicate whether the PCA scores were computed successfully

moseq2_pca.helpers.wrappers.clip_scores_wrapper(pca_file, clip_samples, from_end=False)

Clip PCA scores from the beginning or end overwriting the original results.

Args: pca_file (str): Path to PCA scores. clip_samples (int): number of samples to clip from beginning or end from_end (bool): if true clip from end rather than beginning

moseq2_pca.helpers.wrappers.compute_changepoints_wrapper(input_dir, config_data, output_dir, output_file)

Wrapper function to compute model-free Changepoints.

Args: input_dir (int): path to directory containing all h5+yaml files config_data (dict): dict of relevant PCA parameters (image filtering etc.) output_dir (str): path to directory to store PCA data output_file (str): pca model filename

Returns: config_data (dict): updated config_data variable to write back in GUI API

moseq2_pca.helpers.wrappers.load_and_check_data(input_dir, output_dir, config_data)

Load relevant h5 and yaml files found in given input directory, then check for timestamps and warn the user if they are missing.

Args: input_dir (str): input directory containing extracted h5 files to find output_dir (str): directory name to save pca results

Returns: output_dir (str): output directory path h5s (list): list of found h5 files yamls (list): list of corresponding yaml files dicts (list): list of corresponding metadata.json files

moseq2_pca.helpers.wrappers.train_pca_wrapper(input_dir, config_data, output_dir, output_file)

Wrapper function to train PCA.

Args: input_dir (int): path to directory containing all h5+yaml files config_data (dict): dict of relevant PCA parameters (image filtering etc.) output_dir (str): path to directory to store PCA data output_file (str): pca model filename

Returns: config_data (dict): updated config_data variable to write back in GUI API