vstadnytskyi / circular_buffer_numpy Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
Kudos for the project ๐
This is a question/suggestion. Is there an easy way to get the data from the CircularBuffer
?
Currently buffer.get_all()
returns NaN
s for memory not filled yet, so the only way I can think of doing it is by buffer.get_all()[~np.isnan(buffer.get_all())]
. This is a bit verbose and having a get_data()
convenience function would make things easier ๐
Seems to be a typo that was reflected in the hosted docs.
The enqueue doesn't behave right if you try to append a single data point to the queue. Currently, it requires the enqueued data point to have shape (1, data_shape) to be enqueue properly.
In [55]: from circular_buffer_numpy.queue import Queue
In [56]: queue = Queue(shape = (100,2), dtype = 'float64')
In [57]: data_point = empty((2))
In [58]: data_point[0] = time()
In [59]: data_point[1] = random.randint(0,4096)
In [60]: data_point
Out[60]: array([1.61452788e+09, 3.69000000e+03])
In [61]: queue.peek_all()
Out[61]: array([], shape=(0, 2), dtype=float64)
In [62]: queue.enqueue(data_point)
In [63]: queue.peek_all()
Out[63]:
array([[1.61452788e+09, 1.61452788e+09],
[3.69000000e+03, 3.69000000e+03]])
The [out 60] should have given only one data point but returned two identical. and it has wrong orientation in the queue.
The temporary fix has to be the following:
In [61]: data_point = empty((1,2))
In [62]: data_point[0,0] = time()
In [63]: data_point[0,1] = random.randint(0,4096)
In [64]: queue.enqueue(data_point)
In [65]: queue.peek_all()
Out[65]:
array([[1.61452788e+09, 1.61452788e+09],
[3.69000000e+03, 3.69000000e+03],
[1.61452918e+09, 1.19300000e+03]])
See issue vstadnytskyi/intel-realsense-devices#17 for details. The circular buffer numpy library needs to be modified. Also, see exact code that can reproduce the error.
The proposed solution:
dtype
in the buffer construction cannot be set from other numpy array dtype
for example:
frame_time = CircularBuffer(shape=(len_frame, 1),
dtype=time.dtype)
And this gives the error:
File "/home/andrei/miniconda3/envs/gait_bench/lib/python3.9/site-packages/circular_buffer_numpy/circular_buffer.py", line 45, in __init__
if 'float' in dtype:
TypeError: argument of type 'numpy.dtype[float64]' is not iterable
numpy
, then it would be very good to accept the numpy dtypes as well!There are conditions when sequence returns wrong data.
for example dequeuing a dataset with the shape of (640,), sometime return shape of (477440,). I wasn't able to reproduce the error yet.
Maybe make it clear in the documentation that NaN
s are returned if the buffer is still empty. I would add the some explanatory code to the documentation
Originally posted by @gerazov in #2 (comment)
>>> dev.circular_buffer.get_last_value()
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
dev.circular_buffer.get_last_value()
File "Z:\circular_buffer_LL.py", line 114, in get_last_value
return get_last_N(N = 1)
NameError: name 'get_last_N' is not defined
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/femto-13/All-Projects-on-femto/LaserLab/Software/libraries/icarus-nmr/icarus_nmr/event_handler.py", line 514, in run
self.run_once()
File "/Users/femto-13/All-Projects-on-femto/LaserLab/Software/libraries/icarus-nmr/icarus_nmr/event_handler.py", line 538, in run_once
self.evaluate_events()
File "/Users/femto-13/All-Projects-on-femto/LaserLab/Software/libraries/icarus-nmr/icarus_nmr/event_handler.py", line 1243, in evaluate_events
self.push_target_pressure()
File "/Users/femto-13/All-Projects-on-femto/LaserLab/Software/libraries/icarus-nmr/icarus_nmr/event_handler.py", line 1371, in push_target_pressure
target_pressure = scipy.stats.mode(data[:,0])[0][0]
IndexError: index 0 is out of bounds for axis 0 with size 0
The function that fails is this:
def get_ring_buffer_N(self,N,pointer):
#print('input: N= %r ; pointer = %r )' % (N, pointer))
if pointer > (self.packet_buffer_size+1)*self.packet_length:
pointer = int(pointer - ((self.packet_buffer_size+1)*self.packet_length)-1)
# try:
#print(' try: N= %r ; pointer = %r' % (N, pointer))
res = self.circular_buffer.get_N(N, pointer)
# except:
# res = nan
return res
N = 400, pointer = unknown.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.