Skip to content

fix: major refactor and update methods in LFP processing#56

Merged
ttngu207 merged 13 commits into
mainfrom
update-lfp
Jun 2, 2025
Merged

fix: major refactor and update methods in LFP processing#56
ttngu207 merged 13 commits into
mainfrom
update-lfp

Conversation

@MilagrosMarin

@MilagrosMarin MilagrosMarin commented May 20, 2025

Copy link
Copy Markdown

This PR proposes the following method for processing broadband LFP signals:

  1. Design and apply a notch filter to remove powerline noise at 60 Hz using iirnotch and filtfilt.
  2. Downsample the signal using scipy.signal.decimate, instead of using a manual Butterworth + downsample approach. Decimate applies an anti-aliasing FIR filter and reduces the sampling rate to 2.5 kHz. Decimate is a more integrated, more compact and efficient (less error-prone) than doing it separately.

In this PR, the ephys.LFP table logic is refactored for computing and storing LFP traces with improved correctness, clarity, and performance. Key changes include:

  • Efficient and accurate downsampling using scipy.signal.decimate() with anti-aliasing FIR filters and zero-phase correction.
  • Add 1% tolerance check for downsampling factor to ensure robust LFP decimation handling
  • explicit list accumulation for timewise concatenation (np.hstack for full_lfp and lfp_concat)
  • Clean structure and documentation including structured inline comments and a docstring for the make() method.

@MilagrosMarin MilagrosMarin changed the title [WIP] fix: update logic in LFP [WIP] fix: update methods in LFP May 20, 2025
@MilagrosMarin MilagrosMarin changed the title [WIP] fix: update methods in LFP fix: update methods in LFP processing and refactor May 21, 2025
@MilagrosMarin MilagrosMarin changed the title fix: update methods in LFP processing and refactor fix: major refactor and update methods in LFP processing May 21, 2025
Comment thread element_array_ephys/ephys_no_curation.py Outdated

@ttngu207 ttngu207 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MilagrosMarin MilagrosMarin requested review from Copilot and ttngu207 May 30, 2025 23:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copilot AI Jun 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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):

Copilot uses AI. Check for mistakes.
@ttngu207 ttngu207 merged commit 408b4e3 into main Jun 2, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants