BrainSense Streaming Pipeline
Overview
The BrainSense Streaming Pipeline is a Python module specific for handling BrainSense Streaming data format from Percept. This section will go over all functions implemented and provide sufficient details on pipeline implementation.
Methods
- Percept.BrainSenseStream.saveRealtimeStreams(deviceID, StreamingTD, StreamingPower, sourceFile)
Save BrainSense Streaming Data in Database Storage
- Parameters
deviceID – UUID4 deidentified id for each unique Percept device.
StreamingTD – BrainSense TimeDomain structure extracted from Medtronic JSON file.
StreamingPower – BrainSense Power Channel structure extracted from Medtronic JSON file.
sourceFile – filename of the raw JSON file that the original data extracted from.
- Returns
Boolean indicating if new data is found (to be saved).
- Percept.BrainSenseStream.processRealtimeStreams(stream, cardiacFilter=False)
Process BrainSense Streaming Data
This is the primary processing function for all BrainSense Streaming data. The server will attempt to calculate Short-time Fourier Transform (STFT) with 1.0 second window and 0.5 second overlap. In addition to the STFT, the server will also calculate Wavelet Transform with a 500ms moving average window.
The user can request the server to perform cardiac removal using cardiacFilter argument. If cardiac filter is used, the server will perform a template matching algorithm to remove cardiac signals. (TODO: details algorithm for later).
- Parameters
stream – BrainSense TimeDomain structure extracted from Medtronic JSON file
cardiacFilter – Boolean indicating if you want to .
- Returns
Processed BrainSense TimeDomain structure
- Percept.BrainSenseStream.queryRealtimeStreamRecording(analysis, cardiacFilter=False, refresh=False)
Query BrainSense Streaming Data
This function will query BrainSense recording data based on provided Recording ID.
- Parameters
user – BRAVO Platform User object.
recordingId – Deidentified recording ID as referenced in SQL Database.
authority – User permission structure indicating the type of access the user has.
cardiacFilter – Boolean indicator if the user want to apply cardiac filters (see processRealtimeStreams function)
refresh – Boolean indicator if the user want to use cache data or reprocess the data.
- Returns
Returns a tuple (BrainSenseData, RecordingID) where BrainSenseData is the BrainSense streaming data structure in Database and RecordingID is the deidentified id of the available data.
- Percept.BrainSenseStream.queryMultipleSegmentComparison(user, recordingIds, authority)
Query Multiple Segment Comparison
This function will query BrainSense recording data based on provided Recording ID.
- Parameters
user – BRAVO Platform User object.
recordingIds – List of deidentified recording IDs as referenced in SQL Database.
authority – User permission structure indicating the type of access the user has.
- Returns
Returns a dictionary (SegmentSummaries) which contains average power spectrum and respective stimulation settings.
- Percept.BrainSenseStream.processRealtimeStreamRenderingData(stream, options={}, centerFrequencies=[0, 0], stimulationReference='Ipsilateral')
Process BrainSense Streaming Data to be used for Plotly rendering.
This function takes the processRealtimeStreams BrainSense Stream object and further process it for frontend rendering system. This is to reduce some computational requirement for the frontend, and because Python signal processing is more efficient than Javascript frontend.
This function wrap around
processRealtimeStreamStimulationPSD
function to generate stimulation related PSD at different stimulation state.- Parameters
stream – processed BrainSense TimeDomain structure (see processRealtimeStreams function)
options – Signal processing module configurations.
centerFrequencies – The center frequencies (Left and Right hemisphere) used to obtain Power-band box plot.
- Returns
Returns processed data object with content sufficient for React.js to render Plotly graphs.
- Percept.BrainSenseStream.processRealtimeStreamStimulationAmplitude(stream)
Process BrainSense Streaming Data to extract data segment at different stimulation amplitude.
- Parameters
stream – processed BrainSense PowerDomain structure (see processRealtimeStreams function)
- Returns
Returns list of stimulation series.
- Percept.BrainSenseStream.processRealtimeStreamPowerBand(stream)
Extract Onboard Power-band recording.
Additional filtering is done by performing zscore normalization. Outliers are removed.
- Parameters
stream – processed BrainSense PowerDomain structure (see processRealtimeStreams function)
- Returns
Returns list of stimulation series.
- Percept.BrainSenseStream.processRealtimeStreamStimulationPSD(stream, channel, method='Spectrogram', stim_label='Ipsilateral', centerFrequency=0)
Process BrainSense Stream Stimulation-specific Power Spectrum
The process will take in stimulation epochs and compute Power Spectral Density using methods specified in parameters. Stimulation epochs with less than 7 seconds of recording are skipped. 2 seconds before and after stimulation changes are skipped to avoid transition artifacts.
Standard method uses 1 second Window and 0.5 seconds overlap. Standard Spectral Feature bandwidth is +/- 2Hz.
- Parameters
stream – processed BrainSense TimeDomain structure (see processRealtimeStreams function)
channel – BrainSense TimeDomain data channel name.
method (string) – Processing method. Default to “Spectrogram” method, can be one of (Welch, Spectrogram, or Wavelet).
stim_label (string) – Using “Ipsilateral” stimulation label or “Contralateral” stimulation label.
centerFrequency (int) – The center frequency at which the spectral features are extracted from PSD.
- Returns
Returns average PSD at each stimulation amplitude, and Spectral Features extracted from desired frequency band.