Core of this library: DataChunk, RecordMaster, Data_Pipe, and import/export of reM
%load_ext autoreload
%autoreload 2

class DataChunk[source]

DataChunk(data, idx, group, fill=0) :: ndarray

Base brick of data. Derived from np.ndarray params:

- data: The ndarray with shape (time, ...)
- idx: Index of the start of the DataChunk in the record.
- group: group of the DataChunk in {stim, sync, cell, data}
- fill: Default filling value.
np.random.seed(1)
dc = DataChunk(np.random.rand(100), 0, "data", fill=0)
test_eq(len(dc), 100)
test_eq(dc.idx, 0)
test_eq(dc.group, "data")
test_eq(dc.fill, 0)

class ContiguousRecord[source]

ContiguousRecord(length:int, signals:DataChunk, main_tp:DataChunk, frame_rate:int=60)

Representation of a contiguous recording session to store DataChunk of various sources under a single time reference. DataChunk are stored under a name in one of the groups "sync","stim","data" and "cell".

A name can contain multiple DataChunk if those are not overlapping in time.

Each ContiguousRecord contains in the group "sync" two master DataChunk, one for signals to be recorded across acquisition device to syncronize them, one for timepoints of these signals for the main device and are called respectively "signals" and "main_tp".

np.random.seed(1)
dc_tp      = DataChunk(np.arange(0,10000,50), 0, "sync", fill=0)
dc_signals = DataChunk(np.random.rand(100), 10, "sync", fill=0)
dc         = DataChunk(np.random.rand(100), 111, "cell", fill=0)

cr = ContiguousRecord(len(dc_tp), dc_signals, dc_tp)
test_eq(cr.dataset_intersect([dc_signals], dc_tp), True)
test_eq(cr.dataset_intersect([dc_signals], dc),    False)

test_eq(cr.get_slice("signals"),    [slice(10, 110, None)])
cr["test"] = dc
test_eq(cr.get_names_group("cell"),    ['test'])
test_eq(cr.get_names_group("sync"),    ['signals', 'main_tp'])

test_eq(len(cr["main_tp"]),    200)
cr.set_slice(slice(100,200,1))
test_eq(len(cr["main_tp"]),    100)
cr.set_slice(None)
test_eq(len(cr["main_tp"]),    200)

class RecordMaster[source]

RecordMaster(reference_data_list:Sequence[Tuple[DataChunk, DataChunk]], frame_rate=60) :: list

The RecordMaster class is the top level object managing all timeseries. It uses a list of ContiguousRecord to represent possible discontinuted data records.

The main aim of the RecordMaster is to store the various data stream of an experiment under a unique time reference, to ease the processing of the data.

A RecordMaster is created by providing to it a list of (timepoints, signals) arrays of identical lenght. This serves as reference to align other DataChunks with the signals at the given timepoints. Multiple tuples represent uncontiguous sequences of data in a same record. The timepoints must be evenly spaced (regular).

params:

- reference_data_list: list of (timepoints, signals) arrays.
- frame_rate: Frame rate in Hz, or list of frame rates matching len(reference_data_list)
np.random.seed(1)
dc_tp      = DataChunk(np.arange(0,10000,50), 0, "sync", fill=0)
dc_signals = DataChunk(np.random.rand(100), 10, "sync", fill=0)
dc         = DataChunk(np.random.rand(100), 111, "cell", fill=0)

reM = RecordMaster([(dc_signals, dc_tp)])
reM.plot()

class Data_Pipe[source]

Data_Pipe(record_master:RecordMaster, data_names:Union[str, list], target_names:Union[str, list]=None, cast_to_np=False)

A Data_Pipe is used to query data from a RecordMaster. By adding/substracting portions of the record using DataChunk names, it creates a mask over which specified DataChunks are retrivied as a dictionary from the Data_Pipe.

params:

- record_master: the RecordMaster from which to retrieve data
- data_names: Name, or list of names of the DataChunk to retrieve once the masking process is done.
- target_names: Alias, or list of alias to give to the DataChunk in the retrieved dictionnary.
- cast_to_np: boolean to cast the piped data into a numpy array. Can be set directly too in self.cast_to_np

export_record[source]

export_record(path, record_master)

Export a Record_Master object to an h5 file, readable outside of this library.

params:

- path: path of the file to be saved
- record_master: RecordMaster to save

import_record[source]

import_record(path)

Import a Record_Master from an h5 file saved by the export_record function of this library.

params:

- path: path of the RecordMaster to import