IO Module / 入出力モジュール¶
The wandas.io module provides readers for external data and persistence for
WDF artifacts. Input, output, units, and compatibility contracts live in the
generated docstrings.
wandas.ioは外部データのreaderとWDF artifactの永続化を提供します。入力、出力、単位、
互換性の契約は生成されたdocstringを正本とします。
wandas.io.readers
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
DownloadedTemporaryFile
dataclass
¶
Temporary file created for streamed URL downloads.
Source code in wandas/io/readers.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
Attributes¶
path
instance-attribute
¶
temp_dir
instance-attribute
¶
Functions¶
__init__(path, temp_dir)
¶
__post_init__()
¶
Source code in wandas/io/readers.py
28 29 30 31 32 33 | |
__enter__()
¶
Source code in wandas/io/readers.py
35 36 | |
__exit__(exc_type, exc, tb)
¶
Source code in wandas/io/readers.py
38 39 | |
cleanup()
¶
Source code in wandas/io/readers.py
41 42 43 | |
CSVFileInfoParams
¶
Bases: TypedDict
Type definition for CSV file reader parameters in get_file_info.
Attributes:
| Name | Type | Description |
|---|---|---|
delimiter |
str
|
Delimiter character. Defaults to |
header |
Optional[int]
|
Row number to use as header. Defaults to 0
(first row); use |
time_column |
Union[int, str]
|
Index or name of the time column. Defaults to 0. |
Source code in wandas/io/readers.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
CSVGetDataParams
¶
Bases: TypedDict
Type definition for CSV file reader parameters in get_data.
Attributes:
| Name | Type | Description |
|---|---|---|
delimiter |
str
|
Delimiter character. Defaults to |
header |
Optional[int]
|
Row number to use as header. Defaults to 0
(first row); use |
time_column |
Union[int, str]
|
Index or name of the time column. Defaults to 0. |
Source code in wandas/io/readers.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
FileReader
¶
Bases: ABC
Base class for external data readers.
Implementations return real channel-first arrays. Audio readers must apply full-scale decoding before returning values.
Source code in wandas/io/readers.py
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 142 143 144 145 146 147 148 149 150 151 | |
Attributes¶
supported_extensions = []
class-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: - samplerate: Sampling rate in Hz - channels: Number of channels - frames: Total number of frames - format: File format - duration: Duration in seconds |
Source code in wandas/io/readers.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
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
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
can_read(path)
classmethod
¶
Check if this reader can handle the file based on extension.
Source code in wandas/io/readers.py
145 146 147 148 149 150 151 | |
SoundFileReader
¶
Bases: FileReader
Audio file reader using SoundFile library.
Source code in wandas/io/readers.py
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 | |
Attributes¶
supported_extensions = ['.wav', '.flac', '.ogg', '.aiff', '.aif', '.snd']
class-attribute
¶
Functions¶
get_file_info(path, **kwargs)
classmethod
¶
Get basic information about the audio file.
Source code in wandas/io/readers.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
get_data(path, channels, start_idx, frames, **kwargs)
classmethod
¶
Read full-scale float64 audio data from the file.
Source code in wandas/io/readers.py
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 | |
CSVFileReader
¶
Bases: FileReader
CSV file reader for time series data.
Metadata inspection eagerly parses the complete table to determine its exact
shape and sampling rate. Sample values in the public Frame remain Dask-backed,
and get_data() parses the table again when that graph is computed.
Source code in wandas/io/readers.py
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 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
Attributes¶
supported_extensions = ['.csv']
class-attribute
¶
Functions¶
get_file_info(path, **kwargs)
classmethod
¶
Get basic information about the CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | bytes | bytearray | memoryview | BinaryIO
|
Union[str, Path]. Path to the CSV file. |
required |
**kwargs
|
Any
|
Any. Additional parameters for CSV reading. Supported parameters:
|
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
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
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 | |
get_data(path, channels, start_idx, frames, **kwargs)
classmethod
¶
Read data from the CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | bytes | bytearray | memoryview | BinaryIO
|
Union[str, Path]. Path to the CSV file. |
required |
channels
|
list[int]
|
list[int]. List of channel indices to read. |
required |
start_idx
|
int
|
int. Starting frame index. |
required |
frames
|
int
|
int. Number of frames to read. |
required |
**kwargs
|
Any
|
Any. Additional parameters for CSV reading. Supported parameters:
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ArrayLike |
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
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 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
Functions¶
download_url_to_temporary_file(url, *, timeout, suffix=None, resource_name='file', max_bytes=None, chunk_size=None)
¶
Source code in wandas/io/readers.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
supported_formats()
¶
Return file extensions supported by the registered readers.
Source code in wandas/io/readers.py
529 530 531 532 533 534 | |
get_file_reader(path, *, file_type=None)
¶
Return the registered reader selected by an explicit type or path suffix.
file_type is case-insensitive and may include or omit the leading dot.
This lower-level registry boundary does not guess a format from file
contents. The public :func:wandas.read entry point owns the additional
name-based inference and anonymous-WAV compatibility default.
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither a type nor suffix is available, or if the normalized extension has no registered reader. |
Source code in wandas/io/readers.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
register_file_reader(reader_class)
¶
Register a new file reader.
Source code in wandas/io/readers.py
594 595 596 597 598 | |
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:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
str. Path to the WAV file. |
required |
target
|
ChannelFrame
|
ChannelFrame. ChannelFrame object containing the data to write. |
required |
format
|
str | None
|
str, optional. File format. If None, determined from file extension. |
None
|
Raises:
| Type | Description |
|---|---|
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 | |
wandas.io.wdf_io
¶
Strict xarray-backed persistence for typed WDF 0.4 artifacts.
Attributes¶
WDF_FORMAT_VERSION = '0.4'
module-attribute
¶
__all__ = ['WDF_FORMAT_VERSION', 'load', 'save']
module-attribute
¶
Classes¶
Functions¶
save(frame, path, *, compress='gzip', overwrite=False)
¶
Save an exact built-in Frame as WDF 0.4.
The artifact retains the Frame label, user metadata, channel labels and
metadata (units, references, calibration, and channel extras), source-time
offsets, analysis coordinates, and the derived operation_history view.
Metadata fields use strict JSON encoding and therefore follow JSON value
semantics (for example, a tuple is loaded as a list).
It stores the concrete Frame result; previous references and replayable
Recipe intent are not persisted.
Dask data is handed directly to xarray and is written synchronously; Wandas does
not first materialize the complete tensor with frame._data.compute().
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 | |
load(path)
¶
Load a local WDF 0.4 artifact as its exact built-in Frame type.
The returned Frame restores the saved label, user metadata, channel labels
and metadata (units, references, calibration, and channel extras),
source-time offsets, analysis coordinates, and derived
operation_history view. Metadata follows strict JSON value semantics;
for example, a tuple saved in metadata is loaded as a list. WDF does not
restore a previous reference or replayable Recipe intent.
The returned Frame owns access to its source internally. Keep the source path
unchanged while that Frame or Frames derived from it are in use. Obtain NumPy
values through frame.data without managing the storage backend directly.
Source code in wandas/io/wdf_io.py
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 | |