Potential bug in `to_ibl.py` raw data metrics PSD calculation

Open
#4,891 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
numpy, python
Domain
backend, data

Research direction

Start with src/spikeinterface/exporters/to_ibl.py at the PSD calculation around line 219, and trace how randomly sampled LFP chunks are passed to Welch. Check the relevant exporter tests and how they validate PSD metrics. Done when the PSD is computed from consecutive samples and a regression test covers the result.

Written by the indexing model from the issue text.

Description

bug exporters

Currently in to_ibl.py the PSD computation for LFP is computed as:

lfp_sample_data = get_random_data_chunks(
    lfp_recording,
    num_chunks_per_segment=psd_num_chunks,
    chunk_duration=f"{psd_chunk_duration_s}s",
    return_in_uV=True,
    concatenated=True,
)
psd = np.zeros((welch_win_length_samples // 2 + 1, lfp_sample_data.shape[1]), dtype=np.float32)
for i_channel in range(lfp_sample_data.shape[1]):
    freqs, Pxx = welch(
        lfp_sample_data[:, i_channel],
        fs=lfp_recording.sampling_frequency,
        nperseg=welch_win_length_samples,
    )
    psd[:, i_channel] = Pxx

Here the randomly sampled chunks of 1s (30k samples) which are concatenated then passed to Welch with chunk size 16384. This then computes the PSD with 50% overlap by default. However, this takes the PSD computation over randomly sampled chunks which are not-consecutive, giving erroneous PSD estimate.

Dominant language
Python
Stars
883
Forks
291
Avg merge
3d 17h
Merged PRs (30d)
40

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SpikeInterface/spikeinterface

All issues in SpikeInterface/spikeinterface

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.