operations
Core operations for manipulating GWF files.
combine_channels ¶
combine_channels(input_sources: Sequence[str | PathLike[str]], output_dir: str | PathLike[str], keep_channels: Sequence[str] | None = None, drop_channels: Sequence[str] | None = None) -> list[str]
Combine channels from multiple frame sources into single files.
Takes N sources (all files or all directories) covering the same time ranges and combines their channels. Sources are matched by time range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_sources
|
sequence of str or path-like
|
List of N source files or N source directories to combine. All sources must be the same type (all files or all directories). |
required |
output_dir
|
str or path - like
|
Directory where output files will be written |
required |
keep_channels
|
sequence of str
|
If specified, only include these channels in the output. Mutually exclusive with drop_channels. |
None
|
drop_channels
|
sequence of str
|
If specified, exclude these channels from the output. Mutually exclusive with keep_channels. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
output_files |
list[str]
|
List of output file paths created |
Examples:
>>> # Combine 2 files covering the same time range
>>> gwframe.combine_channels(['file1.gwf', 'file2.gwf'], 'output/')
>>> # Combine and keep only specific channels
>>> gwframe.combine_channels(
... ['file1.gwf', 'file2.gwf'], 'output/',
... keep_channels=['L1:STRAIN', 'L1:LSC']
... )
>>> # Combine and drop specific channels
>>> gwframe.combine_channels(
... ['dir1/', 'dir2/'], 'output/',
... drop_channels=['L1:UNWANTED']
... )
Notes
All sources must have matching frame structures (same times and durations). Raises detailed error messages if frames don't align.
Source code in gwframe/operations.py
195 196 197 198 199 200 201 202 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 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 | |
drop_channels ¶
drop_channels(input_files: str | PathLike[str] | Sequence[str | PathLike[str]], output_dir: str | PathLike[str] | None = None, channels_to_drop: Sequence[str] | None = None, *, in_place: bool = False) -> list[str]
Remove specified channels from frame files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_files
|
str, path-like, or sequence of str/path-like
|
Input GWF file(s) to process |
required |
output_dir
|
str, path-like, or None
|
Directory where output files will be written. Required if in_place=False. Mutually exclusive with in_place=True. |
None
|
channels_to_drop
|
sequence of str
|
List of channel names to remove |
None
|
in_place
|
bool
|
If True, modify files in place (default: False) |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
output_files |
list[str]
|
List of output file paths created |
Examples:
>>> # In place
>>> gwframe.drop_channels(
... 'input.gwf',
... channels_to_drop=['L1:UNWANTED_CHANNEL'],
... in_place=True
... )
Source code in gwframe/operations.py
impute_missing_data ¶
impute_missing_data(input_files: str | PathLike[str] | Sequence[str | PathLike[str]], output_dir: str | PathLike[str] | None = None, replace_value: float = nan, fill_value: float = 0.0, channels: Sequence[str] | None = None, *, in_place: bool = False) -> list[str]
Replace specific values in frame file channels with a fill value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_files
|
str, path-like, or sequence of str/path-like
|
Input GWF file(s) to process |
required |
output_dir
|
str, path-like, or None
|
Directory where output files will be written. Required if in_place=False. Mutually exclusive with in_place=True. |
None
|
replace_value
|
float
|
Value to replace (default: NaN). Can be NaN or any numeric value. |
nan
|
fill_value
|
float
|
Value to use for replacement (default: 0.0). Will be cast to appropriate dtype. |
0.0
|
channels
|
sequence of str
|
If specified, only impute these channels. Otherwise imputes all channels. |
None
|
in_place
|
bool
|
If True, modify files in place (default: False) |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
output_files |
list[str]
|
List of output file paths created |
Examples:
>>> # Replace specific value in specific channels
>>> gwframe.impute_missing_data(
... 'input.gwf', 'output/',
... replace_value=-999.0,
... fill_value=0.0,
... channels=['L1:STRAIN']
... )
Source code in gwframe/operations.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
recompress_frames ¶
recompress_frames(input_files: str | PathLike[str] | Sequence[str | PathLike[str]], output_dir: str | PathLike[str] | None = None, compression: int = ZERO_SUPPRESS_OTHERWISE_GZIP, compression_level: int = 6, *, in_place: bool = False) -> list[str]
Rewrite frame files with different compression settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_files
|
str, path-like, or sequence of str/path-like
|
Input GWF file(s) to process |
required |
output_dir
|
str or path - like
|
Directory where output files will be written. Required if in_place=False. Ignored if in_place=True. |
None
|
compression
|
int
|
Compression scheme (e.g., Compression.RAW, Compression.GZIP) |
ZERO_SUPPRESS_OTHERWISE_GZIP
|
compression_level
|
int
|
Compression level 0-9 (default: 6) |
6
|
in_place
|
bool
|
If True, modify files in place (default: False) |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
output_files |
list[str]
|
List of output file paths created |
Examples:
>>> # Remove compression
>>> gwframe.recompress_frames('input.gwf', 'output/',
... compression=gwframe.Compression.RAW)
>>> # Maximum compression, in place
>>> gwframe.recompress_frames('input.gwf',
... compression=gwframe.Compression.GZIP,
... compression_level=9,
... in_place=True)
Source code in gwframe/operations.py
rename_channels ¶
rename_channels(input_files: str | PathLike[str] | Sequence[str | PathLike[str]], output_dir: str | PathLike[str] | None = None, channel_map: dict[str, str] | None = None, *, in_place: bool = False) -> list[str]
Rename channels in frame files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_files
|
str, path-like, or sequence of str/path-like
|
Input GWF file(s) to process |
required |
output_dir
|
str, path-like, or None
|
Directory where output files will be written. Required if in_place=False, ignored if in_place=True. |
None
|
channel_map
|
dict
|
Mapping of old channel names to new channel names |
None
|
in_place
|
bool
|
If True, modify files in place (default: False) |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
output_files |
list[str]
|
List of output file paths created |
Examples:
>>> # Write to output directory
>>> gwframe.rename_channels(
... 'input.gwf',
... 'output/',
... {'L1:OLD_NAME': 'L1:NEW_NAME'}
... )
>>> # Modify in place
>>> gwframe.rename_channels(
... 'input.gwf',
... channel_map={'L1:OLD_NAME': 'L1:NEW_NAME'},
... in_place=True
... )
Source code in gwframe/operations.py
replace_channels ¶
replace_channels(base_files: str | PathLike[str] | Sequence[str | PathLike[str]], update_files: str | PathLike[str] | Sequence[str | PathLike[str]], output_dir: str | PathLike[str], channels_to_replace: Sequence[str] | None = None) -> list[str]
Replace data in channels with updated versions from another frame file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_files
|
str, path-like, or sequence of str/path-like
|
Base GWF file(s) to process |
required |
update_files
|
str, path-like, or sequence of str/path-like
|
GWF file(s) containing updated channel data |
required |
output_dir
|
str or path - like
|
Directory where output files will be written |
required |
channels_to_replace
|
sequence of str
|
List of channel names to replace. If None, replaces all channels found in update_files. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
output_files |
list[str]
|
List of output file paths created |
Examples:
>>> gwframe.replace_channels(
... 'base.gwf',
... 'updated.gwf',
... 'output/',
... ['L1:STRAIN']
... )
Source code in gwframe/operations.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 | |
resize_frames ¶
resize_frames(input_files: str | PathLike[str] | Sequence[str | PathLike[str]], output_dir: str | PathLike[str] | None = None, target_duration: float | None = None, *, in_place: bool = False) -> list[str]
Resize frames to a different duration (e.g., 64s frames to 4s frames).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_files
|
str, path-like, or sequence of str/path-like
|
Input GWF file(s) to process |
required |
output_dir
|
str or path - like
|
Directory where output files will be written. Required if in_place=False. Ignored if in_place=True. |
None
|
target_duration
|
float
|
Target frame duration in seconds |
None
|
in_place
|
bool
|
If True, modify files in place (default: False) |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
output_files |
list[str]
|
List of output file paths created |
Examples:
>>> # Split 64-second frames into 4-second frames
>>> gwframe.resize_frames('input.gwf', 'output/', target_duration=4.0)
>>> # Split frames in place
>>> gwframe.resize_frames('input.gwf', target_duration=4.0, in_place=True)
Notes
When splitting frames (target_duration < source_duration), data is divided evenly. When merging frames (target_duration > source_duration), consecutive frames are combined.
Source code in gwframe/operations.py
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 576 577 | |