nirspipe.qc.metrics.aggregate#
The dicts a run actually stores, assembled from the families.
One function per signal domain, plus comparable_stage_metrics, which is the one place
that recomputes metrics with a common passband so two stages can be subtracted. Nothing
here measures anything itself; it decides which family applies to which stage and merges
the results. Writing any of it to disk is qc/sqm_record.py’s job.
Module Contents#
Functions#
Metrics computable from raw intensity data (no haemo required). |
|
Haemoglobin metrics that stay valid after bandpass and resampling. |
|
The above plus spectral band power and drift, which need unfiltered input. |
|
|
|
Stage-by-stage metrics that may be compared with each other. |
Data#
API#
- nirspipe.qc.metrics.aggregate.logger = 'get_logger(...)'#
- nirspipe.qc.metrics.aggregate.compute_raw_sqm(raw_intensity: mne.io.Raw, sci_scores: dict[str, float], bad_channels: list[str], cardiac_l_freq: float, cardiac_h_freq: float, good_frac_scores: dict[str, float] | None = None, ceiling: float | None = None, resp_h_freq: float | None = None) dict[str, Any]#
Metrics computable from raw intensity data (no haemo required).
- Parameters:
raw_intensity (
mne.io.Raw) -- Raw intensity, or already-OD, recording.sci_scores (
dict[str,float]) -- Per-channel SCI, as returned bycompute_sci_scores().bad_channels (
list[str]) -- Channel names marked bad.cardiac_l_freq (
float) -- Cardiac band edges in Hz.cardiac_h_freq (
float) -- Cardiac band edges in Hz.good_frac_scores (
dict[str,float]orNone, optional) -- Per-channel share of passing windows, as the screening already counted it. None stores no such entry rather than paying for a second windowed pass.ceiling (
floatorNone, optional) -- The whole recording’s highest intensity, which the saturated share is counted against. Pass it whenraw_intensityis one channel set or one stretch of the recording; None takes the maximum ofraw_intensityitself.resp_h_freq (
floatorNone, optional) -- Top of the respiration band, where the heart rate is looked for from. None stores no heart rate and no wavelength check, as for a trial’s crop, too short for their spectra.
- Returns:
Flat dict of SCI (whole-run and windowed), channel distance, PSP, CP, the heart rate, the cardiac HbO/HbR ratio as labelled and swapped, the passing-window share, and (intensity input only) CV/SNR/amplitude plus motion metrics.
- Return type:
Notes
If the input is already optical density, the intensity-value and motion metrics are meaningless and set to None; SCI, distance, PSP and CP still run.
- nirspipe.qc.metrics.aggregate.compute_haemo_sqm(raw_haemo: mne.io.Raw) dict[str, Any]#
Haemoglobin metrics that stay valid after bandpass and resampling.
For every stage past
preproc, where the signal has usually been filtered, downsampled or regressed. Returns HbO-HbR correlation, CNR, gcor, and data retention. Band power and drift are deliberately absent: past the bandpass they describe the filter rather than the recording, which is whatcompute_prep_haemo_sqmis for.
- nirspipe.qc.metrics.aggregate.compute_prep_haemo_sqm(raw_haemo: mne.io.Raw, cardiac_l_freq: float, cardiac_h_freq: float, resp_l_freq: float, resp_h_freq: float) dict[str, Any]#
The above plus spectral band power and drift, which need unfiltered input.
Band power and drift amplitude describe how much cardiac, respiration, and low-frequency content the recording carries. Once a bandpass has removed those bands they measure the filter rather than the recording, and above the resampled Nyquist they are undefined, so this is restricted to the Beer-Lambert output. Band edges are in Hz.
- nirspipe.qc.metrics.aggregate.in_analysis_band(raw: mne.io.Raw, l_freq: float | None, h_freq: float | None, **design: Any) mne.io.Raw#
rawon the analysis band, filtered only if its stamp records a different band.A stage the bandpass already wrote would otherwise go through the filter twice, and the second pass alone moves its metrics away from those of a stage filtered once:
desc-preproc {dpf: [6.0]} -> band_limited(raw, 0.01, None) desc-filtered {high_pass: 0.01, low_pass: None} -> raw, as stored
- nirspipe.qc.metrics.aggregate.comparable_stage_metrics(stages: list[tuple[str, mne.io.Raw]], l_freq: float | None, h_freq: float | None, cardiac_l_freq: float, cardiac_h_freq: float, resp_l_freq: float, resp_h_freq: float, limited: list[mne.io.Raw] | None = None, design: dict[str, Any] | None = None) dict[str, Any]#
Stage-by-stage metrics that may be compared with each other.
Not read from the record: a record stores each stage measured on the signal as it is at that stage, which is the right thing to store and the wrong thing to subtract. A stage before the bandpass and one after it are dominated by different frequency content, so the difference between their quality metrics is mostly the filter. Every quality metric here is therefore recomputed with every stage on the analysis passband, which is the only way the columns answer the same question. A stage already filtered to that band is read as stored (see
in_analysis_band()):stages = [("desc-preproc", raw_a), ("desc-errts", raw_b)], l_freq=0.02, h_freq=0.2 -> quality["gcor_hbo"] == [<a in 0.02-0.2 Hz>, <b in 0.02-0.2 Hz>]
removedis the opposite case and stays on the signal as stored: those rows exist to show what left the recording, so band-limiting them would erase the answer.bandedis False when no passband was given and the quality rows fall back to as-stored, which the caller should say out loud.limitedis the stages already band-limited, one per stage, for a caller that had to filter before cutting a stretch out; the quality rows read them andremovedstill readsstagesas stored.designis the run’smethodandorder, so the band is applied with the filter the data went through; None takes the pipeline’s default.- Returns:
labels,banded,qualityandremoved({key: value per stage}),variance_remaining, the median share of the first stage’s per-channel variance still present at each stage,hbo_hbr_corr_per_channel, one dict per stage, andno_kept_time, the stages aBAD_span covers whole, which get no spectrum.- Return type: