BeForRecord#

class befordata.BeForRecord(dat, sampling_rate, columns=<factory>, sessions=<factory>, time_column='', meta=<factory>)#

Data Structure for handling behavioural force measurements

Parameters:
  • dat (Pandas Dataframe) – data

  • sample_rate (float) – the sampling rate of the force measurements

  • columns (list of strings) – the columns in ‘dat’ that comprise the force measurements

  • sessions (list of integer) – sample numbers at which a new recording session starts, if the exists

  • time_column – str = “”

  • meta (dictionary) – any kind of meta data

Methods

add_column(name, data[, is_force_column])

Add data column (in place).

add_session(dat)

Adds data (dataframe) as a new recording

drop_column(name)

Drop a column for the data (in place)

extract_epochs(column, zero_samples, n_samples)

extracts epochs from BeForRecord

find_samples_by_time(times)

returns sample index (i) of the closes time in the BeForRecord.

from_arrow(tbl[, sampling_rate, columns, ...])

Creates BeForRecord struct from pyarrow.Table

get_data([columns, session])

Returns data of a particular column and/or a particular session

get_forces([session])

Returns force data of a particular session

n_forces()

Number of force columns

n_samples()

Number of sample in all sessions

n_sessions()

Number of recoding sessions

session_samples(session)

tuple represents the range of the samples (from, to) of this sessions

time_stamps()

The time stamps (numpy array)

to_arrow()

converts BeForRecord to pyarrow.Table

n_samples()#

Number of sample in all sessions

Return type:

int

n_forces()#

Number of force columns

Return type:

int

n_sessions()#

Number of recoding sessions

Return type:

int

time_stamps()#

The time stamps (numpy array)

Creates time stamps, of they are not define in the data

Return type:

ndarray[tuple[int, ...], dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]

get_data(columns=None, session=None)#

Returns data of a particular column and/or a particular session

Return type:

DataFrame | Series

get_forces(session=None)#

Returns force data of a particular session

Return type:

DataFrame | Series

add_session(dat)#

Adds data (dataframe) as a new recording

Dataframe has to have the same columns as the already existing data

add_column(name, data, is_force_column=True)#

Add data column (in place).

Parameters:
  • name (str) – columns name

  • data (List or Pandas Series) – column data, that has to have the correct length

  • is_force_column (bool, optional) – set this to False, if the added data do not comprise force measurements (default=true)

drop_column(name)#

Drop a column for the data (in place)

session_samples(session)#

tuple represents the range of the samples (from, to) of this sessions

Return type:

Tuple[int, int]

find_samples_by_time(times)#

returns sample index (i) of the closes time in the BeForRecord. Takes the next larger element, if the exact time could not be found. :rtype: ndarray[tuple[int, ...], dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]

\[\text{time_stamps}[i-1] <= t < \text{time_stamps}[i]\]
Parameters:

times (ArrayLike) – the sorted array of time stamps

extract_epochs(column, zero_samples, n_samples, n_samples_before=0, design=Empty DataFrame Columns: [] Index: [])#

extracts epochs from BeForRecord

Return type:

BeForEpochs

Parameters:
  • column (str) – name of column containing the force data to be used

  • zero_samples (List[int]) – zero sample that define the epochs

  • n_samples (int) – number of samples to be extract (from zero sample on)

  • n_samples_before (int, optional) – number of samples to be extracted before the zero sample (default=0)

  • design (pd.DataFrame, optional) – design information

Notes

use find_times to detect zero samples with time-based

to_arrow()#

converts BeForRecord to pyarrow.Table

metadata of schema will be defined. Files can converted back to BeForRecord struct using BeForRecord.from_arrow()

Return type:

Table

Return type:

pyarrow.Table

Examples

>>> from pyarrow import feather
>>> feather.write_feather(data.to_arrow(), "filename.feather",
                  compression="lz4", compression_level=6)
static from_arrow(tbl, sampling_rate=None, columns=None, sessions=None, time_column=None, meta=None)#

Creates BeForRecord struct from pyarrow.Table

Return type:

BeForRecord

Parameters:

tbl (pyarrow.Table)

Examples

>>> from pyarrow import feather
>>> dat = feather.read_table("my_force_data.feather")
>>> dat = BeforeData.from_arrow(dat)