Repository navigation
IBL raw data quality metrics - #4823
JoeZiminski wants to merge 29 commits into
Conversation
This reverts commit 8f311f5.
|
@JoeZiminski let me drop here also our AIND QC module: https://github.com/AllenNeuralDynamics/aind-ephys-processing-qc |
|
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 |
|
Hey @alejoe91 have moved the code into a new |
…keinterface into raw-data-quality-metrics
| _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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 : |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
Ah, I see - I didn't read the docstrings carefully enough, I thought it was affecting the plots. I think it's ok.
| 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
|
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 |
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:
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
DataQualityMetricsmodule to compute various metrics after the pipeline has run, using spikes from the sorter.Their metrics are summarized in:
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 = Falseflag that turns off the rolling RMS computation.