compare
Compare frame files or directories for consistency (data and metadata).
ComparisonResult
dataclass
¶
ComparisonResult(file_results: list[FileComparison])
Result of comparing two paths (files or directories).
Attributes:
| Name | Type | Description |
|---|---|---|
file_results |
list[FileComparison]
|
Per-file-pair comparison results |
Difference
dataclass
¶
Difference(category: str, field: str, left: str, right: str, channel: str | None = None, frame_index: int | None = None, detail: str = '')
A single difference found between two frame files.
Attributes:
| Name | Type | Description |
|---|---|---|
category |
str
|
One of 'error', 'structure', 'channels', 'metadata', 'data' |
field |
str
|
What differed, e.g. 'num_frames', 'start', 'duration', 'dtype', 'sample_rate', 'n_samples', 'unit', 'type', 'values', 'mask', 'only_in_left', 'only_in_right', 'unmatched_file' |
left |
str
|
Rendered left-side value ('-' if absent on that side) |
right |
str
|
Rendered right-side value ('-' if absent on that side) |
channel |
str or None
|
Channel name, or None for file/frame-level differences |
frame_index |
int or None
|
Frame index, or None for file-level differences |
detail |
str
|
Extra context, e.g. sample mismatch statistics |
FileComparison
dataclass
¶
FileComparison(left: Path | None, right: Path | None, differences: list[Difference], channels_compared: int, frames_compared: int)
Result of comparing a single pair of frame files.
Attributes:
| Name | Type | Description |
|---|---|---|
left |
Path or None
|
Left-side file (None if this side had no matching file) |
right |
Path or None
|
Right-side file (None if this side had no matching file) |
differences |
list[Difference]
|
All differences found between the two files |
channels_compared |
int
|
Number of channels compared |
frames_compared |
int
|
Number of frame pairs compared |
compare_files ¶
compare_files(left: str | PathLike[str], right: str | PathLike[str], *, channels: Sequence[str] | None = None, common_channels: bool = False, common_time_spans: bool = False, ignore_channel_type: bool = False, metadata_only: bool = False, rtol: float = 0.0, atol: float = 0.0) -> FileComparison
Compare two GWF files for consistency.
Checks channel sets, frame structure (count and time spans), per-channel metadata (type, dtype, sample rate, sample count, unit), and sample data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
str or path - like
|
First GWF file |
required |
right
|
str or path - like
|
Second GWF file |
required |
channels
|
Sequence[str]
|
Compare only these channels. Channels found on neither side raise ChannelNotFoundError. |
None
|
common_channels
|
bool
|
If True, compare only channels present on both sides; channels present on one side only are not reported as differences. |
False
|
common_time_spans
|
bool
|
If True, pair frames by (start, duration) time span and skip frames present on one side only, instead of pairing frames by index and reporting count/span mismatches. |
False
|
ignore_channel_type
|
bool
|
If True, do not report channel type (adc/proc/sim) differences, e.g. when the same data is stored as ADC on one side and proc on the other. |
False
|
metadata_only
|
bool
|
If True, skip sample data comparison (faster). |
False
|
rtol
|
float
|
Relative tolerance for floating-point data comparison. Default 0.0 (exact comparison, with NaN == NaN). |
0.0
|
atol
|
float
|
Absolute tolerance for floating-point data comparison (default: 0.0). |
0.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
FileComparison
|
Structured comparison result; |
Examples:
>>> result = gwframe.compare_files('a.gwf', 'b.gwf')
>>> if not result.consistent:
... for diff in result.differences:
... print(diff)
Source code in gwframe/compare.py
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 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
compare_paths ¶
compare_paths(left: str | PathLike[str], right: str | PathLike[str], *, recursive: bool = False, channels: Sequence[str] | None = None, common_channels: bool = False, common_time_spans: bool = False, ignore_channel_type: bool = False, metadata_only: bool = False, rtol: float = 0.0, atol: float = 0.0) -> ComparisonResult
Compare two paths (GWF files or directories of GWF files).
When both paths are files they are compared directly. Otherwise each
path is expanded to its GWF files and frames are paired across sides
by their (start, duration) GPS span, regardless of which file holds
them, so two productions of the same data compare equal even when their
file boundaries differ. Results are grouped per pair of files that
shared frames. Frames with no counterpart are reported per frame, or as
one unmatched_file difference when a whole file has none, unless
common_time_spans is set, in which case they are silently skipped.
common_time_spans likewise skips files that disappear from disk
while the comparison is running (e.g. removed from a live retention
window); open failures where the file still exists are always
reported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
str or path - like
|
First GWF file or directory |
required |
right
|
str or path - like
|
Second GWF file or directory |
required |
recursive
|
bool
|
Search directories recursively for GWF files (default: False) |
False
|
channels
|
Sequence[str] | None
|
|
None
|
common_channels
|
Sequence[str] | None
|
|
None
|
common_time_spans
|
Sequence[str] | None
|
|
None
|
ignore_channel_type
|
Sequence[str] | None
|
|
None
|
metadata_only
|
bool
|
See :func: |
False
|
rtol
|
bool
|
See :func: |
False
|
atol
|
bool
|
See :func: |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ComparisonResult
|
Results per pair of files that shared frames; |
Examples:
>>> result = gwframe.compare_paths('dir1/', 'dir2/', common_channels=True)
>>> print(f"{result.num_differences} differences")
Source code in gwframe/compare.py
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 | |