read
Read functions for GWF files.
FrameReader ¶
Holds an open GWF file for efficient repeated reads.
The underlying file stream and TOC are created once on construction and reused for every read. Use as a context manager or let the garbage collector close it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str or path - like
|
Path to the GWF file |
required |
validate_checksum
|
bool
|
Validate frame file checksums before reading (default: False). When enabled, performs file-level checksum validation which requires reading the entire frame file. Disabled by default for performance. |
False
|
Examples:
>>> with gwframe.FrameReader("data.gwf") as f:
... print(f.num_frames)
... ts = f.read("L1:STRAIN", frame_index=0)
Source code in gwframe/read.py
channel_details ¶
channel_details(frame_index: int = 0) -> list[ChannelInfo]
Get detailed metadata for all channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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) |
Source code in gwframe/read.py
close ¶
read ¶
read(channels: str, frame_index: int = 0, *, start: float | None = None, end: float | None = None, allow_invalid: bool = False, aux_mask: bool = False) -> TimeSeries
read(channels: str | list[str] | None = None, frame_index: int = 0, *, start: float | None = None, end: float | None = None, allow_invalid: bool = False, aux_mask: bool = False) -> TimeSeries | dict[str, TimeSeries]
Read channel data from the open file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
str, None, or list[str]
|
Channel(s) to read: - str: Read single channel - None: Read all channels from the frame (default) - list[str]: Read specific list of channels |
None
|
frame_index
|
int
|
Index of the frame to read from (default: 0). Mutually exclusive with start/end parameters. |
0
|
start
|
float
|
GPS start time for time-based slicing. Must be used with end. |
None
|
end
|
float
|
GPS end time for time-based slicing. Must be used with start. |
None
|
allow_invalid
|
bool
|
If True, return masked arrays for invalid ADC data instead of raising InvalidDataError (default: False). |
False
|
aux_mask
|
bool
|
If True, decode auxiliary mask vectors on ADC channels (a site
convention, e.g. CDS |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
TimeSeries or dict[str, TimeSeries]
|
|
Source code in gwframe/read.py
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 | |
read ¶
read(source: str | PathLike[str] | BinaryIO, channels: str, frame_index: int = 0, *, validate_checksum: bool = False, start: float | None = None, end: float | None = None, allow_invalid: bool = False, aux_mask: bool = False) -> TimeSeries
read(source: str | PathLike[str] | BinaryIO, channels: str | list[str] | None = None, frame_index: int = 0, *, validate_checksum: bool = False, start: float | None = None, end: float | None = None, allow_invalid: bool = False, aux_mask: bool = False) -> TimeSeries | dict[str, TimeSeries]
Read channel data from a GWF file or file-like object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str, path-like, or file-like object
|
Either a path to the GWF file (str or PathLike), or a file-like object with a .read() method (e.g., open('file.gwf', 'rb'), BytesIO) |
required |
channels
|
str, None, or list[str]
|
Channel(s) to read: - str: Read single channel (e.g., 'L1:GWOSC-16KHZ_R1_STRAIN') - None: Read all channels from the frame (default) - list[str]: Read specific list of channels |
None
|
frame_index
|
int
|
Index of the frame to read from (default: 0). Mutually exclusive with start/end parameters. |
0
|
validate_checksum
|
bool
|
Validate frame file checksums before reading (default: False). When enabled, performs file-level checksum validation which requires reading the entire frame file. Disabled by default for performance. |
False
|
start
|
float
|
GPS start time for time-based slicing. Must be used with end parameter. When specified, reads and stitches all frames overlapping [start, end). Mutually exclusive with frame_index parameter. |
None
|
end
|
float
|
GPS end time for time-based slicing. Must be used with start parameter. When specified, reads and stitches all frames overlapping [start, end). Mutually exclusive with frame_index parameter. |
None
|
allow_invalid
|
bool
|
If True, return masked arrays for ADC channels whose channel-level dataValid flag is nonzero instead of raising InvalidDataError (default: False). |
False
|
aux_mask
|
bool
|
If True, decode auxiliary mask vectors on ADC channels (a site
convention, e.g. CDS |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
TimeSeries or dict[str, TimeSeries]
|
|
Examples:
>>> # Read single channel from file path
>>> data = gwframe.read('data.gwf', 'L1:GWOSC-16KHZ_R1_STRAIN')
>>> print(f"Read {len(data.array)} samples at {data.sample_rate} Hz")
>>> print(f"Time range: {data.start} to {data.start + data.duration}")
>>> # Read all channels
>>> all_data = gwframe.read('data.gwf', channels=None)
>>> print(f"Found {len(all_data)} channels: {list(all_data.keys())}")
>>> # Read specific list of channels
>>> channels = ['L1:STRAIN', 'L1:LSC-DARM_IN1']
>>> data_dict = gwframe.read('data.gwf', channels)
>>> for ch, ts in data_dict.items():
... print(f"{ch}: {len(ts.array)} samples")
>>> # Read from file object
>>> with open('data.gwf', 'rb') as f:
... data = gwframe.read(f, 'L1:GWOSC-16KHZ_R1_STRAIN')
>>> # Read from BytesIO
>>> from io import BytesIO
>>> data = gwframe.read(BytesIO(gwf_bytes), 'L1:STRAIN')
>>> # Time-based slicing (reads and stitches multiple frames)
>>> data = gwframe.read('multi_frame.gwf', 'L1:STRAIN',
... start=1234567890.0, end=1234567900.0)
>>> print(
... f"Read {data.duration} seconds from {data.start} to "
... f"{data.start + data.duration}"
... )
Notes
When using time-based slicing (start/end parameters), this function automatically finds, reads, and stitches together all frames that overlap with the requested time range. The returned data is sliced to the exact [start, end) interval.
When reading from file-like objects, the entire file is loaded into memory.
Source code in gwframe/read.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
read_bytes ¶
read_bytes(data: bytes, channels: str, frame_index: int = 0, *, validate_checksum: bool = False, start: float | None = None, end: float | None = None, allow_invalid: bool = False, aux_mask: bool = False) -> TimeSeries
read_bytes(data: bytes, channels: str | list[str] | None = None, frame_index: int = 0, *, validate_checksum: bool = False, start: float | None = None, end: float | None = None, allow_invalid: bool = False, aux_mask: bool = False) -> TimeSeries | dict[str, TimeSeries]
Read channel data from GWF data in memory (bytes).
This allows reading GWF data without writing to disk first, which is useful when working with data from network streams, compressed archives, or in-memory buffers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Raw GWF file data as bytes |
required |
channels
|
str, None, or list[str]
|
Channel(s) to read: - str: Read single channel (e.g., 'L1:GWOSC-16KHZ_R1_STRAIN') - None: Read all channels from the frame (default) - list[str]: Read specific list of channels |
None
|
frame_index
|
int
|
Index of the frame to read from (default: 0) |
0
|
validate_checksum
|
bool
|
Validate frame file checksums before reading (default: False). When enabled, performs file-level checksum validation which requires reading the entire frame file. Disabled by default for performance. |
False
|
allow_invalid
|
bool
|
If True, return masked arrays for ADC channels whose channel-level dataValid flag is nonzero instead of raising InvalidDataError (default: False). |
False
|
aux_mask
|
bool
|
If True, decode auxiliary mask vectors on ADC channels (a site
convention, e.g. CDS |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
TimeSeries or dict[str, TimeSeries]
|
|
Examples:
>>> with open('data.gwf', 'rb') as f:
... gwf_bytes = f.read()
>>> data = gwframe.read_bytes(gwf_bytes, 'L1:GWOSC-16KHZ_R1_STRAIN')
>>> print(f"Read {len(data.array)} samples at {data.sample_rate} Hz")
>>> # Read all channels
>>> all_data = gwframe.read_bytes(gwf_bytes, channels=None)
>>> print(f"Found {len(all_data)} channels")
>>> import io
>>> from io import BytesIO
>>> data = gwframe.read_bytes(BytesIO(gwf_bytes).read(), 'L1:STRAIN')
Notes
This function uses frameCPP's MemoryBuffer internally to read from memory without writing to disk.
Source code in gwframe/read.py
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 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 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 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 | |
read_frames ¶
read_frames(filename: str | PathLike[str], *, allow_invalid: bool = False, aux_mask: bool = False) -> Generator[Frame, None, None]
Read frames from a GWF file, preserving complete metadata.
Yields Frame objects that can be written directly to disk with identical metadata (frame name, run number, frame number, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or path - like
|
Path to the GWF file |
required |
allow_invalid
|
bool
|
If True, mask ADC channels whose channel-level dataValid flag is nonzero instead of raising InvalidDataError (default: False). |
False
|
aux_mask
|
bool
|
If True, decode auxiliary mask vectors on ADC channels into
per-sample masks (default: False). See :func: |
False
|
Yields:
| Name | Type | Description |
|---|---|---|
frame |
Frame
|
Frame object containing all channel data with correct sample rates, units, types, and original frame metadata |
Examples:
>>> # Iterate over frames
>>> for frame in gwframe.read_frames('data.gwf'):
... print(f"Frame {frame.name} at GPS {frame.start}")
>>> # Process and write frames
>>> with gwframe.FrameWriter('output.gwf') as writer:
... for frame in gwframe.read_frames('input.gwf'):
... writer.write_frame(frame)
>>> # Collect all frames into a list
>>> frames = list(gwframe.read_frames('data.gwf'))
>>> print(f"Read {len(frames)} frames")
See Also
read : Read channel data from frames Frame : Frame object for creating and manipulating frames FrameWriter : Context manager for writing frames to files
Source code in gwframe/read.py
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 | |