Skip to content

IBL raw data quality metrics - #4823

Open
JoeZiminski wants to merge 29 commits into
SpikeInterface:mainfrom
JoeZiminski:raw-data-quality-metrics
Open

JoeZiminski wants to merge 29 commits into
SpikeInterface:mainfrom
JoeZiminski:raw-data-quality-metrics

Conversation

@JoeZiminski

@JoeZiminski JoeZiminski commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

This PR implements some (but not all) of the IBL's raw data quality metrics. According to the IBL's white paper (version two) their quality metrics are:

  1. Over 1s chunks every 300 seconds, compute:
  • Power spectral density (Welch) (num_channel x num_freqs(
  • RMS (num_channel x 1)

then take the median RMS across all of the chunks (giving noise estimate per-channel) and the 10-90 quantile across channels (giving spread of noise across channels). They also average all of the Welch PSDs into a single representattive. They do this across AP and LFP, before and after preprocessing.

Further, they compute a rolling RMS over consecutive 3s chunks, I believe only for AP preprocessed and LFP.

They also do a quick spike detection using a threshold method. Here I skipped this, as it is not simple AFAICT to have a static threshold across different recordings (rather than the threshold being a multiple of the noise) and it is not easy to find such a threshold across recordings. Instead i would be better for a general-purpose DataQualityMetrics module to compute various metrics after the pipeline has run, using spikes from the sorter.

Their metrics are summarized in:

image image

This is a draft implementation still up for discussion so I've not implemented tests or documentation yet as it might change. @oliche here I have demeaned the RMS for better comparison between raw and preprocessed, and for the PSD taken chunks, computed periodogram (Hann window) and averaged over these PSDs, so a kind of non-overlapping Welch. Am curios as to your opinion on these design choices.

The runtime is fast for the metrics computed over chunks (RMS, PSD), by default the number of chunks is set to 30 so this is constant with recording size and only takes a few seconds. The rolling RMS is much slower. By default, this only computes rolling RMS on the preprocessed data (and LFP if passed). I think in most cases people will only be passing the AP band. It took around 1m30 on raw data, 7m16 on HP filtered data and 9m26 on LFP data. For this reason there is also a quick_metrics_only: bool = False flag that turns off the rolling RMS computation.

@alejoe91

Copy link
Copy Markdown
Member

@JoeZiminski let me drop here also our AIND QC module: https://github.com/AllenNeuralDynamics/aind-ephys-processing-qc

@JoeZiminski
JoeZiminski marked this pull request as ready for review October 22, 2026 18:10
@JoeZiminski

JoeZiminski commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey @alejoe91 thanks for this! This PR should be ready for review / feedback on the implementation (no tests or docs yet), I think test failures are unrelated.

For the raw data QC we cover the PSD and noise, but am missing "raw data: snippets of AP and LFP traces at multiple points over the session" - could make sense to also write this to the output folder in this PR?

I wonder if a general DataQC module can somehow combine the outputs from raw data quality metrics, artefact detection (if run), and sorting to cover all bases (drift raster map, saturation, unit yield, firing rate)

@JoeZiminski JoeZiminski changed the title [WIP] IBL raw data quality metrics IBL raw data quality metrics Oct 22, 2026
@alejoe91

Copy link
Copy Markdown
Member

Hey @alejoe91 thanks for this! This PR should be ready for review / feedback on the implementation (no tests or docs yet), I think test failures are unrelated.

For the raw data QC we cover the PSD and noise, but am missing "raw data: snippets of AP and LFP traces at multiple points over the session" - could make sense to also write this to the output folder in this PR?

I wonder if a general DataQC module can somehow combine the outputs from raw data quality metrics, artefact detection (if run), and sorting to cover all bases (drift raster map, saturation, unit yield, firing rate)

Yes I think that a separate "qc" or spelled out "qualitycontrol" module with full metric plots and potentially also some automatic assessment is the way to go. Let's move things there! I think it can have both compute and plotting, since the application is very specific

@JoeZiminski

Copy link
Copy Markdown
Contributor Author

Hey @alejoe91 have moved the code into a new qualitycontrol module. If you agree with the general shape I'll add documentation and tests. @chrishalcrow might also be intereted in a quick look, we were recently discussing the idea of having a raw-data quality metrics and sorting output quality metrics (e.g. drift maps, unit locations etc). Maybe these could be submodules of this new module? raw_data and sorting_output or something.

_write_rms_summary_csvs(folder, all_chunk_results)

for segment_index in range(raw_ap_recording.get_num_segments()):
widget = plot_raw_data_quality_metrics(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might be a good idea, but we don't usually mix computation and ploting. E.g. in motion we get the users to compute the motion, then separately make plots. And for the analyzer, we have a separation of computation and plotting.

I'm not sure what I think we should do; just bringing it up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @chrishalcrow yes I agree here, I did it as a convenience for pipeline building but it is more in keeping with spikeinterface to keep these separate. It is trivial to handle this in the pipleine itself, and the separation gives better flexibility for SI users

chunk_size_s :
The size of the chunks for non-consecutive uniform sampling used
for RMS median, quantiles and PSD computation. Uses the IBLs 1s default.
num_chunks :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My intuition would say that num_chunks should scale with the length of the recording.

E.g. suppose you run this on a 10 minute recording and a 60 minute recording and want to compare results. You might want to check that the some quantity is changing on the same timescale in both recordings. This comparison is easier to see if the sampling is similar, and the time axis has the same scale. That makes me think that num_chunks should scale linearly with recording length by default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For this, it affects only the computation of the RMS median, quantiles (scalars) and the PSD (channel x frequency). For the RMS, the RMS is computed per-chunk then the median value taken across chunks, for PSD it is like an average over the PSD of each chunk. This is separate from the rolling RMS plots, in which each chunk is always consecutive, and the window size default is fixed across different session lengths (3s) (rolling_rms_window_size_s).

One benefit of keeping the chunk size the same across recordings is the variance of the measures doesn't scale with the recording. That being said, if we have more data we might want to use it!

But this API is quite confusing, we have:
chunk_size_s and num_chunks (for the non-consecutive chunks for RMS, PSD)
rolling_rms_window_size_s for the consecutive chunks (plots)

not sure if there is a better way to handle this 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I see - I didn't read the docstrings carefully enough, I thought it was affecting the plots. I think it's ok.

Comment on lines +76 to +79
quick_metrics_only : bool, default: False
Compute only the sampled RMS summaries and PSD. Skip rolling RMS for all
recordings, including LFP and raw AP even if ``compute_raw_rolling_rms=True``.
The returned ``rolling_rms`` dictionary is empty in this mode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have this type of argument (skip_pc_metrics) in the metrics module and I never really liked it. Especially because we don't really know what "quick" means to each end user. In the future, we might make a really fast implementation of a slow metric, and then decide to change what's included in "quick" and "slow, which I think it a bit confusing.

I'd prefer if the function accepted a list of metric names and we documented a list of "quick" ones that the user can pass if they'd like. This also gives the user flexibility over which raw metrics to compute. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, that's more explicit and future-proof. It's also a bit weird that it compute_raw_rolling_rms even if its explicitly set to True!

@JoeZiminski

Copy link
Copy Markdown
Contributor Author

thanks @chrishalcrow! I will address the two points (+ we can discuss the third) then add docs and tests and I think this will be good to go

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