GithubHelp home page GithubHelp logo

circular_buffer_numpy's People

Contributors

vstadnytskyi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

circular_buffer_numpy's Issues

Getting the data from the circular buffer

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 NaNs 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 ๐Ÿ‘

Bug in enqueue in Queue class

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]])

Appending of image without prior reshaping

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:

  1. check the dimensionality of incoming data. If data is one dimension smaller, assume that first dimension is 1. If dimensionality the same, append as it is.

`dtype` can be set only as a string

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

If your project is based on the numpy, then it would be very good to accept the numpy dtypes as well!

bug in dequeue function of the Queue class

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.

improve documentation

Maybe make it clear in the documentation that NaNs 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)

  1. add examples of usage
  2. add explanation of internal structure of the buffer

circular_buffer.get_last_value bug

>>> 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

potential error in retrieving data from circular buffer

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.