Coverage for src/evutils/io/_bin.py: 67%
21 statements
« prev ^ index » next coverage.py v7.15.1, created at 2026-07-15 09:33 +0000
« prev ^ index » next coverage.py v7.15.1, created at 2026-07-15 09:33 +0000
1"""Binary (.bin) file decoder and encoder.
3.. note::
4 Not implemented yet: both classes raise :class:`NotImplementedError` on
5 construction. The classes exist so the ``.bin`` extension is reserved in
6 the reader/writer registries and the error message is explicit.
7"""
8from typing import Any
10import numpy as np
11from ..types import EventArray, TriggerArray
12from .common import EventDecoder, EventEncoder
14_NOT_IMPLEMENTED = (
15 "The .bin event format is not implemented yet. "
16 "Convert the file to a supported format (RAW/EVT, DAT, AER, HDF5, NPZ, CSV) "
17 "or pass an explicit file_decoder/file_encoder."
18)
21class EventDecoder_Bin(EventDecoder):
22 """A decoder for reading events from binary files.
24 .. note::
25 Not implemented yet -- constructing this class raises
26 :class:`NotImplementedError`.
28 Parameters
29 ----------
30 source : ByteSource
31 Byte source to read events from.
32 **kwargs
33 Additional decoder arguments.
35 Raises
36 ------
37 NotImplementedError
38 Always, until the format is implemented.
40 """
42 def __init__(self, source: Any, **kwargs: Any):
43 raise NotImplementedError(_NOT_IMPLEMENTED)
45 def init(self) -> None:
46 """Initialize the file for reading."""
47 raise NotImplementedError(_NOT_IMPLEMENTED)
49 def read_chunk(self, delta_t_hint: int | None = None, n_events_hint: int | None = None) -> Any:
50 """Read a chunk of events."""
51 raise NotImplementedError(_NOT_IMPLEMENTED)
53 def reset(self) -> None:
54 """Reset the file pointer to the beginning of the file."""
55 raise NotImplementedError(_NOT_IMPLEMENTED)
58class EventEncoder_Bin(EventEncoder):
59 """An encoder for writing events to binary files.
61 .. note::
62 Not implemented yet -- constructing this class raises
63 :class:`NotImplementedError`.
65 Parameters
66 ----------
67 writable : io.BufferedIOBase
68 Destination for writing events.
69 **kwargs
70 Additional encoder arguments (``width``, ``height``, ``dt``, ...).
72 Raises
73 ------
74 NotImplementedError
75 Always, until the format is implemented.
77 """
79 def __init__(self, writable: Any, **kwargs: Any):
80 raise NotImplementedError(_NOT_IMPLEMENTED)
82 def init(self) -> None:
83 """Initialize the file for writing."""
84 raise NotImplementedError(_NOT_IMPLEMENTED)
86 def write(self, events: 'np.ndarray | EventArray', triggers: 'np.ndarray | TriggerArray | None' = None) -> int:
87 """Write a chunk of events."""
88 raise NotImplementedError(_NOT_IMPLEMENTED)