vineetbansal / wbi

0 stars 0 forks source link

Bug fixing in flash_finder.py #6

Closed anushka255 closed 10 months ago

anushka255 commented 11 months ago

There are at least 2 bugs in flash_finder.py, which have their own test cases. Once these bugs are removed, the test cases can be modified as well.

anushka255 commented 11 months ago

Bug 1: The bug seems to be coming from imbalance of test_data size.

Based on line 30 & 31 with the following code:

nIterations = nFrames // chunkMaxSize
remaining frames = nFrames - nIterations * chunkMaxSize

This leads the size of iterations to always be 0 and the loop that does some reshaping to never run. The value of remainingframes will always be equal to nFrames.

Causes problem in line 50 brightness[-remainingframes - 1:-1] = np.average(frames, axis=1)

Fixed the bug by encapsulating the code into a try except block.

anushka255 commented 11 months ago

Bug 2:

Based on line 30 & 31 with the following code:

nIterations = nFrames // chunkMaxSize
remainingframes = nFrames - nIterations * chunkMaxSize

The value of remainingframes always be 0 in cases where the number of frames in .dat file are exact multiple of 6 * chunk size.

Fixed the bug by adding an if statement before the code deals with the last partial check. If the frames are exact multiples of 6 * chunk size, then there will be no case of remaining frames.

The updated code looks like:

if remainingframes > 0:
        # Last partial chunk
        chunk = np.fromfile(f, dtype=np.uint16, count=remainingframes * 1024 * 512)
        frames = chunk.reshape((remainingframes, 1024 * 512))
        brightness[-remainingframes - 1:-1] = np.average(frames, axis=1)
        stdev[-remainingframes - 1:-1] = np.std(frames.astype(np.float64), axis=1)
anushka255 commented 11 months ago

Full Iteration:

anushka255 commented 11 months ago

Potential Bug 3:

After iterating through most of the data from binary file, there;s a section of code that calculates average value and standard deviation of each row in the frames array.

The code looks like:

brightness[-remainingframes - 1:-1] = np.average(frames, axis=1)
stdev[-remainingframes - 1:-1] = np.std(frames.astype(np.float64), axis=1)

This overwrites the value of brightness in -remaining-1 index and leaves the last index empty.