Skip to content

Commit

Permalink
Added StopIteration inside the iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
agirbau committed Sep 21, 2023
1 parent 34f4ee0 commit 7861ed3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 0 additions & 3 deletions examples/visualize_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,3 @@

t_current += t_window
i += 1

# TODO: When using a for loop the event iterator stays in an infinite loop
break
6 changes: 5 additions & 1 deletion src/evlib/codec/fileformat/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def _init_vars_(self) -> None:

def read_ev_file(self) -> np.ndarray:
# From https://github.com/gorchard/event-Python/blob/master/eventvision.py#L532
# Change np.fromfile() to use "offset" if needed for future datasets
raw_data = np.fromfile(self.file, dtype=np.uint8)
self.file.close()
raw_data = np.uint32(raw_data)
raw_evs = self._transform_raw_to_evs_(raw_data)
return raw_evs

Check warning on line 50 in src/evlib/codec/fileformat/bin.py

View check run for this annotation

Codecov / codecov/patch

src/evlib/codec/fileformat/bin.py#L46-L50

Added lines #L46 - L50 were not covered by tests

@staticmethod
# Andreu: Add the return type and the ingestion type
def _transform_raw_to_evs_(raw_data: np.ndarray) -> np.ndarray:
all_y = raw_data[1::5]
all_x = raw_data[0::5]
Expand Down Expand Up @@ -83,6 +83,10 @@ def __next__(self) -> RawEvents:
raw_evs = self.raw_evs
_l = len(raw_evs)

Check warning on line 84 in src/evlib/codec/fileformat/bin.py

View check run for this annotation

Codecov / codecov/patch

src/evlib/codec/fileformat/bin.py#L83-L84

Added lines #L83 - L84 were not covered by tests

# As we are reading the whole file at once this works. Re-check if we decide to go for chunk reading.
if self.count > _l:
raise StopIteration

Check warning on line 88 in src/evlib/codec/fileformat/bin.py

View check run for this annotation

Codecov / codecov/patch

src/evlib/codec/fileformat/bin.py#L88

Added line #L88 was not covered by tests

x = raw_evs[:, 0].astype(np.int32)
y = raw_evs[:, 1].astype(np.int32)
t = raw_evs[:, 2].astype(np.float64)
Expand Down

0 comments on commit 7861ed3

Please sign in to comment.