canvod.audit API Reference¶
Audit, comparison, and regression verification for canvodpy GNSS-VOD pipelines.
Core¶
Core comparison engine for canvod-audit.
The main entry point is compare_datasets(), which aligns two xarray
Datasets on shared coordinates and computes per-variable statistics
with configurable tolerance tiers.
ComparisonResult
dataclass
¶
Result of comparing two datasets.
Attributes¶
label : str Human-readable label for this comparison. variable_stats : dict[str, VariableStats] Per-variable statistics. tier : ToleranceTier Tolerance tier used. passed : bool True if all variables are within tolerance for the given tier. For EXACT tier this is equivalent to bit-identical; for SCIENTIFIC tier it means within the stated per-variable tolerances. failures : dict[str, str] Variables that failed, with a reason string. metadata : dict[str, Any] Free-form metadata (source paths, timestamps, configs). alignment : AlignmentInfo Information about coordinate alignment.
Source code in packages/canvod-audit/src/canvod/audit/core.py
24 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 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 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 142 | |
to_polars()
¶
Return per-variable stats as a polars DataFrame.
Source code in packages/canvod-audit/src/canvod/audit/core.py
57 58 59 60 61 62 63 64 | |
summary()
¶
Human-readable summary string.
Source code in packages/canvod-audit/src/canvod/audit/core.py
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 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 142 | |
AlignmentInfo
dataclass
¶
Information about how two datasets were aligned.
Source code in packages/canvod-audit/src/canvod/audit/core.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 | |
compare_datasets(ds_a, ds_b, *, variables=None, tier=ToleranceTier.NUMERICAL, tolerance_overrides=None, label='', align=True, metadata=None, report_coverage=False)
¶
Compare two xarray Datasets variable-by-variable.
Parameters¶
ds_a, ds_b : xarray.Dataset
Datasets to compare. ds_a is typically the candidate (canvodpy),
ds_b the reference.
variables : list[str], optional
Variables to compare. If None, uses the intersection of both datasets'
data variables.
tier : ToleranceTier
Comparison strictness level.
tolerance_overrides : dict[str, Tolerance], optional
Per-variable tolerance overrides.
label : str
Human-readable label for this comparison.
align : bool
If True, align datasets on shared (epoch, sid) coordinates.
metadata : dict, optional
Free-form metadata to attach to the result.
Returns¶
ComparisonResult
Source code in packages/canvod-audit/src/canvod/audit/core.py
384 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 424 425 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 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
Statistics¶
Statistical comparison functions for paired arrays.
All functions operate on flat numpy arrays and handle NaN masking consistently: statistics are computed only over mutually non-NaN values.
This module also provides the observable-difference reporting framework:
VariableBudget, VarDiffStats, compute_diff_report, and
print_diff_report. These support the scientific principle that every
observable difference must be reported with actual numbers and annotated
against a physically-grounded expected budget — never hidden in tolerances.
VariableStats
dataclass
¶
Per-variable comparison statistics.
Source code in packages/canvod-audit/src/canvod/audit/stats.py
225 226 227 228 229 230 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 271 272 273 274 275 276 277 | |
as_dict()
¶
Flat dict for DataFrame construction.
Source code in packages/canvod-audit/src/canvod/audit/stats.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
compute_variable_stats(name, a, b, exact_match=None)
¶
Compute all comparison statistics for a single variable.
Parameters¶
name : str
Variable name.
a, b : np.ndarray
Arrays of equal shape to compare.
exact_match : bool, optional
Pre-computed exact equality (e.g. from da.equals()).
If None, inferred as max_abs_diff == 0.
Source code in packages/canvod-audit/src/canvod/audit/stats.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 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 424 425 | |
rmse(a, b)
¶
Root Mean Square Error over mutually valid elements.
Source code in packages/canvod-audit/src/canvod/audit/stats.py
285 286 287 288 289 290 291 | |
bias(a, b)
¶
Mean difference (a - b) over mutually valid elements.
Source code in packages/canvod-audit/src/canvod/audit/stats.py
294 295 296 297 298 299 | |
mae(a, b)
¶
Mean Absolute Error over mutually valid elements.
Source code in packages/canvod-audit/src/canvod/audit/stats.py
302 303 304 305 306 307 | |
max_abs_diff(a, b)
¶
Maximum absolute difference over mutually valid elements.
Source code in packages/canvod-audit/src/canvod/audit/stats.py
310 311 312 313 314 315 | |
correlation(a, b)
¶
Pearson correlation over mutually valid elements.
Source code in packages/canvod-audit/src/canvod/audit/stats.py
318 319 320 321 322 323 324 | |
nan_agreement(a, b)
¶
Fraction of elements where NaN status agrees (both NaN or both finite).
Source code in packages/canvod-audit/src/canvod/audit/stats.py
327 328 329 330 331 332 | |
Tolerances¶
Tolerance definitions for numerical comparison.
Three tiers of comparison strictness, from bit-identical to domain-specific scientific thresholds.
TIER_DEFAULTS = {ToleranceTier.EXACT: Tolerance(atol=0.0, mae_atol=0.0, description='Bit-identical comparison'), ToleranceTier.NUMERICAL: Tolerance(atol=1e-06, mae_atol=1e-10, description='Float64 precision — atol bounds worst-case single-element error from operation reordering; mae_atol bounds typical (MAE) error.'), ToleranceTier.SCIENTIFIC: Tolerance(atol=0.01, mae_atol=0.01, description='Domain-specific scientific tolerance')}
module-attribute
¶
SCIENTIFIC_DEFAULTS = {'SNR': Tolerance(atol=0.25, mae_atol=0.0, nan_rate_atol=0.01, description='SBF quantization is 0.25 dB; RINEX ~0.001 dB. Hardware limitation.'), 'vod': Tolerance(atol=0.01, mae_atol=0.01, nan_rate_atol=0.01, description='VOD retrieval: sub-0.01 differences are below measurement noise.'), 'phi': Tolerance(atol=0.05, mae_atol=0.0, nan_rate_atol=0.0, description='Elevation angle: coordinate conversion differences up to ~2.4 deg observed between implementations (wrap-aware).'), 'theta': Tolerance(atol=0.05, mae_atol=0.0, nan_rate_atol=0.0, description='Azimuth angle: coordinate conversion differences.'), 'carrier_phase': Tolerance(atol=1e-06, mae_atol=1e-09, nan_rate_atol=0.01, description='Carrier phase: high-precision observable, expect near-exact agreement.'), 'pseudorange': Tolerance(atol=0.001, mae_atol=1e-06, nan_rate_atol=0.01, description='Pseudorange: meter-level observable.'), 'sat_x': Tolerance(atol=0.001, mae_atol=1e-09, nan_rate_atol=0.05, description='Satellite X coordinate (meters). NaN rate may differ due to broadcast vs SP3 satellite coverage.'), 'sat_y': Tolerance(atol=0.001, mae_atol=1e-09, nan_rate_atol=0.05, description='Satellite Y coordinate (meters).'), 'sat_z': Tolerance(atol=0.001, mae_atol=1e-09, nan_rate_atol=0.05, description='Satellite Z coordinate (meters).')}
module-attribute
¶
Tolerance
dataclass
¶
Numerical tolerance for a single variable comparison.
A variable passes if ALL of the following hold:
max_abs_diff <= atol— worst-case single-element errormae <= mae_atol— typical (mean) error, whenmae_atol > 0|NaN_rate_a - NaN_rate_b| <= nan_rate_atol
Parameters¶
atol : float Absolute tolerance on maximum single-element error. mae_atol : float Absolute tolerance on Mean Absolute Error (typical error). Set to 0 to skip this check. nan_rate_atol : float Maximum allowed difference in NaN rates between the two datasets. 0.0 means NaN patterns must match exactly. description : str Human-readable justification for this tolerance (for the paper).
Source code in packages/canvod-audit/src/canvod/audit/tolerances.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 38 39 40 | |
ToleranceTier
¶
Bases: Enum
Pre-defined comparison strictness levels.
Source code in packages/canvod-audit/src/canvod/audit/tolerances.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
EXACT = 'exact'
class-attribute
instance-attribute
¶
Bit-identical. atol=0, mae_atol=0. Use for values that should be computed from the same source data with the same algorithm.
NUMERICAL = 'numerical'
class-attribute
instance-attribute
¶
Float64 precision. atol=1e-6, mae_atol=1e-10. Use for values that should be mathematically identical but may differ due to floating-point operation ordering.
SCIENTIFIC = 'scientific'
class-attribute
instance-attribute
¶
Domain-specific thresholds per variable. Use for comparisons across independent implementations or data sources where small physical differences are expected (e.g. SBF 0.25 dB SNR quantization).
get_tolerance(variable, tier, overrides=None)
¶
Look up the tolerance for a variable at a given tier.
Resolution order:
1. overrides[variable] if provided
2. SCIENTIFIC_DEFAULTS[variable] if tier is SCIENTIFIC
3. TIER_DEFAULTS[tier] (catch-all)
Source code in packages/canvod-audit/src/canvod/audit/tolerances.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
Tiers — Internal¶
Internal consistency comparisons within canvodpy.
Compare outputs from different processing paths that should produce equivalent results: SBF vs RINEX readers, broadcast vs agency ephemeris.
compare_sbf_vs_rinex(store_sbf, store_rinex, *, group, variables=None)
¶
Compare SBF and RINEX reader outputs from the same observation period.
Parameters¶
store_sbf : MyIcechunkStore Store populated from SBF files. store_rinex : MyIcechunkStore Store populated from RINEX files. group : str Date group key (e.g. "2025001"). variables : list[str], optional Variables to compare. Defaults to intersection.
Returns¶
ComparisonResult SCIENTIFIC tier — expects SNR quantization differences (0.25 dB) and potentially different satellite coverage.
Source code in packages/canvod-audit/src/canvod/audit/tiers/internal.py
18 19 20 21 22 23 24 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 50 51 52 53 54 55 56 57 58 59 | |
compare_ephemeris_sources(store_broadcast, store_agency, *, group, variables=None)
¶
Compare broadcast vs agency (SP3/CLK) ephemeris augmentation.
Parameters¶
store_broadcast : MyIcechunkStore Store augmented with broadcast ephemeris (from SBF SatVisibility). store_agency : MyIcechunkStore Store augmented with agency products (SP3 + CLK). group : str Date group key.
Returns¶
ComparisonResult SCIENTIFIC tier — broadcast ephemeris has lower accuracy than precise products (~1-2m vs ~2cm orbit accuracy).
Source code in packages/canvod-audit/src/canvod/audit/tiers/internal.py
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 | |
Tiers — Regression¶
Regression verification against frozen reference outputs.
Freeze a known-good output as a checkpoint, then compare future outputs against it to detect regressions.
freeze_checkpoint(ds, output_path, *, metadata=None)
¶
Save a dataset as a NetCDF checkpoint for future regression testing.
Parameters¶
ds : xarray.Dataset The known-good reference output. output_path : Path Where to write the checkpoint file (.nc). metadata : dict, optional Metadata to store as dataset attributes (git hash, date, config).
Returns¶
Path The written checkpoint path.
Source code in packages/canvod-audit/src/canvod/audit/tiers/regression.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
compare_against_checkpoint(ds, checkpoint_path, *, variables=None, tier=ToleranceTier.EXACT, label='')
¶
Compare a dataset against a frozen checkpoint.
Parameters¶
ds : xarray.Dataset Current output to verify. checkpoint_path : Path Path to the reference checkpoint (.nc file). variables : list[str], optional Variables to compare. Defaults to intersection. tier : ToleranceTier Default EXACT — regressions should produce identical output. label : str Comparison label.
Returns¶
ComparisonResult
Source code in packages/canvod-audit/src/canvod/audit/tiers/regression.py
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 | |
Tiers — External¶
External intercomparison with independent implementations.
Compare canvodpy outputs against gnssvod (Humphrey et al.) — the established community GNSS-VOD processing tool.
This module provides the low-level compare_vs_gnssvod function.
For the full audit workflow (with AuditResult), use
canvod.audit.runners.vs_gnssvod.audit_vs_gnssvod instead.
compare_vs_gnssvod(ds_canvod, ds_or_df_gnssvod, *, band_filter='L1|C', snr_col='S1C', vod_col='VOD1', variables=None, label='canvodpy vs gnssvod', gnssvod_epoch_col='Epoch', gnssvod_sid_col='SV')
¶
Compare canvodpy output against gnssvod output for one band.
Uses GnssvodAdapter to project canvodpy into gnssvod variable
space before comparison, ensuring identical variable names, units,
and conventions.
Parameters¶
ds_canvod : xarray.Dataset
canvodpy output (epoch, sid) dataset.
ds_or_df_gnssvod : xarray.Dataset or pandas.DataFrame
gnssvod output. If a pandas DataFrame, it is automatically
converted to xarray.
band_filter : str
SID band suffix, e.g. "L1|C" or "L2|W".
snr_col : str
gnssvod SNR column name for this band.
vod_col : str or None
gnssvod VOD column name for this band.
variables : list[str], optional
Variables to compare. Defaults to all shared variables.
label : str
Comparison label.
gnssvod_epoch_col, gnssvod_sid_col : str
Column names in gnssvod DataFrame.
Returns¶
ComparisonResult SCIENTIFIC tier — two independent implementations.
Source code in packages/canvod-audit/src/canvod/audit/tiers/external.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 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 114 115 116 117 | |
Reporting — Tables¶
Table export for audit results: LaTeX, Markdown, Polars.
to_polars(result)
¶
Return per-variable stats as a polars DataFrame.
Source code in packages/canvod-audit/src/canvod/audit/reporting/tables.py
11 12 13 | |
to_markdown(result)
¶
Render per-variable stats as a Markdown table.
Source code in packages/canvod-audit/src/canvod/audit/reporting/tables.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
to_latex(result, *, caption='', label='')
¶
Render per-variable stats as a LaTeX table.
Produces a tabular environment inside a table float, ready
to paste into a paper.
Source code in packages/canvod-audit/src/canvod/audit/reporting/tables.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 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
Reporting — Figures¶
Publication-quality figures for audit results.
plot_diff_histogram(ds_a, ds_b, variable, *, ax=None, bins=100, title=None)
¶
Histogram of element-wise differences (a - b) for a single variable.
Returns a matplotlib Figure.
Source code in packages/canvod-audit/src/canvod/audit/reporting/figures.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
plot_scatter(ds_a, ds_b, variable, *, ax=None, title=None, label_a='Dataset A', label_b='Dataset B', max_points=50000)
¶
Scatter plot of variable values: a vs b with 1:1 line.
Returns a matplotlib Figure.
Source code in packages/canvod-audit/src/canvod/audit/reporting/figures.py
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 | |
plot_summary_dashboard(result, *, figsize=(12, 6))
¶
Multi-panel summary of a ComparisonResult.
Bar chart of RMSE per variable + pass/fail indicators. Returns a matplotlib Figure.
Source code in packages/canvod-audit/src/canvod/audit/reporting/figures.py
110 111 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 142 143 144 145 146 147 148 149 150 151 152 153 | |