Buffer API Class

physiolabxr.utils.buffers

class physiolabxr.utils.buffers.DataBuffer

A class to store data from multiple streams.

Variables:
buffer : dict

a dictionary to store data from multiple streams, contains ‘stream_names’, (‘frames’ , ‘timestamps’)

stream_name_buffer_sizes : dict

a dictionary to store buffer size for each stream

__init__(stream_buffer_sizes)

Initializes the data buffer.

Parameters:
stream_buffer_sizes : dict

a dictionary to specify buffer size

__getitem__(key)

get data using a key.

Parameters:
key : str

key to get data

keys()

get keys of the buffer.

Returns:

keys of the buffer

Return type:

list

get_stream(stream)

return buffer from a specific stream.

Parameters:
stream : str

stream

Returns:

buffer from a specific stream

Return type:

any

get_data(stream_name)

get data from a specific stream name.

Parameters:
stream_name : str

name of the stream

Returns:

data from a specific stream name

Return type:

numpy.ndarray

get_timestamps(self, stream_name)

get timestamps from a specific stream name.

Parameters:
stream_name : str

name of the stream

Returns:

timestamps from a specific stream name

Return type:

numpy.ndarray

update_buffer(data_dict)

Updates the buffer with data from a dictionary.

Parameters:
data_dict : dict

a dictionary that containing ‘stream_name’, ‘frames’ and ‘timestamps’

update_buffers(data_buffer)

Updates the buffer with data from another buffer.

Parameters:
data_buffer : DataBuffer

Another DataBuffer object.

update_buffer_size(stream_name, size)

Updates the buffer size from stream.

Parameters:
stream_name : str

name of the stream

size : str

size of the data buffer

clear_buffer()

Clear the entire buffer.

clear_stream_buffer(stream_name)

Clear buffer from a specific stream.

Parameters:
stream_name : str

name of the stream

clear_stream_buffer_data(stream_name)
Remove the buffered data for a stream without removing the existing keys.

The data and timestamps array will instead become empty arraries

Parameters:
stream_name : str

name of the stream

clear_buffer_data()
Remove buffered data for all streams without removing the existing keys.

The data and timestamps array will instead become empty arraries

clear_stream_up_to(stream_name, timestamp)

Remove buffered data of a specific stream up to a specific timestamp. The resulting timestamp is guaranteed to be greater than the given cut-to timestamp.

Parameters:
stream_name : str

name of the stream

timestamp : float

timestamp to clear up to

clear_stream_up_to_index(stream_name, cut_to_index)

Clear data of a specific stream up to a specific index.

Parameters:
stream_name : str

name of the stream

cut_to_index : int

index to clear up to

clear_up_to(timestamp, ignores=())

Clear data in all streams up to a specific timestamp, optionally ignoring specified streams. The resulting timestamp is guaranteed to be greater than the given cut-to timestamp.

Parameters:
timestamp : float

timestamp to clear up to

ignores : list

list of stream names to ignore