WDF File I/O / WDFファイル入出力¶
The wandas.io.wdf_io module provides functionality for saving and loading ChannelFrame objects in the WDF (Wandas Data File) format.
wandas.io.wdf_io モジュールは、ChannelFrame オブジェクトを WDF (Wandas Data File) 形式で保存・読み込みするための機能を提供します。
The WDF format is based on HDF5 and preserves not only the data but also all metadata such as sampling rate, units, and channel labels. WDFフォーマットは HDF5 をベースとし、データだけでなくサンプリングレート、単位、チャンネルラベルなどのメタデータも完全に保存します。
WDF Format Overview / WDFフォーマット概要¶
The WDF format has the following features: WDFフォーマットは以下の特徴を持ちます:
- HDF5-based hierarchical data structure. HDF5ベースの階層的なデータ構造。
- Complete preservation of channel data and metadata. チャンネルデータとメタデータの完全な保持。
- Size optimization through data compression and chunking. データ圧縮とチャンク化によるサイズ最適化。
- Version management for future extensions. 将来の拡張に対応するバージョン管理。
File structure / ファイル構造:
/meta : Frame-level metadata (JSON format) / Frame 全体のメタデータ (JSON形式)
/channels/{i} : Individual channel data and metadata / 個々のチャンネルデータとメタデータ
├─ data : Waveform data (numpy array) / 波形データ (numpy array)
└─ attrs : Channel attributes (labels, units, etc.) / チャンネル属性 (ラベル、単位など)
Saving WDF Files / WDFファイル保存¶
wandas.io.wdf_io.save(frame, path, *, format='hdf5', compress='gzip', overwrite=False, dtype=None)
¶
Save a frame to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
BaseFrame[Any]
|
The frame to save. |
required |
path
|
str | Path
|
Path to save the file. '.wdf' extension will be added if not present. |
required |
format
|
str
|
Format to use (currently only 'hdf5' is supported) |
'hdf5'
|
compress
|
str | None
|
Compression method ('gzip' by default, None for no compression) |
'gzip'
|
overwrite
|
bool
|
Whether to overwrite existing file |
False
|
dtype
|
str | dtype[Any] | None
|
Optional data type conversion before saving (e.g. 'float32') |
None
|
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the file exists and overwrite=False. |
NotImplementedError
|
For unsupported formats. |
Source code in wandas/io/wdf_io.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
Loading WDF Files / WDFファイル読み込み¶
wandas.io.wdf_io.load(path, *, format='hdf5', timeout=10.0)
¶
Load a ChannelFrame object from a WDF (Wandas Data File) file or URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the WDF file to load, or an HTTP/HTTPS URL pointing to a remote WDF file. When a URL is given the file is downloaded in full before opening. |
required |
format
|
str
|
Format of the file. Currently only "hdf5" is supported. |
'hdf5'
|
timeout
|
float
|
Timeout in seconds for HTTP/HTTPS URL downloads. Default is 10.0 seconds. Has no effect for local file paths. |
10.0
|
Returns:
| Type | Description |
|---|---|
ChannelFrame
|
A new ChannelFrame object with data and metadata loaded from the file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file doesn't exist. |
NotImplementedError
|
If format is not "hdf5". |
ValueError
|
If the file format is invalid or incompatible. |
Example
cf = ChannelFrame.load("audio_data.wdf") cf = ChannelFrame.load("https://example.com/audio_data.wdf")
Source code in wandas/io/wdf_io.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 | |
Usage Examples / 利用例¶
# Save a ChannelFrame in WDF format
# ChannelFrame を WDF形式で保存
cf = wd.read_wav("audio.wav")
cf.save("audio_data.wdf")
# Specifying options when saving
# 保存時のオプション指定
cf.save(
"high_quality.wdf",
compress="gzip", # Compression method / 圧縮方式
dtype="float64", # Data type / データ型
overwrite=True # Allow overwriting / 上書き許可
)
# Load a ChannelFrame from a WDF file
# WDFファイルから ChannelFrame を読み込み
cf2 = wd.ChannelFrame.load("audio_data.wdf")