inspect
File inspection and metadata functions.
ChannelInfo
dataclass
¶
ChannelInfo(name: str, type: str, dtype: dtype, sample_rate: float, n_samples: int, unit: str, data_valid: int = 0)
Metadata about a single channel in a GWF file.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Channel name (e.g., 'H1:LOSC-STRAIN') |
type |
str
|
Channel type: 'adc', 'proc', or 'sim' |
dtype |
dtype
|
NumPy dtype of the channel samples (e.g., |
sample_rate |
float
|
Sampling rate in Hz |
n_samples |
int
|
Number of samples in the channel |
unit |
str
|
Physical unit of the data (e.g., 'strain') |
data_valid |
int
|
Raw dataValid flag for ADC channels in the inspected frame. Nonzero means the channel data is invalid. Always 0 for proc and sim channels, which carry no dataValid flag. |
get_channel_details ¶
Get detailed metadata for all channels in a GWF file.
Reads channel headers (without decompressing data) to extract sample rate, data type, sample count, and units for each channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or path - like
|
Path to the GWF file |
required |
frame_index
|
int
|
Frame index to read metadata from (default: 0) |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
details |
list[ChannelInfo]
|
List of channel metadata, ordered by type (adc, proc, sim) |
Examples:
>>> details = gwframe.get_channel_details('data.gwf')
>>> for ch in details:
... print(f"{ch.name}: {ch.dtype_name} @ {ch.sample_rate} Hz")
Source code in gwframe/inspect.py
get_channels ¶
Get a list of all channels in a GWF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or path - like
|
Path to the GWF file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
channels |
list[str]
|
List of all channel names |
Examples:
>>> channels = gwframe.get_channels('data.gwf')
>>> print(f"Found {len(channels)} channels")
>>> for channel in channels:
... print(channel)
Source code in gwframe/inspect.py
get_channels_by_type ¶
Get channel names grouped by type (adc, proc, sim).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or path - like
|
Path to the GWF file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
channels |
dict[str, list[str]]
|
Dictionary with keys 'adc', 'proc', 'sim' mapping to channel name lists |
Examples:
>>> by_type = gwframe.get_channels_by_type('data.gwf')
>>> print(f"ADC channels: {len(by_type['adc'])}")
>>> print(f"Proc channels: {len(by_type['proc'])}")
Source code in gwframe/inspect.py
get_info ¶
get_info(filename: str | PathLike[str]) -> FrameFileInfo
Get metadata about a GWF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or path - like
|
Path to the GWF file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
info |
FrameFileInfo
|
Structured metadata containing: - num_frames: number of frames in file - channels: list of all channel names - frames: list of FrameInfo objects with complete frame metadata |
Examples:
>>> info = gwframe.get_info('data.gwf')
>>> print(f"File contains {info.num_frames} frames")
>>> print(f"Frame 0: {info.frames[0].name} at GPS {info.frames[0].start}")
>>> print(f"Channels: {', '.join(info.channels)}")
Source code in gwframe/inspect.py
get_invalid_channels ¶
Find ADC channels flagged invalid (dataValid != 0) in any frame.
Scans the channel-level dataValid flag of every ADC channel in every frame. This is a header-only read: no sample data is decompressed, so the scan is cheap even for large files. Proc and sim channels carry no dataValid flag and are never included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or path - like
|
Path to the GWF file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
invalid |
dict[str, dict[int, int]]
|
Mapping of channel name to |
Examples:
>>> invalid = gwframe.inspect.get_invalid_channels('data.gwf')
>>> for channel, frames in invalid.items():
... print(f"{channel}: invalid in frames {sorted(frames)}")