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, *, progress: ProgressCallback | 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
|
progress
|
callable
|
Called after each combined frame has been written with
|
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
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 278 279 280 281 282 283 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 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
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, progress: ProgressCallback | None = None) -> 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
|
progress
|
callable
|
Called after each input frame has been processed with
|
None
|
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, progress: ProgressCallback | None = None) -> 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
|
progress
|
callable
|
Called after each input frame has been processed with
|
None
|
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
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, progress: ProgressCallback | None = None) -> 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
|
progress
|
callable
|
Called after each input frame has been processed with
|
None
|
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, progress: ProgressCallback | None = None) -> 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
|
progress
|
callable
|
Called after each input frame has been processed with
|
None
|
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, *, progress: ProgressCallback | 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
|
progress
|
callable
|
Called after each base frame has been processed with
|
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
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 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 | |
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, progress: ProgressCallback | None = None) -> 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
|
progress
|
callable
|
Called after each input frame has been processed with
|
None
|
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), the source
duration must be a whole multiple of the target and data is divided
evenly. When merging frames (target_duration > source_duration),
consecutive contiguous frames are combined until they reach the target;
the last frame of a file may be shorter. See
:class:gwframe.pipeline.ResizeStage.
Source code in gwframe/operations.py
select_channels ¶
select_channels(input_files: str | PathLike[str] | Sequence[str | PathLike[str]], output_dir: str | PathLike[str] | None = None, channels_to_select: Sequence[str] | None = None, *, in_place: bool = False, progress: ProgressCallback | None = None) -> list[str]
Keep only specified channels in frame files, removing all others.
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_select
|
sequence of str
|
List of channel names to keep |
None
|
in_place
|
bool
|
If True, modify files in place (default: False) |
False
|
progress
|
callable
|
Called after each input frame has been processed with
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
output_files |
list[str]
|
List of output file paths created |
Examples:
>>> # In place
>>> gwframe.select_channels(
... 'input.gwf',
... channels_to_select=['L1:STRAIN'],
... in_place=True
... )