Repository navigation
Add signal-quality checks and optional channel rejection for band powers - #875
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Expose signal quality and quality-aware band powers in C#, Java, TypeScript, Rust, Swift, Julia, and MATLAB using the existing native implementation. Exercise channel ordering, flags, power parity, and invalid windows through the language bindings.
Keep the signal-quality and reusable band-power regressions, and link the Swift API notes to the shared signal-quality documentation.
Validate logical and numeric switches before marshalling, and cover both forms in the MATLAB regression.
Move Unix tests and C++ artifacts to macos-15 and select macOS steps by runner OS. GitHub has retired the macos-14 image.
| var report = DataFilter.get_signal_quality(data, channels, rate, options).quality[1]; | ||
| if (report.channel != 1 || report.flags != (SignalQualityFlags.NONFINITE | SignalQualityFlags.CLIPPED | SignalQualityFlags.FLATLINE) || | ||
| report.nonfinite_percentage != 100.0 / samples || report.clipped_percentage != 200.0 / samples || | ||
| report.longest_flatline_seconds != (samples - 4.0) / rate) |
| throw new Exception("Quality-aware powers differ from the accepted channel subset"); | ||
| var report = DataFilter.get_signal_quality(data, channels, rate, options).quality[1]; | ||
| if (report.channel != 1 || report.flags != (SignalQualityFlags.NONFINITE | SignalQualityFlags.CLIPPED | SignalQualityFlags.FLATLINE) || | ||
| report.nonfinite_percentage != 100.0 / samples || report.clipped_percentage != 200.0 / samples || |
| throw new Exception("Quality-aware powers differ from the accepted channel subset"); | ||
| var report = DataFilter.get_signal_quality(data, channels, rate, options).quality[1]; | ||
| if (report.channel != 1 || report.flags != (SignalQualityFlags.NONFINITE | SignalQualityFlags.CLIPPED | SignalQualityFlags.FLATLINE) || | ||
| report.nonfinite_percentage != 100.0 / samples || report.clipped_percentage != 200.0 / samples || |
Comment on lines
+391
to
+393
| return DataHandlerLibrary64.get_signal_quality_flat (data, rows, cols, sampling_rate, | ||
| clipping, options.lower_bound, options.upper_bound, options.max_clipped_percentage, | ||
| options.flatline_tolerance, options.max_flatline_seconds, options.min_channels, flags, measurements); |
Comment on lines
+395
to
+397
| return DataHandlerLibrary32.get_signal_quality_flat (data, rows, cols, sampling_rate, | ||
| clipping, options.lower_bound, options.upper_bound, options.max_clipped_percentage, | ||
| options.flatline_tolerance, options.max_flatline_seconds, options.min_channels, flags, measurements); |
Comment on lines
+411
to
+414
| return DataHandlerLibrary64.get_custom_band_powers_with_quality_flat (data, rows, cols, | ||
| starts, stops, starts.Length, sampling_rate, filters, clipping, options.lower_bound, | ||
| options.upper_bound, options.max_clipped_percentage, options.flatline_tolerance, | ||
| options.max_flatline_seconds, options.min_channels, avgs, stddevs, flags, measurements, out valid); |
Comment on lines
+416
to
+419
| return DataHandlerLibrary32.get_custom_band_powers_with_quality_flat (data, rows, cols, | ||
| starts, stops, starts.Length, sampling_rate, filters, clipping, options.lower_bound, | ||
| options.upper_bound, options.max_clipped_percentage, options.flatline_tolerance, | ||
| options.max_flatline_seconds, options.min_channels, avgs, stddevs, flags, measurements, out valid); |
| class DataHandlerLibrary64 | ||
| { | ||
| [DllImport ("DataHandler", CallingConvention = CallingConvention.Cdecl)] | ||
| internal static extern int get_signal_quality_flat (double[] data, int rows, int cols, int sampling_rate, |
| double flatline_tolerance, double max_flatline_seconds, int min_channels, [Out] int[] flags, | ||
| [Out] double[] measurements); | ||
| [DllImport ("DataHandler", CallingConvention = CallingConvention.Cdecl)] | ||
| internal static extern int get_custom_band_powers_with_quality_flat (double[] data, int rows, int cols, |
| class DataHandlerLibrary32 | ||
| { | ||
| [DllImport ("DataHandler32", CallingConvention = CallingConvention.Cdecl)] | ||
| internal static extern int get_signal_quality_flat (double[] data, int rows, int cols, int sampling_rate, |
| from brainflow.exit_codes import BrainFlowExitCodes, BrainFlowError | ||
| from brainflow.utils import check_memory_layout_row_major, LogLevels | ||
| from numpy.ctypeslib import ndpointer | ||
| from brainflow.signal_quality import SignalQualityFlags as SignalQualityFlags |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A clipped or stuck EEG channel can dominate the channel-averaged spectrum and move every normalized band. This adds opt-in native quality checks and band-power methods that exclude rejected whole channel windows before filtering and aggregation. Existing APIs keep their behavior.
get_signal_qualityandget_custom_band_powers_with_qualitywith a versioned policy and per-channel reports. The bindings can also call equivalent entry points that use primitive buffers.The API is stateless: recovery dwell belongs to the caller. It does not inspect timestamps, splice samples, alter raw recordings, or automatically classify every contact/movement artifact. Thresholds are explicit device/application settings.
Binding validation
Original Windows/MSVC Release validation
git diff --checkpassed.NeuroGames integration and classifier revalidation are separate from this library PR.