Skip to content

Commit

Permalink
feat: access more frames via direct read_frame() method (#192)
Browse files Browse the repository at this point in the history
* access more frames

* style(pre-commit.ci): auto fixes [...]

* fix lint

* remove

* remove dir

* no walrus

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
tlambert03 and pre-commit-ci[bot] committed Nov 15, 2023
1 parent 5a7eb19 commit eb1deb2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/nd2/readers/_modern/modern_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,16 @@ def _frame_offsets(self) -> dict[int, int]:

def read_frame(self, index: int) -> np.ndarray:
"""Read a chunk directly without using SDK."""
if index > self._seq_count():
raise IndexError(f"Frame out of range: {index}")
if not self._fh: # pragma: no cover
raise ValueError("Attempt to read from closed nd2 file")

# sometimes a frame index has a valid offset even if it's greater than
# _seq_count() (for example, if experiment parsing misses stuff)
# so, it should still be accessible.
offset = self._frame_offsets.get(index, None)
if offset is None:
if index > self._seq_count(): # pragma: no cover
raise IndexError(f"Frame out of range: {index}")
return self._missing_frame(index)

if self.attributes().compressionType == "lossless":
Expand Down

0 comments on commit eb1deb2

Please sign in to comment.