From 0ae95f010a4186ab44f1560f91b35076f79e3848 Mon Sep 17 00:00:00 2001 From: Chadwick Boulay Date: Fri, 6 Dec 2024 20:02:20 -0500 Subject: [PATCH] ruff fixes --- src/pylsl/examples/HandleMetadata.py | 8 ++++++-- src/pylsl/examples/PerformanceTest.py | 10 ++++------ src/pylsl/info.py | 4 ++-- src/pylsl/outlet.py | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/pylsl/examples/HandleMetadata.py b/src/pylsl/examples/HandleMetadata.py index acab02b..8c9f80f 100644 --- a/src/pylsl/examples/HandleMetadata.py +++ b/src/pylsl/examples/HandleMetadata.py @@ -3,6 +3,7 @@ import time +import numpy as np from pylsl import StreamInfo, StreamInlet, StreamOutlet, resolve_byprop @@ -13,7 +14,8 @@ def main(): # now attach some meta-data (in accordance with XDF format, # see also https://github.com/sccn/xdf/wiki/Meta-Data) chns = info.desc().append_child("channels") - for label in ["C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"]: + ch_labels = ["C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"] + for label in ch_labels: ch = chns.append_child("channel") ch.append_child_value("label", label) ch.append_child_value("unit", "microvolts") @@ -27,7 +29,9 @@ def main(): # create outlet for the stream outlet = StreamOutlet(info) - # (...normally here one might start sending data into the outlet...) + # Send a sample into the outlet... + dummy_sample = np.arange(len(ch_labels), dtype=np.float32) + outlet.push_sample(dummy_sample) # === the following could run on another computer === diff --git a/src/pylsl/examples/PerformanceTest.py b/src/pylsl/examples/PerformanceTest.py index 186f038..3d954b2 100644 --- a/src/pylsl/examples/PerformanceTest.py +++ b/src/pylsl/examples/PerformanceTest.py @@ -16,12 +16,10 @@ ) try: - from pyfftw.interfaces.numpy_fft import ( # Performs much better than numpy's fftpack - irfft, - rfft, - ) + from pyfftw.interfaces.numpy_fft import irfft + # Performs much better than numpy's fftpack except ImportError: - from numpy.fft import irfft, rfft + from numpy.fft import irfft try: import sys @@ -339,7 +337,7 @@ def __init__(self): self.inlet = StreamInlet(streams[0], processing_flags=proc_flags) # The following is an example of how to read stream info stream_info = self.inlet.info() - stream_Fs = stream_info.nominal_srate() + # stream_Fs = stream_info.nominal_srate() stream_xml = stream_info.desc() chans_xml = stream_xml.child("channels") chan_xml_list = [] diff --git a/src/pylsl/info.py b/src/pylsl/info.py index b9dc230..dababd0 100644 --- a/src/pylsl/info.py +++ b/src/pylsl/info.py @@ -89,8 +89,8 @@ def __del__(self): # noinspection PyBroadException try: lib.lsl_destroy_streaminfo(self.obj) - except: - pass + except Exception as e: + print(f"StreamInfo deletion triggered error: {e}") # === Core Information (assigned at construction) === diff --git a/src/pylsl/outlet.py b/src/pylsl/outlet.py index c669009..3c4e6c3 100644 --- a/src/pylsl/outlet.py +++ b/src/pylsl/outlet.py @@ -60,8 +60,8 @@ def __del__(self): # noinspection PyBroadException try: lib.lsl_destroy_outlet(self.obj) - except: - pass + except Exception as e: + print(f"StreamOutlet deletion triggered error: {e}") def push_sample(self, x, timestamp=0.0, pushthrough=True): """Push a sample into the outlet.