fix: major refactor and update methods in LFP processing#56
Merged
Conversation
ttngu207
reviewed
May 21, 2025
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the LFP processing workflow to improve efficiency, clarity, and performance by integrating a notch filter and using scipy.signal.decimate() for downsampling.
- Refactored LFP processing logic in the ephys table with improved filtering and downsampling.
- Updated code documentation and constant naming for clarity.
- Updated package version and changelog accordingly.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| element_array_ephys/version.py | Updated package version from 0.5.1 to 0.6.0 |
| element_array_ephys/ephys_no_curation.py | Refactored LFP signal processing: added docstrings, integrated decimate for downsampling, and updated filtering logic |
| CHANGELOG.md | Updated changelog to document the major refactor and updated methods in LFP processing |
Comments suppressed due to low confidence (1)
element_array_ephys/ephys_no_curation.py:399
- Ensure that using 'ch_idx' as the lookup key for 'channel_to_electrode_map' accurately reflects the intended mapping between the LFP channel order and its associated electrode. If 'channel_to_electrode_map' keys are based on channel indices from the raw data rather than the enumeration order, consider using the actual channel index value.
"electrode": channel_to_electrode_map[ch_idx],
| downsample_factor = int(np.round(true_ratio)) | ||
|
|
||
| # Check if the ratio is within 1% of an integer (1% tolerance) | ||
| if abs(true_ratio - downsample_factor) > 0.01: |
There was a problem hiding this comment.
[nitpick] Consider revisiting the 1% tolerance check for the downsampling factor; the strict threshold of 0.01 might trigger errors due to minor floating point imprecision.
Suggested change
| if abs(true_ratio - downsample_factor) > 0.01: | |
| if not np.isclose(true_ratio, downsample_factor, rtol=0.01, atol=1e-8): |
ttngu207
approved these changes
Jun 2, 2025
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.
This PR proposes the following method for processing broadband LFP signals:
iirnotchandfiltfilt.scipy.signal.decimate, instead of using a manual Butterworth + downsample approach.Decimateapplies an anti-aliasing FIR filter and reduces the sampling rate to 2.5 kHz.Decimateis a more integrated, more compact and efficient (less error-prone) than doing it separately.In this PR, the
ephys.LFPtable logic is refactored for computing and storing LFP traces with improved correctness, clarity, and performance. Key changes include:scipy.signal.decimate()with anti-aliasing FIR filters and zero-phase correction.np.hstackforfull_lfpandlfp_concat)