Data Structures#
Description#
|
Data Structure for handling behavioural force measurements. |
|
Behavioural force data organized epoch-wise. |
- BeForRecord
Represents a single continuous recording of force data, including metadata such as sampling rate, channel information, and experimental annotations. BeForRecord supports data cleaning, resampling, and extraction of epochs, and provides convenient access to raw and processed force signals.
The data structure has the following attributes:
`dat`: DataFrame containing force measurements and optionally a time column.
`sampling_rate`: Sampling rate of the force measurements (Hz).
`sessions`: List of sample indices where new recording sessions start.
`time_column` (optional): Name of the column containing time stamps (if any).
`meta` (optional): Arbitrary metadata associated with the record.
- BeForEpochs
A container class for managing multiple epochs of force data. Each epoch represents a segment of continuous force measurements, typically corresponding to a trial or experimental condition. BeForEpochs provides methods for slicing, indexing, and batch-processing epochs, as well as for loading and saving epoch data from various formats.
The data structure has the following attributes:
`dat`: 2D numpy array containing the force data (epochs x samples).
`sampling_rate`: Sampling rate of the force measurements (Hz).
`design`: DataFrame containing design/metadata for each epoch.
`zero_sample`: Sample index representing the sample of the time zero within each epoch (default: 0).
`baseline` (optional): 1D numpy array containing baseline values for each epoch at zero_sample.
`meta` (optional): Arbitrary metadata associated with the epochs.
BeForRecord#
- class BeForRecord(dat, sampling_rate, sessions=<factory>, time_column='', meta=<factory>)#
Data Structure for handling behavioural force measurements.
This data structure encapsulates force measurement data, session information, and metadata, providing methods for session management, force extraction, and epoch extraction.
- Parameters:
- datpd.DataFrame
The main data table containing force measurements and optionally a time column.
- sampling_ratefloat
The sampling rate (Hz) of the force measurements.
- sessionslist of int, optional
List of sample indices where new recording sessions start. Defaults to [0].
- time_columnstr, optional
Name of the column containing time stamps. If empty, time stamps are generated.
- metadict, optional
Arbitrary metadata associated with the record.
Methods
append
(dat[, new_session])Appends new recordings to the existing data.
find_samples_by_time
(times)Find the indices of samples corresponding to or immediately following the given time stamps.
forces
([session])Returns force data for all samples or a specific session.
n_forces
()Returns the number of force columns.
Returns the total number of samples across all sessions.
Returns the number of recording sessions.
session_range
(session)Returns the sample index range for a specific session.
Returns a list of sample index ranges for all sessions.
Returns the time stamps as a numpy array.
- n_samples()#
Returns the total number of samples across all sessions.
- Return type:
int
- n_forces()#
Returns the number of force columns.
- Return type:
int
- n_sessions()#
Returns the number of recording sessions.
- Return type:
int
- time_stamps()#
Returns the time stamps as a numpy array.
If a time column is specified, its values are returned. Otherwise, time stamps are generated based on the sampling rate.
- Return type:
NDArray
- forces(session=None)#
Returns force data for all samples or a specific session.
- Return type:
DataFrame
|Series
- Parameters:
- sessionint or None, optional
If specified, returns force data for the given session index. If None, returns force data for all samples.
- append(dat, new_session=False)#
Appends new recordings to the existing data.
- Return type:
None
- Parameters:
- datpd.DataFrame
DataFrame containing the new data to append. Must have the same columns as the current data.
- new_sessionbool, optional
If True, records will be marked as new session in the sessions list. Default is False.
- session_ranges()#
Returns a list of sample index ranges for all sessions. Each range corresponds to the sample indices of a session.
- Return type:
List
[range
]
- session_range(session)#
Returns the sample index range for a specific session.
- Return type:
range
- Parameters:
- sessionint
Session index.
- find_samples_by_time(times)#
Find the indices of samples corresponding to or immediately following the given time stamps.
This method searches for the indices of time stamps in the dataset that are equal to or the next larger value for each time in the input array. If an exact match is not found,the index of the next larger time stamp is returned.
- Return type:
NDArray
- Parameters:
- timesArrayLike
Array of time stamps to search for.
Notes
Uses numpy.searchsorted with ‘left’ side.
BeForEpochs#
- class BeForEpochs(dat, sampling_rate, design=<factory>, zero_sample=0, baseline=<factory>, meta=<factory>)#
Behavioural force data organized epoch-wise.
This data structure stores and manages behavioural force data segmented into epochs. Each epoch is represented as a row in a 2D numpy array, with columns corresponding to samples within that epoch. Sampling rate, experimental design, baseline values, zero sample index and additional optional metadata are also represented.
- Parameters:
- datNDArray[np.floating]
2D numpy array containing the force data. Each row is an epoch, each column a sample.
- sampling_ratefloat
Sampling rate of the force measurements (Hz).
- designpd.DataFrame
DataFrame containing design/metadata for each epoch (one row per epoch).
- zero_sampleint, optional
Sample index representing the sample of the time zero within each epoch (default: 0).
- baselineNDArray[np.float64], optional
1D numpy array containing baseline values for each epoch at zero_sample.
- metadict, optional
Arbitrary metadata associated with the record.
Methods
Check if baseline adjustment has been applied.
n_epochs
()Returns the number of epochs.
Returns the number of samples per epoch.
- n_epochs()#
Returns the number of epochs.
- Return type:
int
- n_samples()#
Returns the number of samples per epoch.
- Return type:
int
- is_baseline_adjusted()#
Check if baseline adjustment has been applied.
Returns True if baseline adjustment has been applied, False otherwise.
- Return type:
bool