IO Module / 入出力モジュール¶
The wandas.io module provides reading and writing capabilities for various file formats.
wandas.io モジュールは、様々なファイル形式の読み書き機能を提供します。
File Readers / ファイルリーダー¶
Provides functionality to read data from various file formats. 様々なファイル形式からデータを読み込む機能を提供します。
wandas.io.readers
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
CSVFileInfoParams
¶
Bases: TypedDict
Type definition for CSV file reader parameters in get_file_info.
Parameters¶
delimiter : str Delimiter character. Default is ",". header : Optional[int] Row number to use as header. Default is 0 (first row). Set to None if no header. time_column : Union[int, str] Index or name of the time column. Default is 0.
Source code in wandas/io/readers.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
CSVGetDataParams
¶
Bases: TypedDict
Type definition for CSV file reader parameters in get_data.
Parameters¶
delimiter : str Delimiter character. Default is ",". header : Optional[int] Row number to use as header. Default is 0. time_column : Union[int, str] Index or name of the time column. Default is 0.
Source code in wandas/io/readers.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
FileReader
¶
Bases: ABC
Base class for audio file readers.
Source code in wandas/io/readers.py
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 | |
Attributes¶
supported_extensions = []
class-attribute
instance-attribute
¶
Functions¶
get_file_info(path, **kwargs)
abstractmethod
classmethod
¶
Get basic information about the audio file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | bytes | bytearray | memoryview | BinaryIO
|
Path to the file. |
required |
**kwargs
|
Any
|
Additional parameters specific to the file reader. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing file information including: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Source code in wandas/io/readers.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
get_data(path, channels, start_idx, frames, **kwargs)
abstractmethod
classmethod
¶
Read audio data from the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | bytes | bytearray | memoryview | BinaryIO
|
Path to the file. |
required |
channels
|
list[int]
|
List of channel indices to read. |
required |
start_idx
|
int
|
Starting frame index. |
required |
frames
|
int
|
Number of frames to read. |
required |
**kwargs
|
Any
|
Additional parameters specific to the file reader. |
{}
|
Returns:
| Type | Description |
|---|---|
ArrayLike
|
Array of shape (channels, frames) containing the audio data. |
Source code in wandas/io/readers.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
can_read(path)
classmethod
¶
Check if this reader can handle the file based on extension.
Source code in wandas/io/readers.py
106 107 108 109 110 | |
SoundFileReader
¶
Bases: FileReader
Audio file reader using SoundFile library.
Source code in wandas/io/readers.py
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 142 143 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 | |
Attributes¶
supported_extensions = ['.wav', '.flac', '.ogg', '.aiff', '.aif', '.snd']
class-attribute
instance-attribute
¶
Functions¶
get_file_info(path, **kwargs)
classmethod
¶
Get basic information about the audio file.
Source code in wandas/io/readers.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
get_data(path, channels, start_idx, frames, normalize=False, **kwargs)
classmethod
¶
Read audio data from the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalize
|
bool
|
When False (default) and the source is a WAV file path, return raw integer PCM samples cast to float32 via scipy.io.wavfile.read. For non-WAV formats or in-memory sources, always uses soundfile (returning float32 normalized to [-1.0, 1.0]). When True, return float32 data normalized to [-1.0, 1.0] via soundfile. |
False
|
Source code in wandas/io/readers.py
136 137 138 139 140 141 142 143 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 | |
CSVFileReader
¶
Bases: FileReader
CSV file reader for time series data.
Source code in wandas/io/readers.py
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 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
Attributes¶
supported_extensions = ['.csv']
class-attribute
instance-attribute
¶
Functions¶
get_file_info(path, **kwargs)
classmethod
¶
Get basic information about the CSV file.
Parameters¶
path : Union[str, Path] Path to the CSV file. **kwargs : Any Additional parameters for CSV reading. Supported parameters:
- delimiter : str, default=","
Delimiter character.
- header : Optional[int], default=0
Row number to use as header. Set to None if no header.
- time_column : Union[int, str], default=0
Index or name of the time column.
Returns¶
dict[str, Any] Dictionary containing file information including: - samplerate: Estimated sampling rate in Hz - channels: Number of data channels (excluding time column) - frames: Total number of frames - format: "CSV" - duration: Duration in seconds (or None if cannot be calculated) - ch_labels: List of channel labels
Notes¶
This method accepts CSV-specific parameters through kwargs. See CSVFileInfoParams for supported parameter types.
Source code in wandas/io/readers.py
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 | |
get_data(path, channels, start_idx, frames, **kwargs)
classmethod
¶
Read data from the CSV file.
Parameters¶
path : Union[str, Path] Path to the CSV file. channels : list[int] List of channel indices to read. start_idx : int Starting frame index. frames : int Number of frames to read. **kwargs : Any Additional parameters for CSV reading. Supported parameters:
- delimiter : str, default=","
Delimiter character.
- header : Optional[int], default=0
Row number to use as header.
- time_column : Union[int, str], default=0
Index or name of the time column.
Returns¶
ArrayLike Array of shape (channels, frames) containing the data.
Notes¶
This method accepts CSV-specific parameters through kwargs. See CSVGetDataParams for supported parameter types.
Source code in wandas/io/readers.py
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 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
Functions¶
get_file_reader(path, *, file_type=None)
¶
Get an appropriate file reader for the given path or file type.
Source code in wandas/io/readers.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
register_file_reader(reader_class)
¶
Register a new file reader.
Source code in wandas/io/readers.py
417 418 419 420 421 | |
WAV File IO / WAVファイル入出力¶
Provides functions for reading and writing WAV files. WAVファイルの読み書き機能を提供します。
wandas.io.wav_io
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions¶
write_wav(filename, target, format=None)
¶
Write a ChannelFrame object to a WAV file.
Parameters¶
filename : str Path to the WAV file. target : ChannelFrame ChannelFrame object containing the data to write. format : str, optional File format. If None, determined from file extension.
Raises¶
ValueError If target is not a ChannelFrame object.
Source code in wandas/io/wav_io.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
WDF File IO / WDFファイル入出力¶
Provides functions for reading and writing WDF (Wandas Data File) format, which enables complete preservation including metadata. WDF(Wandas Data File)形式の読み書き機能を提供します。このフォーマットはメタデータを含む完全な保存が可能です。
wandas.io.wdf_io
¶
WDF (Wandas Data File) I/O module for saving and loading ChannelFrame objects.
This module provides functionality to save and load ChannelFrame objects in the WDF (Wandas Data File) format, which is based on HDF5. The format preserves all metadata including sampling rate, channel labels, units, and frame metadata.
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
WDF_FORMAT_VERSION = '0.1'
module-attribute
¶
Classes¶
Functions¶
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 | |
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 | |