Skip to content

Latest commit

 

History

History
114 lines (79 loc) · 4.48 KB

analysis_library.md

File metadata and controls

114 lines (79 loc) · 4.48 KB

MAP Analysis, Visualization, Data Export

This document presents the modular, built-in functions available for analysis, plotting, and data export.

The goal is for users to reuse and extend on the available library, avoiding "reinvent the wheel".

Analysis Functions

Compute unit PSTH

from pipeline.psth import compute_unit_psth

def compute_unit_psth(unit_key, trial_keys, per_trial=False):
"""
Compute unit-level psth for the specified unit and trial-set - return (time,)
If per_trial == True, compute trial-level psth - return ((trial x time), time_vec)
:param unit_key: key of a single unit to compute the PSTH for
:param trial_keys: list of all the trial keys to compute the PSTH over
"""

Compute coding direction (CD)

from pipeline.psth import compute_coding_direction

def compute_coding_direction(contra_psths, ipsi_psths, time_period=None):
    """
    Coding direction here is a vector of length: len(unit_keys)
    This coding direction vector (vcd) is the normalized difference between contra-trials firing rate
    and ipsi-trials firing rate per unit, within the specified time period
    :param contra_psths: unit# x (trial-ave psth, psth_edge)
    :param ipsi_psths: unit# x (trial-ave psth, psth_edge)
    :param time_period: (time_from, time_to) in seconds, relative to go-cue
    """

Compute CD-projected unit PSTHs

from pipeline.psth import compute_CD_projected_psth

def compute_CD_projected_psth(units, time_period=None):
"""
Routine for Coding Direction computation on all the units in the specified unit_keys
Coding Direction is calculated in the specified time_period
Unit PSTH are computed over no early-lick, correct-response trials
:param: unit_keys - list of unit_keys
:param time_period: (time_from, time_to) in seconds, relative to go-cue
:return: coding direction unit-vector,
         contra-trials CD projected trial-psth,
         ipsi-trials CD projected trial-psth
         psth time-stamps
"""

Get units' hemisphere (helper function):

from pipeline.util import _get_units_hemisphere

def _get_units_hemisphere(units):
"""
Return the hemisphere ("left" or "right") that the specified units belong to,
 based on the targeted insertion location - "ephys.ProbeInsertion.InsertionLocation"
:param units: either a list of unit_keys or a query of the ephys.Unit table
:return: "left" or "right"
"""

Get units' clustering method (helper function):

from pipeline.util import _get_clustering_method

def _get_clustering_method(probe_insertion):
"""
Return the "clustering_method" used to estimate the all the units for the provided "probe_insertion"
:param probe_insertion: an "ephys.ProbeInsertion" key
:return: clustering_method
"""

Visualization library

The MAP project provides a library of plotting functions, which are used to generate all the result figures in the report schema, as presented here

Detailed descriptions and demonstrations of this plotting library are presented in the following 3 notebooks:

  • Ephys result visualization notebook
  • Behavior and tracking visualization notebook
  • Histology probe track visualization notebook

Data Export

This MAP-pipeline features a data export function, to MATLAB (.mat) format.

Data are export per "probe insertion", one .mat file represents all data from one probe insertion.

from pipeline.export import export_recording

def export_recording(insert_keys, output_dir='./', filename=None, overwrite=False):
'''
Export a 'recording' (or a list of recording) (probe specific data + related events) to a file.

Parameters:

  - insert_keys: one or a list of ephys.ProbeInsertion.primary_key
    currently: {'subject_id', 'session', 'insertion_number'})

  - output_dir: directory to save the file at (default to be the current working directory)

  - filename: an optional output file path string. If not provided,
    filename will be autogenerated using the 'mkfilename'
    function.
    Note: if exporting a list of probe keys, filename will be auto-generated
'''

See this demo notebook for example export usage.