module io
Loading and saving tracking and behavior annotation files
Global Variables
- DEFAULT_BUFFER_SIZE
- SEEK_SET
- SEEK_CUR
- SEEK_END
- XY_IDS
- XYLIKELIHOOD_IDS
function uniquifier
uniquifier(seq: Sequence)
Return a sequence (e.g. list) with unique elements only, but maintaining original list order
function save_sklearn_model
save_sklearn_model(model, fn_out: str)
Save sklearn model to file
Args:
model
: sklearn model to savefn_out
: filename to save to
function load_sklearn_model
load_sklearn_model(fn_in: str)
Load sklearn model from file
Args:
fn_in
: filename to load from
Returns: the loaded sklearn model
function read_DLC_tracks
read_DLC_tracks(
fn_in: str,
part_renamer: dict = None,
animal_renamer: dict = None,
read_likelihoods: bool = True,
labels: DataFrame = None
) → tuple
Read in tracks from DLC.
Args:
fn_in
: csv or h5 file that has DLC trackspart_renamer
: dictionary to rename body parts, if neededanimal_renamer
: dictionary to rename animals, if neededread_likelihoods
: default True. Whether to attach DLC likelihoods to table
Returns: Pandas DataFrame with (n_animals2n_body_parts) columns plus with filename and frame, List of body parts, List of animals, Columns names for DLC tracks (excluding likelihoods, if read in), Scorer
function read_sleap_tracks
read_sleap_tracks(
fn_in: str,
part_renamer: dict = None,
animal_renamer: dict = None,
read_likelihoods: bool = True,
labels: DataFrame = None
) → tuple
Read in tracks from SLEAP.
Args:
fn_in
: csv or h5 file that has sleap trackspart_renamer
: dictionary to rename body parts, if neededanimal_renamer
: dictionary to rename animals, if neededread_likelihoods
: default True. Whether to attach DLC likelihoods to table
Returns: Pandas DataFrame with (n_animals2n_body_parts) columns plus with filename and frame, List of body parts, List of animals, Columns names for DLC tracks (excluding likelihoods, if read in), Scorer
function read_NWB_tracks
read_NWB_tracks(
fn_in: str,
part_renamer: dict = None,
animal_renamer: dict = None,
read_likelihoods: bool = True
) → tuple
Read in tracks from NWB PoseEstimiationSeries format (something saved using the DLC2NWB package).
Args:
fn_in
: nwb file that has the tracking informationpart_renamer
: dictionary to rename body parts, if neededanimal_renamer
: dictionary to rename animals, if neededread_likelihoods
: default True. Whether to attach DLC likelihoods to table
Returns: Pandas DataFrame with (n_animals2n_body_parts) columns plus with filename and frame, List of body parts, List of animals, Columns names for pose tracks (excluding likelihoods, if read in), Scorer
function save_DLC_tracks_h5
save_DLC_tracks_h5(df: DataFrame, fn_out: str) → None
Save DLC tracks in h5 format.
Args:
df
: Pandas dataframe to savefn_out
: Where to save the dataframe
function load_data
load_data(fn: str)
Load an object from a pickle file
Args:
fn
: The filename
Returns: The pickled object.
function get_sample_nwb_paths
get_sample_nwb_paths()
Get path to a sample NWB file with tracking data for testing and dev purposes.
Returns: Path to a sample NWB file.
function get_sample_sleap_paths
get_sample_sleap_paths()
Get path to a sample SLEAP h5 file with tracking data for testing and dev purposes.
Returns: Path to a sample SLEAP file.
function get_sample_data_paths_dlcboris
get_sample_data_paths_dlcboris()
Get path to sample data files provided with package.
Returns: (tuple) list of DLC tracking file, list of boris annotation files
function get_sample_data
get_sample_data()
Load a sample dataset of 5 mice social interaction videos. Each video is approx. 5 minutes in duration
Returns: (ExperimentDataFrame) Data frame with the corresponding tracking and behavior annotation files
function read_boris_annotation
read_boris_annotation(
fn_in: str,
fps: int,
duration: float,
behav_labels: list = None
) → tuple
Read behavior annotation from BORIS exported csv file.
This will import behavior types specified (or all types, if behavior_list is None) and assign a numerical label to each. Overlapping annotations (those occurring simulataneously) are not supported. Any time the video is annotated as being in multiple states, the last state will be the one labeled.
Args:
fn_in
: The filename with BORIS behavior annotations to loadfps
: The frames per second of the videoduration
: The duration of the video in secondsbehav_labels
: If provided, only import behaviors with these names. Default = None = import everything.
Returns: A dictionary of numpy arrays which gives, for all frames, which behavior is occuring. 0 = no behavior, 1 = behavior.
function create_behavior_labels
create_behavior_labels(boris_files: list)
Create behavior labels from BORIS exported csv files.
Args:
boris_files
: List of BORIS exported csv files
Returns: A dictionary with keys the numerical labels and values the names of the behaviors.
class BufferedIOBase
Base class for buffered IO objects.
The main difference with RawIOBase is that the read() method supports omitting the size argument, and does not have a default implementation that defers to readinto().
In addition, read(), readinto() and write() may raise BlockingIOError if the underlying raw stream is in non-blocking mode and not ready; unlike their raw counterparts, they will never return None.
A typical implementation should not inherit from a RawIOBase implementation, but wrap one.
class IOBase
The abstract base class for all I/O classes, acting on streams of bytes. There is no public constructor.
This class provides dummy implementations for many methods that derived classes can override selectively; the default implementations represent a file that cannot be read, written or seeked.
Even though IOBase does not declare read, readinto, or write because their signatures will vary, implementations and clients should consider those methods part of the interface. Also, implementations may raise UnsupportedOperation when operations they do not support are called.
The basic type used for binary data read from or written to a file is bytes. Other bytes-like objects are accepted as method arguments too. In some cases (such as readinto), a writable object is required. Text I/O classes work with str data.
Note that calling any method (except additional calls to close(), which are ignored) on a closed stream should raise a ValueError.
IOBase (and its subclasses) support the iterator protocol, meaning that an IOBase object can be iterated over yielding the lines in a stream.
IOBase also supports the :keyword:with
statement. In this example, fp is closed after the suite of the with statement is complete:
with open('spam.txt', 'r') as fp: fp.write('Spam and eggs!')
class RawIOBase
Base class for raw binary I/O.
class TextIOBase
Base class for text I/O.
This class provides a character and line based interface to stream I/O. There is no readinto method because Python's character strings are immutable. There is no public constructor.
class UnsupportedOperation
This file was automatically generated via lazydocs.