Skip to content

Commit

Permalink
ruff format (mostly whitespace)
Browse files Browse the repository at this point in the history
  • Loading branch information
cboulay committed Jan 18, 2025
1 parent 7bee0b1 commit 3caecc8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 36 deletions.
7 changes: 3 additions & 4 deletions examples/lsl_inlet_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
def main(stream_name: str = "", stream_type: str = "EEG"):
comps = {
"SRC": LSLInletUnit(info=LSLInfo(name=stream_name, type=stream_type)),
"LOGGER": DebugLog(name="DEBUG", max_length=400), # MessageLogger(output=file_path),
"LOGGER": DebugLog(name="DEBUG", max_length=400),
# MessageLogger(output=file_path),
}
conns = (
(comps["SRC"].OUTPUT_SIGNAL, comps["LOGGER"].INPUT),
)
conns = ((comps["SRC"].OUTPUT_SIGNAL, comps["LOGGER"].INPUT),)
ez.run(components=comps, connections=conns)


Expand Down
32 changes: 18 additions & 14 deletions src/ezmsg/lsl/inlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class LSLInletState(ez.State):


class LSLInletGenerator:
def __init__(self, *args, settings: typing.Optional[LSLInletSettings] = None, **kwargs):
def __init__(
self, *args, settings: typing.Optional[LSLInletSettings] = None, **kwargs
):
kwargs = _sanitize_kwargs(kwargs)
if settings is None:
if len(args) > 0 and isinstance(args[0], LSLInletSettings):
Expand Down Expand Up @@ -130,15 +132,15 @@ def _reset_inlet(self):
# If name, type, and host are all provided, then create the StreamInfo directly and
# create the inlet directly from that info.
if all(
[
_ is not None
for _ in [
[
_ is not None
for _ in [
self.settings.info.name,
self.settings.info.type,
self.settings.info.channel_count,
self.settings.info.channel_format,
]
]
]
):
info = pylsl.StreamInfo(
name=self.settings.info.name,
Expand All @@ -154,16 +156,16 @@ def _reset_inlet(self):
for strm_info in results:
b_match = True
b_match = b_match and (
(not self.settings.info.name)
or strm_info.name() == self.settings.info.name
(not self.settings.info.name)
or strm_info.name() == self.settings.info.name
)
b_match = b_match and (
(not self.settings.info.type)
or strm_info.type() == self.settings.info.type
(not self.settings.info.type)
or strm_info.type() == self.settings.info.type
)
b_match = b_match and (
(not self.settings.info.host)
or strm_info.hostname() == self.settings.info.host
(not self.settings.info.host)
or strm_info.hostname() == self.settings.info.host
)
if b_match:
self._state.inlet = pylsl.StreamInlet(
Expand All @@ -185,8 +187,8 @@ def _reset_inlet(self):
if fmt in fmt2npdtype:
dtype = fmt2npdtype[fmt]
n_buff = (
int(self.settings.local_buffer_dur * inlet_info.nominal_srate())
or 1000
int(self.settings.local_buffer_dur * inlet_info.nominal_srate())
or 1000
)
self._state.fetch_buffer = np.zeros((n_buff, n_ch), dtype=dtype)
ch_labels = []
Expand Down Expand Up @@ -238,7 +240,8 @@ def __next__(self) -> typing.Optional[AxisArray]:

if self._state.fetch_buffer is not None:
samples, timestamps = self._state.inlet.pull_chunk(
max_samples=self._state.fetch_buffer.shape[0], dest_obj=self._state.fetch_buffer
max_samples=self._state.fetch_buffer.shape[0],
dest_obj=self._state.fetch_buffer,
)
else:
samples, timestamps = self._state.inlet.pull_chunk()
Expand Down Expand Up @@ -298,6 +301,7 @@ class LSLInletUnit(ez.Unit):
stream_name: The `name` of the created LSL outlet.
stream_type: The `type` of the created LSL outlet.
"""

SETTINGS = LSLInletSettings
STATE = LSLInletUnitState

Expand Down
11 changes: 7 additions & 4 deletions src/ezmsg/lsl/outlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class LSLOutletState(ez.State):


class OutletProcessor:

def __init__(self, *args, settings: typing.Optional[LSLOutletSettings] = None, **kwargs):
def __init__(
self, *args, settings: typing.Optional[LSLOutletSettings] = None, **kwargs
):
if settings is None:
if len(args) > 0 and isinstance(args[0], LSLOutletSettings):
settings = args[0]
Expand Down Expand Up @@ -88,7 +89,9 @@ def check_metadata(self, message: AxisArray) -> bool:
if hasattr(message.axes["time"], "gain"):
fs = 1 / message.axes["time"].gain
time_ix = message.get_axis_idx("time")
sample_shape = message.data.shape[:time_ix] + message.data.shape[time_ix + 1:]
sample_shape = (
message.data.shape[:time_ix] + message.data.shape[time_ix + 1 :]
)
this_hash = hash((message.key, message.data.dtype, fs, sample_shape))
b_reset = b_reset or this_hash != self._state.hash
if b_reset:
Expand All @@ -113,7 +116,7 @@ def reset(self, message: AxisArray) -> None:
)
# Add channel labels to the info desc.
if "ch" in message.axes and isinstance(
message.axes["ch"], AxisArray.CoordinateAxis
message.axes["ch"], AxisArray.CoordinateAxis
):
ch_labels = message.axes["ch"].data
# TODO: or get ch_labels from self.settings.map_file
Expand Down
18 changes: 8 additions & 10 deletions src/ezmsg/lsl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def __new__(cls, *args, **kwargs):
cls._instance = super().__new__(cls)
return cls._instance

def __init__(self, alpha: float = 0.1, min_interval: float = 0.1, run_thread: bool = True):
def __init__(
self, alpha: float = 0.1, min_interval: float = 0.1, run_thread: bool = True
):
if not hasattr(self, "_initialized"):
self._alpha = alpha
self._interval = min_interval
Expand Down Expand Up @@ -75,27 +77,23 @@ def offset(self) -> float:
return self._offset

@typing.overload
def lsl2system(self, lsl_timestamp: float) -> float:
...
def lsl2system(self, lsl_timestamp: float) -> float: ...

@typing.overload
def lsl2system(self, lsl_timestamp: npt.NDArray[float]) -> npt.NDArray[float]:
...
def lsl2system(self, lsl_timestamp: npt.NDArray[float]) -> npt.NDArray[float]: ...

def lsl2system(self, lsl_timestamp):
# offset = system - lsl --> system = lsl + offset
with self._lock:
return lsl_timestamp + self._offset

@typing.overload
def system2lsl(self, system_timestamp: float) -> float:
...
def system2lsl(self, system_timestamp: float) -> float: ...

@typing.overload
def system2lsl(
self, system_timestamp: npt.NDArray[float]
) -> npt.NDArray[float]:
...
self, system_timestamp: npt.NDArray[float]
) -> npt.NDArray[float]: ...

def system2lsl(self, system_timestamp):
# offset = system - lsl --> lsl = system - offset
Expand Down
6 changes: 4 additions & 2 deletions tests/test_inlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ def test_inlet_generator():
)
outlet = pylsl.StreamOutlet(dummy_out_info)
state = {"pushed": 0}

def step_outlet(n_interval: int = 10):
dummy_data = np.arange(state["pushed"], state["pushed"] + n_interval)[:, None] / rate + np.zeros((1, nch))
dummy_data = np.arange(state["pushed"], state["pushed"] + n_interval)[
:, None
] / rate + np.zeros((1, nch))
outlet.push_chunk(dummy_data.astype(np.float32))
state["pushed"] += n_interval

Expand Down Expand Up @@ -125,7 +128,6 @@ def configure(self) -> None:

def network(self) -> ez.NetworkDefinition:
return (

(self.INLET.OUTPUT_SIGNAL, self.LOGGER.INPUT_MESSAGE),
(self.LOGGER.OUTPUT_MESSAGE, self.TERM.INPUT_MESSAGE),
)
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3caecc8

Please sign in to comment.