Provides a two-dimensional circular buffer with homogeneous elements
See other classes’ docstrings for more information:
Provides a two-dimensional circular buffer with homogeneous elements
The buffer can be used simultaneously by several processes, because both data and metadata are stored in a single sharectypes byte array. First, the buffer object is created and initialized in one of the processes. Second, its raw array is shared with others. Third, those processes create their own RingBuffer objects and initialize them so that they all point to the same shared raw array (see initialize_from_raw method’s docstring).
See also
Notes
The buffer consists of a buffer interface (self) and the raw sharectypes byte array which has header, data, and pocket subsections (self.raw).
1. header section Contains the metadata such as size of the sections, current write pointer, datatype, number of channels (number of columns) and total number of samples (not bytes) written
2. data section Contains the actual data in the buffer. When the write pointer reaches the end of the section it jumps to the beginning overwriting the old data.
3. pocket section The pocket section always contains the same data as the leftmost such chunk of the data section. This is done to avoid data copies when reading a data chunk (up to the size of the pocket) first part of which happens to be located at the end of the data section while the second - already in the beginning. This might be useful when reading the data with a sliding window.
Attributes
| is_initialized | Indicates whether the buffer is initialized, read-only (bool) |
| nChannels | Dimensionality of a sample, read-only (int) |
| bufSize | The buffer capacity in samples, read-only (int) |
| pocketSize | Size of the buffer pocket in samples, read-only (int) |
| nptype | The type of the data in the buffer, read-only (string) |
| raw | Raw buffer array, read-only (sharedctypes, char) |
| writePtr | Current write pointer position, read-only (int) |
Methods
| check_availablility(sampleStart, sampleEnd) | Checks whether the requested data samples are available. |
| get_data(sampleStart, sampleEnd[, wprotect]) | Gets the data from the buffer. |
| initialize(nChannels, nSamples[, ...]) | Initializes the buffer with a new raw array |
| initialize_from_raw(raw) | Initializes the buffer with the compatible external raw array. |
| put_data(data) | Pushes the data to the buffer |
The buffer capacity in samples, read-only (int)
Checks whether the requested data samples are available.
| Parameters : | sampleStart : int
sampleEnd : int
|
|---|---|
| Returns : | 0 :
2 :
3 :
|
Gets the data from the buffer. If possible, the data is returned in the form of a numpy view on the corresponding chunk (without copy). If the data is not available, rises an exception
| Parameters : | sampleStart : int
sampleEnd : int
wprotect : bool, optional
|
|---|---|
| Returns : | data : data chunk (numpy view or numpy array) |
| Raises : | BufferError :
|
Initializes the buffer with a new raw array
| Parameters : | nChannels : int
nSamples : int
windowSize : int, optional
nptype : string, optional
|
|---|
Initializes the buffer with the compatible external raw array. All the metadata will be read from the header region of this array.
| Parameters : | raw : sharedctypes char array
|
|---|
Indicates whether the buffer is initialized, read-only (bool)
Dimensionality of a sample, read-only (int)
The type of the data in the buffer, read-only (string)
Size of the buffer pocket in samples, read-only (int)
Pushes the data to the buffer
| Parameters : | data : ndarray
|
|---|
Raw buffer array, read-only (sharedctypes, char)
Current write pointer position, read-only (int)
A ctypes structure describing the buffer header
Attributes
| bufSizeBytes | Structure/Union member |
| pocketSizeBytes | Structure/Union member |
| dataType | Structure/Union member |
| nChannels | Structure/Union member |
| nSamplesWritten | Structure/Union member |
Structure/Union member
Structure/Union member
Structure/Union member
Structure/Union member
Structure/Union member
A helper class to interpret the typecode read from buffer header. To add new supported datatypes, add them to the ‘type’ dictionary
Methods
| get_code(type) | Gets buffer typecode given numpy datatype |
| get_type(code) | Gets numpy datatype given a buffer typecode |
Gets buffer typecode given numpy datatype
| Parameters : | type : string
|
|---|
Gets numpy datatype given a buffer typecode
| Parameters : | code : int
|
|---|