API reference
Analysis
Windowed signal-quality analysis orchestration.
analyze(recording, *, window_seconds=None, step_seconds=None, threshold=0.5, model=None, include_partial=True)
Analyze every channel and aggregate each window conservatively by median.
Scores are calibrated estimates from the selected model, not guarantees of clinical usability. The threshold is an application policy and should be validated for the intended downstream task.
Source code in src/biosqi/analysis.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
Input readers
Readers for common biomedical and array file formats.
OptionalDependencyError
Bases: ImportError
Raised when a file reader's explicitly optional package is unavailable.
Source code in src/biosqi/io.py
15 16 | |
read_csv(path, *, sample_rate, signal_type=SignalType.GENERIC)
Read a numeric CSV/TSV where rows are samples and columns are channels.
Source code in src/biosqi/io.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
read_edf(path, *, signal_type=SignalType.GENERIC)
Read EDF/BDF via pyedflib; channels must share a sample rate.
Source code in src/biosqi/io.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
read_numpy(path, *, sample_rate=None, signal_type=SignalType.GENERIC, channel_axis=0)
Read .npy or .npz arrays.
An NPZ may store data, sample_rate (or fs), and channel_names.
Plain NPY inputs require sample_rate.
Source code in src/biosqi/io.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
read_recording(path, *, sample_rate=None, signal_type=SignalType.GENERIC, channel_axis=0)
Dispatch to a reader based on the source suffix.
Source code in src/biosqi/io.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
read_wfdb(path, *, signal_type=SignalType.ECG)
Read a WFDB record using the optional wfdb package.
Source code in src/biosqi/io.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
Profiles
Signal-family profiles used to select physiologically relevant SQIs.
SignalProfile
dataclass
Frequency and beat-rate assumptions for one signal family.
Bounds are deliberately broad. They are engineering defaults for quality triage, not diagnostic limits and not claims about individual physiology.
Source code in src/biosqi/profiles.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
get_profile(signal_type)
Return the profile for an enum or case-insensitive string.
Source code in src/biosqi/profiles.py
38 39 40 41 42 43 44 45 46 47 48 49 50 | |
Windowing
Deterministic sample-domain window generation.
iter_windows(recording, window_seconds, step_seconds, *, include_partial=True)
Yield channel-major views over a recording in ascending sample order.
Source code in src/biosqi/windowing.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
seconds_to_samples(seconds, sample_rate, *, name='duration')
Convert seconds to samples using stable half-up rounding.
Source code in src/biosqi/windowing.py
12 13 14 15 16 17 18 19 20 21 22 | |
window_bounds(n_samples, sample_rate, window_seconds, step_seconds, *, include_partial=True)
Return deterministic half-open bounds, without padding or duplicated tails.
Source code in src/biosqi/windowing.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
Indicators
Numerically robust signal-quality indicators.
Normalized qualities and artifact thresholds in this module are transparent engineering heuristics. They are not clinical decision limits and should be recalibrated on a labelled, task-representative dataset.
baseline_wander_ratio(values, sample_rate, baseline_band, physiological_band)
Measure baseline-band power relative to physiological-band power.
Baseline power ratios are motivated by Clifford et al., Physiol. Meas. 33(9), 2012. Profile bands and the ratio-to-score transform are heuristic.
Source code in src/biosqi/indicators.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
beat_agreement_template(values, sample_rate, signal_type, rate_bpm)
Compare two independent beat detectors and beat-template morphology.
Detector agreement as a quality concept follows Clifford et al., Physiol. Meas. 33(9), 2012; template correlation follows Orphanidou et al., IEEE J. Biomed. Health Inform. 19(3), 2015. The 150 ms tolerance and equal score weighting are explicit heuristics, not clinical thresholds.
Source code in src/biosqi/indicators.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
clipping_flatline_rms(values)
Measure clipping, flat-line occupancy, and RMS amplitude.
Flat-line and saturation checks are common in Li et al., Physiol. Meas. 29(1), 2008. Without ADC limits, clipping is inferred from repeated extrema; the 1% tolerance and score weights are dataset-agnostic heuristics.
Source code in src/biosqi/indicators.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
compute_indicators(values, sample_rate, profile)
Compute all applicable indicators without allowing one failure to abort a window.
Source code in src/biosqi/indicators.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
detect_peaks_energy(values, sample_rate, signal_type, rate_bpm)
Detect beats from derivative energy and adaptive local maxima.
Squared derivative integration follows Pan and Tompkins, IEEE Trans. Biomed. Eng. BME-32(3), 1985. Parameters are simplified for quality agreement and must not be treated as a diagnostic QRS detector.
Source code in src/biosqi/indicators.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
detect_peaks_prominence(values, sample_rate, signal_type, rate_bpm)
Detect beats using bandpass amplitude and robust prominence.
This intentionally simple detector is independent of the energy detector. Its filtering/peak-search structure is inspired by Elgendi, PLoS ONE 8(10), 2013 for PPG and Hamilton, Comput. Cardiol., 2002 for ECG.
Source code in src/biosqi/indicators.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
distribution_shape(values)
Return skewness and Pearson kurtosis with a conservative morphology score.
Orphanidou et al., IEEE J. Biomed. Health Inform. 19(3), 2015 discuss statistical ECG quality features. No universal target distribution exists; the score only down-weights very extreme shape statistics.
Source code in src/biosqi/indicators.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
line_noise_ratio(values, sample_rate)
Measure 50/60 Hz power relative to nearby high-frequency power.
Power-line interference assessment is consistent with Clifford et al., Physiol. Meas. 33(9), 2012. The 1 Hz bands and exponential score mapping are transparent engineering choices, not validated clinical thresholds.
Source code in src/biosqi/indicators.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
periodicity_autocorrelation(values, sample_rate, rate_bpm)
Find the strongest normalized autocorrelation at plausible beat lags.
Autocorrelation SQIs follow the periodicity principle in Li et al., Physiol. Meas. 29(1), 2008. Plausible rate bounds come from the selected profile and are broad quality-analysis assumptions, not diagnostic limits.
Source code in src/biosqi/indicators.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
spectral_band_power_ratio(values, sample_rate, band)
Return in-band/total spectral power.
The Welch estimator follows Welch, IEEE Trans. Audio Electroacoustics 15(2), 1967. Band limits are profile defaults, not universal physiology.
Source code in src/biosqi/indicators.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
spectral_entropy(values, sample_rate)
Estimate normalized spectral entropy.
Spectral entropy as an SQI follows the information-theoretic approach used by Zhang et al., IEEE Trans. Biomed. Eng. 62(9), 2015. The quality mapping, centered on moderate entropy, is heuristic because either extreme can be poor depending on signal family.
Source code in src/biosqi/indicators.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
Fusion and calibration
Logistic SQI fusion with monotone isotonic calibration.
FusionModel
dataclass
Serializable logistic model followed by piecewise-linear isotonic calibration.
Source code in src/biosqi/fusion.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
predict(indicators)
Fuse valid indicator qualities; missing features use the documented neutral value.
Source code in src/biosqi/fusion.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
FusionOutput
dataclass
One model prediction and its per-indicator log-odds contributions.
Source code in src/biosqi/fusion.py
21 22 23 24 25 26 27 | |
fit_fusion_model(features, labels, feature_names, *, name='fitted-logistic-isotonic', random_state=0)
Fit logistic fusion with isotonic calibration on out-of-fold predictions.
Source code in src/biosqi/fusion.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
load_default_model()
Load the package's explicitly versioned default heuristic model.
Source code in src/biosqi/fusion.py
123 124 125 126 127 128 129 130 | |
Artifact attribution
Transparent conversion of indicator deficits into artifact likelihoods.
attribute_artifacts(indicators, model)
Aggregate 1 - quality by artifact using absolute model weights.
Values are relative diagnostic severities, not probabilities. Invalid or non-applicable indicators are omitted instead of being silently called bad.
Source code in src/biosqi/attribution.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Domain objects
Typed domain objects shared by the numerical core and command-line interface.
AnalysisResult
dataclass
Complete, serializable output of a quality analysis.
Source code in src/biosqi/types.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
ChannelResult
dataclass
Quality result for one channel in one window.
Source code in src/biosqi/types.py
108 109 110 111 112 113 114 115 116 | |
IndicatorResult
dataclass
One indicator's normalized quality and transparent diagnostic evidence.
Source code in src/biosqi/types.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
Recording
dataclass
A sampled, channel-major biomedical recording.
Source code in src/biosqi/types.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
SignalType
Bases: str, Enum
Supported biomedical signal families.
Source code in src/biosqi/types.py
16 17 18 19 20 21 22 23 | |
SignalWindow
dataclass
A deterministic half-open sample window into a recording.
Source code in src/biosqi/types.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
WindowResult
dataclass
Aggregated result for one recording window.
Source code in src/biosqi/types.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
source_name(path)
Return a stable display name for a source path.
Source code in src/biosqi/types.py
160 161 162 163 | |