neurochat.nc_datacontainer module

This module implements a container for the NData class.

This module is intended to simplify multi experiment analyses.

@author: Sean Martin; martins7 at tcd dot ie

class neurochat.nc_datacontainer.NDataContainer(share_positions=False, load_on_fly=False, share_stms=False)[source]

Bases: object

Class for storing multiple file locations for NData objects.

Optionally, the NData objects themselves can be stored.

Parameters:
  • share_positions (bool) – Share the same position file between the data objects
  • load_on_fly (bool) – If True, don’t store all the data in memory, instead load it as needed, or on the fly
  • share_stms (bool) – Share the same stimulation file between the data objects
_file_names_dict

A dictionary containing all the file names

Type:Dict
_container

The underlying NData object list

Type:List
_units

The list of all units available for these data objects

Type:List
_unit_count

The number of units available for these data objects

Type:List
_share_positions

Whether to share positional data between the data objects

Type:bool
_share_stms

Whether to share stimulation data between the data objects

Type:bool
_load_on_fly

Whether all the data should be stored in memory or loaded as needed

Type:bool
_smoothed_speed

Stores has the data been smoothed yet. This is usually not needed as NeuroChaT automatically smooths speed

Type:bool
_last_data_pt

A cached version of the last data point used from the collection. This is stored to avoid reloading if the same object is used multiple times in succession.

Type:tuple (int, NData)
class EFileType[source]

Bases: enum.Enum

The different filetypes that can be added to an object.

LFP = 3
Position = 2
STM = 4
Spike = 1
__getitem__(index)[source]

Return the data object with corresponding unit at index.

__iter__()[source]

Iterate over all units in the container.

__len__()[source]

Return the number of units in the collection.

__str__()[source]

Return a string representation of the collection.

add_all_files(spats, spikes, lfps)[source]

Quickly add a list of positions, spikes and lfps.

Parameters:
  • spats (list) – The list of spatial files
  • spikes (list) – The list of spike files
  • lfps (list) – The list of lfp files
Returns:

None

add_axona_files_from_dir(directory, recursive=False, verbose=False, **kwargs)[source]

Go through a directory, extracting Axona files from it automatically.

Parameters:
  • directory (str) – The directory to parse through
  • recursive (bool, optional.) – Defaults to False. Whether to recurse through dirs
  • verbose (bool, optional.) – Defaults to False. Whether to print the files being added.
  • **kwargs (keyword arguments) –
    tetrode_list : list
    list of tetrodes to consider default is 1 to 16
    data_extension : str
    default .set
    cluster_extension : str
    default .cut
    pos_extension : str
    default .txt
    lfp_extension : str
    default .eeg
    re_filter : str
    default None - no regex performed regex string for matching filenames
    save_result : bool
    default True should save the resulting collection to a file
    unit_cutoff : tuple of ints
    don’t consider any recordings with units outside this range e.g. if the cutoff is set at 10, any clustering containing 11 or more units will not be considered valid and won’t be added to the container.
Returns:

List or str – If save_result is true, returns a string indicated where the result was saved Otherwise returns a list of the cluster files which were used.

add_data(data)[source]

Add an NData object to this container.

Parameters:data (NData) – The NData object to add to this container.
add_files(f_type, descriptors)[source]

Add a list of filenames of the given type to the container.

Parameters:
  • f_type (EFileType:) – The type of file being added (Spike, LFP, Position)
  • descriptors (list) – Either a list of filenames, or a tuple of lists in the order (filenames_list, obj_names_list, data_system_list). Filenames should be absolute.
Returns:

None

add_files_from_excel(file_loc, unit_sep=' ')[source]

Add filepaths from an excel file.

These should be setup to be in the order: directory | position file | spike file | unit numbers | eeg extension

Parameters:
  • file_loc (str) – Name of the excel file that contains the data specifications
  • unit_sep (str) – Optional separator character for unit numbers, default ” “
Returns:

excel_info – The raw info parsed from the excel file for further use

get_data(index=None)[source]

Return the NData objects in this collection, or a specific object.

Do not call this with no index if loading data on the fly.

Parameters:index (int) – Optional index to get data at Defaults to None, in which case all data is returned.
Returns:NData or list of NData objects
get_data_at(data_index, unit_index)[source]

Return an NData object from the given indices.

Parameters:
  • data_index (int) – The index in the container to return data at.
  • unit_index (int) – The unit number to set on the returned data.
Returns:

NData – The ndata object at data_index with unit number unit_index

get_file_dict(key=None)[source]

Return the key value filename dictionary for this collection.

Parameters:key (str, optional) – The key to retrieve the filenames for. See EFileType for options. Defaults to None, in which case the whole dict is returned.
Returns:list or dict
get_index_info(idx, absolute=False)[source]

Return the Spike, LFP, Position and Unit info at idx.

get_name_at_idx(idx, ext, opt_end='', base_dir=None, out_dirname='nc_plots')[source]

Get the filename to save an index in the collection to.

Parameters:
  • idx (int) – The index of the collection to get the filename for.
  • ext (str) – The extension to append to the filename.
  • opt_end (str, optional.) – Used like this default_name + opt_end + ext
  • base_dir (str, optional.) – One can specify a directory that all files originated from. It is used like so: Say data1 is in test/foo/data.txt and data2 is in test/bar/data.txt Then passing base_dir as test Would set the names to out_dirname/foo–data.txt out_dirname/bar–data.txt
  • outdirname (str, optional) – The directory to save the plots to. This is relative to the directory of the filename if base dir is None.
Returns:

str

get_num_data()[source]

Return the number of Ndata objects in the container.

get_units(index=None)[source]

Return the units in this collection, optionally at a given index.

Parameters:index (int, optional) – Collection data index to get the units for. Defaults to None. If None all units are returned.
Returns:list – Either a list containing lists of all units in the collection or the list of units for the given data index
list_all_units()[source]

Print all the units in the container.

remove_recordings_units(unit_lb=0, unit_ub=10000, verbose=False)[source]

Remove data objects in this recording with units outside bounds.

Parameters:
  • unit_lb (int, optional.) – Lower bound on the number of allowed units. Defaults to 0.
  • unit_ub (int, optional.) – Upper bound on the number of allowed units. Defaults to 10000.
  • verbose (bool, optional.) – Whether to print extra information on what is being removed. Defaults to False.
Returns:

None

set_units(units='all')[source]

Set the list of units for the collection.

Parameters:units (list or str:) – If a list, indicates the units to use for each data object stored in the collection. “all” is accepted as a single element. Otherwise, a string “all” is expected, which sets all available units picked up from clustering files.
setup()[source]

Perform data initialisation based on the input filenames.

sort_units_spatially(should_sort_list=None, mode='vertical')[source]

Sort the units in the collection based on the place field centroid.

Parameters:
  • should_sort_list (list) – Optional list of boolean values indicating what objects
  • mode (str) – “horizontal” or “vertical”, indicating what axis to sort on.
Returns:

None

string_repr(pretty=True)[source]

Return a string representation of this class.

Parameters:pretty (str, Default True) – Should return a pretty version or all the info.
Returns:str
subsample(key)[source]

Return a subsample of the original data collection.

This subsample is not a reference, but a deep copy

Parameters:key (Slice, list of int, or int) – How to sample the original collection
Returns:NDataContainer – The deep copied subsample
class neurochat.nc_datacontainer.NDataContainerIterator(container)[source]

Bases: object

A custom iterator for the NDataContainer class.

__next__()[source]

Increase the container index by 1.