The Circular Buffer Class Details¶
Below are provided the details of the methods and properties of the circular buffer class.
- class circular_buffer_numpy.circular_buffer.CircularBuffer(shape=(100, 2), dtype='float64', packet_length=1)[source]¶
- Variables
pointer – initial value: -1
g_pointer – initial value: -1
packet_length – initial value 1
- append(data)[source]¶
appends data to the existing circular buffer.
- Parameters
- data :: (numpy array)
data to append
- Returns
Examples
>>> buffer = circular_buffer_numpy.circular_buffer.CircularBuffer(shape = (10,4) >>> from numpy.random import random >>> rand_arr = random(size=(6,4)) >>> buffer.append(rand_arr) >>> buffer.pointer 5
- change_length(length)[source]¶
changes length of the buffer
- Parameters
- lengthinteger
new length of the buffer
- Returns
Examples
>>> buffer = circual_buffer.CircularBuffer(shape=(10,4)) >>> buffer.shape (10,4) >>> buffer.change_length(12) >>> buffer.shape (12,4)
- property circular_packet_pointer¶
returns packet pointer calculated from local pointer and packet size. The packet pointer can be a float number. It serves as an indaction something was not appended in packets.
- property circular_pointer¶
‘circular pointer’ refers to an actual pointer in the circular buffer numpy array and is an alias of ‘pointer’
- property data_shape¶
tuple: property objects that returns the shape of one data point (or N dimensional array) of the circular buffer
- property dtype¶
dtype: property objects that returns the shape of one data point (or N dimensional array) of the circular buffer
- property g_packet_pointer¶
returns packet pointer calculated from local pointer and packet size. The packet pointer can be a float number. It serves as an indaction something was not appended in packets.
- get_N(N=0, M=0)[source]¶
return N points before index M in the circular buffer
- Parameters
- Ninteger
number of points to return
- Minteger
index of the pointer
- Returns
- arrayarray_like
Examples
>>> data = circual_buffer.CircularBuffer.get_N(N=2, M=5)
- get_N_global(N=0, M=0)[source]¶
return N points before global index M in the circular buffer.
- Parameters
- Ninteger
number of points to return
- Minteger
global index of the pointer
- Returns
- arrayarray_like
Examples
>>> data = circual_buffer.CircularBuffer.get_N(N=2, M=5)
- get_all()[source]¶
return entire circular buffer server in ordered way, where last value is the last collected.
- Parameters
- None
- Returns
- arrayarray_like
array of data points in the historic order
Examples
>>> data = circual_buffer.CircularBuffer.get_all()
- get_data()[source]¶
return all valid circular buffer entries in ordered way, where last value is the last collected.
- Parameters
- None
- Returns
- arrayarray_like
(numpy array)
Examples
>>> data = circual_buffer.CircularBuffer.get_data()
- get_i_j(i, j)[source]¶
returns buffer between indices i and j (including index i) if j < i, it assumes that buffer wrapped around and will give information accordingly. NOTE: the user needs to pay attention to the order at which indices are passed NOTE: index i cannot be -1 otherwise it will return empty array
- Parameters
- iinteger
start index in the buffer
- jinteger
end index in the buffer
- Returns
- arrayarray_like
Examples
>>> data = circual_buffer.CircularBuffer.get_i_j(i=2,j=5)
- get_last_N(N)[source]¶
returns last N entries from the known self.pointer(circular buffer pointer)
- Parameters
- Ninteger
number of points to return
- Returns
- array (numpy array)
Examples
>>> data = circual_buffer.CircularBuffer.get_last_N(10)
- get_last_value()[source]¶
returns last entry from the known. Same as self.buffer[self.pointer]
- Parameters
- None
- Returns
- arrayarray_like
Examples
>>> data = circual_buffer.CircularBuffer.get_last_value()
- get_packet_circular_i_j(i, j=None, copy=False)[source]¶
return packets between i and j circular packet pointers. If i==j, function returns i’s packet only. if j is None, function returns only i’s packet
- get_packet_linear_i_j(i, j=None, copy=False)[source]¶
return packets between i and j linear packet pointers. If i==j, function returns i’s packet only. if j is None, function returns only i’s packet
- get_value(linear_pointer=None, circular_pointer=None)[source]¶
returns last entry from the known. Same as self.buffer[self.pointer]
- Parameters
- None
- Returns
- arrayarray_like
Examples
>>> data = circual_buffer.CircularBuffer.get_last_value()
- property length¶
integer: returns the length of the circular buffer along fast
- property linear_packet_pointer¶
returns global packet pointer calculated from global pointer and packet size. The packet pointer can be a float number. It serves as an indaction something was not appended in packets.
- property linear_pointer¶
‘linear pointer’ refers to a global pointer that has been counting from the beginning of times.
- property packet_pointer¶
returns packet pointer calculated from local pointer and packet size. The packet pointer can be a float number. It serves as an indaction something was not appended in packets.
- reset(clear=False)[source]¶
resets pointers to -1 (empty buffer), the full reset can be force via parameter clears The parameter clear can be used to
- Parameters
- clear(boolean)
force clearing the buffer
- Returns
Examples
>>> circual_buffer.CircularBuffer.reset()
- property shape¶
- shapetuple
property objects that returns the shape of the circular buffer.
- property size¶