Source code for brainaccess.core.stream_rate
from enum import Enum
[docs]
class StreamRate(Enum):
"""Sample rates the library knows.
A headset supports only some of them (250 and 500 Hz on every model, 1000 Hz
on HALO V3, 1000 and 2000 Hz on EXG8). The setter
:meth:`~brainaccess.core.eeg_manager.EEGManager.set_sample_rate` takes the rate
in Hz, not a member of this enum; use :meth:`from_hz` and :attr:`to_hz` to
convert.
Attributes
----------
X16kHz : int
16000 Hz.
X8kHz : int
8000 Hz.
X4kHz : int
4000 Hz.
X2kHz : int
2000 Hz.
X1kHz : int
1000 Hz.
X500Hz : int
500 Hz.
X250Hz : int
250 Hz.
UNKNOWN : int
An unrecognized rate.
"""
@property
[docs]
def to_hz(self) -> int:
"""The sample rate in Hz, or ``-1`` for :attr:`UNKNOWN`."""
_map = {
StreamRate.X16kHz: 16000,
StreamRate.X8kHz: 8000,
StreamRate.X4kHz: 4000,
StreamRate.X2kHz: 2000,
StreamRate.X1kHz: 1000,
StreamRate.X500Hz: 500,
StreamRate.X250Hz: 250,
}
return _map.get(self, -1)
@classmethod
[docs]
def from_hz(cls, hz: int) -> "StreamRate":
"""Get the member for a sample rate.
Parameters
----------
hz : int
Sample rate in Hz.
Returns
-------
StreamRate
The matching member, or :attr:`UNKNOWN` if there is none.
"""
_hz_map = {
16000: cls.X16kHz,
8000: cls.X8kHz,
4000: cls.X4kHz,
2000: cls.X2kHz,
1000: cls.X1kHz,
500: cls.X500Hz,
250: cls.X250Hz,
}
return _hz_map.get(hz, cls.UNKNOWN)