API Reference¶
API reference for the main components and functions of the Wandas library.
Core Module¶
The core module provides the basic functionality of Wandas.
wandas.core
¶
Attributes¶
__all__ = ['BaseFrame']
module-attribute
¶
Classes¶
BaseFrame
¶
Bases: ABC, Generic[T]
Abstract base class for all signal frame types.
This class provides the common interface and functionality for all frame types used in signal processing. It implements basic operations like indexing, iteration, and data manipulation that are shared across all frame types.
Parameters¶
data : DaArray The signal data to process. Must be a dask array. sampling_rate : float The sampling rate of the signal in Hz. label : str, optional A label for the frame. If not provided, defaults to "unnamed_frame". metadata : dict, optional Additional metadata for the frame. operation_history : list[dict], optional History of operations performed on this frame. channel_metadata : list[ChannelMetadata], optional Metadata for each channel in the frame. previous : BaseFrame, optional The frame that this frame was derived from.
Attributes¶
sampling_rate : float The sampling rate of the signal in Hz. label : str The label of the frame. metadata : dict Additional metadata for the frame. operation_history : list[dict] History of operations performed on this frame.
Source code in wandas/core/base_frame.py
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 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 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 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 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
Attributes¶
sampling_rate = sampling_rate
instance-attribute
¶
label = label or 'unnamed_frame'
instance-attribute
¶
metadata = metadata or {}
instance-attribute
¶
operation_history = operation_history or []
instance-attribute
¶
n_channels
property
¶
Returns the number of channels.
channels
property
¶
Property to access channel metadata.
previous
property
¶
Returns the previous frame.
shape
property
¶
data
property
¶
Returns the computed data. Calculation is executed the first time this is accessed.
labels
property
¶
Get a list of all channel labels.
Functions¶
__init__(data, sampling_rate, label=None, metadata=None, operation_history=None, channel_metadata=None, previous=None)
¶
Source code in wandas/core/base_frame.py
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 | |
get_channel(channel_idx)
¶
Get channel(s) by index.
Parameters¶
channel_idx : int or sequence of int Single channel index or sequence of channel indices. Supports negative indices (e.g., -1 for the last channel).
Returns¶
S New instance containing the selected channel(s).
Examples¶
frame.get_channel(0) # Single channel frame.get_channel([0, 2, 3]) # Multiple channels frame.get_channel((-1, -2)) # Last two channels frame.get_channel(np.array([1, 2])) # NumPy array of indices
Source code in wandas/core/base_frame.py
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 | |
__len__()
¶
Returns the number of channels.
Source code in wandas/core/base_frame.py
172 173 174 175 176 | |
__iter__()
¶
Source code in wandas/core/base_frame.py
178 179 180 | |
__getitem__(key)
¶
Get channel(s) by index, label, or advanced indexing.
This method supports multiple indexing patterns similar to NumPy and pandas:
- Single channel by index:
frame[0] - Single channel by label:
frame["ch0"] - Slice of channels:
frame[0:3] - Multiple channels by indices:
frame[[0, 2, 5]] - Multiple channels by labels:
frame[["ch0", "ch2"]] - NumPy integer array:
frame[np.array([0, 2])] - Boolean mask:
frame[mask]where mask is a boolean array - Multidimensional indexing:
frame[0, 100:200](channel + time)
Parameters¶
key : int, str, slice, list, tuple, or ndarray - int: Single channel index (supports negative indexing) - str: Single channel label - slice: Range of channels - list[int]: Multiple channel indices - list[str]: Multiple channel labels - tuple: Multidimensional indexing (channel_key, time_key, ...) - ndarray[int]: NumPy array of channel indices - ndarray[bool]: Boolean mask for channel selection
Returns¶
S New instance containing the selected channel(s).
Raises¶
ValueError If the key length is invalid for the shape or if boolean mask length doesn't match number of channels. IndexError If the channel index is out of range. TypeError If the key type is invalid or list contains mixed types. KeyError If a channel label is not found.
Examples¶
Single channel selection¶
frame[0] # First channel frame["acc_x"] # By label frame[-1] # Last channel
Multiple channel selection¶
frame[[0, 2, 5]] # Multiple indices frame[["acc_x", "acc_z"]] # Multiple labels frame[0:3] # Slice
NumPy array indexing¶
frame[np.array([0, 2, 4])] # Integer array mask = np.array([True, False, True]) frame[mask] # Boolean mask
Time slicing (multidimensional)¶
frame[0, 100:200] # Channel 0, samples 100-200 frame[[0, 1], ::2] # Channels 0-1, every 2nd sample
Source code in wandas/core/base_frame.py
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 342 | |
label2index(label)
¶
Get the index from a channel label.
Parameters¶
label : str Channel label.
Returns¶
int Corresponding index.
Raises¶
KeyError If the channel label is not found.
Source code in wandas/core/base_frame.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
compute()
¶
Compute and return the data. This method materializes lazily computed data into a concrete NumPy array.
Returns¶
NDArrayReal The computed data.
Raises¶
ValueError If the computed result is not a NumPy array.
Source code in wandas/core/base_frame.py
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 | |
plot(plot_type='default', ax=None, **kwargs)
abstractmethod
¶
Plot the data
Source code in wandas/core/base_frame.py
479 480 481 482 483 484 | |
persist()
¶
Persist the data in memory
Source code in wandas/core/base_frame.py
486 487 488 489 | |
__array__(dtype=None)
¶
Implicit conversion to NumPy array
Source code in wandas/core/base_frame.py
537 538 539 540 541 542 | |
visualize_graph(filename=None)
¶
Visualize the computation graph and save it to a file
Source code in wandas/core/base_frame.py
544 545 546 547 548 549 550 551 552 | |
__add__(other)
¶
Addition operator
Source code in wandas/core/base_frame.py
566 567 568 | |
__sub__(other)
¶
Subtraction operator
Source code in wandas/core/base_frame.py
570 571 572 | |
__mul__(other)
¶
Multiplication operator
Source code in wandas/core/base_frame.py
574 575 576 | |
__truediv__(other)
¶
Division operator
Source code in wandas/core/base_frame.py
578 579 580 | |
apply_operation(operation_name, **params)
¶
Apply a named operation.
Parameters¶
operation_name : str Name of the operation to apply. **params : Any Parameters to pass to the operation.
Returns¶
S A new instance with the operation applied.
Source code in wandas/core/base_frame.py
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
debug_info()
¶
Output detailed debug information
Source code in wandas/core/base_frame.py
606 607 608 609 610 611 612 613 614 | |
Modules¶
base_frame
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
T = TypeVar('T', NDArrayComplex, NDArrayReal)
module-attribute
¶
S = TypeVar('S', bound='BaseFrame[Any]')
module-attribute
¶
Classes¶
BaseFrame
¶
Bases: ABC, Generic[T]
Abstract base class for all signal frame types.
This class provides the common interface and functionality for all frame types used in signal processing. It implements basic operations like indexing, iteration, and data manipulation that are shared across all frame types.
Parameters¶
data : DaArray The signal data to process. Must be a dask array. sampling_rate : float The sampling rate of the signal in Hz. label : str, optional A label for the frame. If not provided, defaults to "unnamed_frame". metadata : dict, optional Additional metadata for the frame. operation_history : list[dict], optional History of operations performed on this frame. channel_metadata : list[ChannelMetadata], optional Metadata for each channel in the frame. previous : BaseFrame, optional The frame that this frame was derived from.
Attributes¶
sampling_rate : float The sampling rate of the signal in Hz. label : str The label of the frame. metadata : dict Additional metadata for the frame. operation_history : list[dict] History of operations performed on this frame.
Source code in wandas/core/base_frame.py
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 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 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 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 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
sampling_rate = sampling_rate
instance-attribute
¶ label = label or 'unnamed_frame'
instance-attribute
¶ metadata = metadata or {}
instance-attribute
¶ operation_history = operation_history or []
instance-attribute
¶ n_channels
property
¶Returns the number of channels.
channels
property
¶Property to access channel metadata.
previous
property
¶Returns the previous frame.
shape
property
¶ data
property
¶Returns the computed data. Calculation is executed the first time this is accessed.
labels
property
¶Get a list of all channel labels.
__init__(data, sampling_rate, label=None, metadata=None, operation_history=None, channel_metadata=None, previous=None)
¶Source code in wandas/core/base_frame.py
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 | |
get_channel(channel_idx)
¶Get channel(s) by index.
Parameters¶
channel_idx : int or sequence of int Single channel index or sequence of channel indices. Supports negative indices (e.g., -1 for the last channel).
Returns¶
S New instance containing the selected channel(s).
Examples¶
frame.get_channel(0) # Single channel frame.get_channel([0, 2, 3]) # Multiple channels frame.get_channel((-1, -2)) # Last two channels frame.get_channel(np.array([1, 2])) # NumPy array of indices
Source code in wandas/core/base_frame.py
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 | |
__len__()
¶Returns the number of channels.
Source code in wandas/core/base_frame.py
172 173 174 175 176 | |
__iter__()
¶Source code in wandas/core/base_frame.py
178 179 180 | |
__getitem__(key)
¶Get channel(s) by index, label, or advanced indexing.
This method supports multiple indexing patterns similar to NumPy and pandas:
- Single channel by index:
frame[0] - Single channel by label:
frame["ch0"] - Slice of channels:
frame[0:3] - Multiple channels by indices:
frame[[0, 2, 5]] - Multiple channels by labels:
frame[["ch0", "ch2"]] - NumPy integer array:
frame[np.array([0, 2])] - Boolean mask:
frame[mask]where mask is a boolean array - Multidimensional indexing:
frame[0, 100:200](channel + time)
Parameters¶
key : int, str, slice, list, tuple, or ndarray - int: Single channel index (supports negative indexing) - str: Single channel label - slice: Range of channels - list[int]: Multiple channel indices - list[str]: Multiple channel labels - tuple: Multidimensional indexing (channel_key, time_key, ...) - ndarray[int]: NumPy array of channel indices - ndarray[bool]: Boolean mask for channel selection
Returns¶
S New instance containing the selected channel(s).
Raises¶
ValueError If the key length is invalid for the shape or if boolean mask length doesn't match number of channels. IndexError If the channel index is out of range. TypeError If the key type is invalid or list contains mixed types. KeyError If a channel label is not found.
Examples¶
Single channel selection¶
frame[0] # First channel frame["acc_x"] # By label frame[-1] # Last channel
Multiple channel selection¶
frame[[0, 2, 5]] # Multiple indices frame[["acc_x", "acc_z"]] # Multiple labels frame[0:3] # Slice
NumPy array indexing¶
frame[np.array([0, 2, 4])] # Integer array mask = np.array([True, False, True]) frame[mask] # Boolean mask
Time slicing (multidimensional)¶
frame[0, 100:200] # Channel 0, samples 100-200 frame[[0, 1], ::2] # Channels 0-1, every 2nd sample
Source code in wandas/core/base_frame.py
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 342 | |
label2index(label)
¶Get the index from a channel label.
Parameters¶
label : str Channel label.
Returns¶
int Corresponding index.
Raises¶
KeyError If the channel label is not found.
Source code in wandas/core/base_frame.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
compute()
¶Compute and return the data. This method materializes lazily computed data into a concrete NumPy array.
Returns¶
NDArrayReal The computed data.
Raises¶
ValueError If the computed result is not a NumPy array.
Source code in wandas/core/base_frame.py
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 | |
plot(plot_type='default', ax=None, **kwargs)
abstractmethod
¶Plot the data
Source code in wandas/core/base_frame.py
479 480 481 482 483 484 | |
persist()
¶Persist the data in memory
Source code in wandas/core/base_frame.py
486 487 488 489 | |
__array__(dtype=None)
¶Implicit conversion to NumPy array
Source code in wandas/core/base_frame.py
537 538 539 540 541 542 | |
visualize_graph(filename=None)
¶Visualize the computation graph and save it to a file
Source code in wandas/core/base_frame.py
544 545 546 547 548 549 550 551 552 | |
__add__(other)
¶Addition operator
Source code in wandas/core/base_frame.py
566 567 568 | |
__sub__(other)
¶Subtraction operator
Source code in wandas/core/base_frame.py
570 571 572 | |
__mul__(other)
¶Multiplication operator
Source code in wandas/core/base_frame.py
574 575 576 | |
__truediv__(other)
¶Division operator
Source code in wandas/core/base_frame.py
578 579 580 | |
apply_operation(operation_name, **params)
¶Apply a named operation.
Parameters¶
operation_name : str Name of the operation to apply. **params : Any Parameters to pass to the operation.
Returns¶
S A new instance with the operation applied.
Source code in wandas/core/base_frame.py
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
debug_info()
¶Output detailed debug information
Source code in wandas/core/base_frame.py
606 607 608 609 610 611 612 613 614 | |
metadata
¶
Classes¶
ChannelMetadata
¶
Bases: BaseModel
Data class for storing channel metadata
Source code in wandas/core/metadata.py
8 9 10 11 12 13 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 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 | |
label = ''
class-attribute
instance-attribute
¶ unit = ''
class-attribute
instance-attribute
¶ ref = 1.0
class-attribute
instance-attribute
¶ extra = Field(default_factory=dict)
class-attribute
instance-attribute
¶ label_value
property
¶Get the label value
unit_value
property
¶Get the unit value
ref_value
property
¶Get the ref value
extra_data
property
¶Get the extra metadata dictionary
__init__(**data)
¶Source code in wandas/core/metadata.py
19 20 21 22 23 | |
__setattr__(name, value)
¶Override setattr to update ref when unit is changed directly
Source code in wandas/core/metadata.py
25 26 27 28 29 30 | |
__getitem__(key)
¶Provide dictionary-like behavior
Source code in wandas/core/metadata.py
52 53 54 55 56 57 58 59 60 61 | |
__setitem__(key, value)
¶Provide dictionary-like behavior
Source code in wandas/core/metadata.py
63 64 65 66 67 68 69 70 71 72 73 | |
to_json()
¶Convert to JSON format
Source code in wandas/core/metadata.py
75 76 77 78 | |
from_json(json_data)
classmethod
¶Convert from JSON format
Source code in wandas/core/metadata.py
80 81 82 83 84 85 | |
Functions¶
Frames Module¶
The frames module defines different types of data frames.
wandas.frames
¶
Modules¶
channel
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
dask_delayed = dask.delayed
module-attribute
¶
da_from_delayed = da.from_delayed
module-attribute
¶
da_from_array = da.from_array
module-attribute
¶
S = TypeVar('S', bound='BaseFrame[Any]')
module-attribute
¶
Classes¶
ChannelFrame
¶
Bases: BaseFrame[NDArrayReal], ChannelProcessingMixin, ChannelTransformMixin
Channel-based data frame for handling audio signals and time series data.
This frame represents channel-based data such as audio signals and time series data, with each channel containing data samples in the time domain.
Source code in wandas/frames/channel.py
32 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 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 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 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 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 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | |
time
property
¶Get time array for the signal.
Returns:
| Type | Description |
|---|---|
NDArrayReal
|
Array of time points in seconds. |
n_samples
property
¶Returns the number of samples.
duration
property
¶Returns the duration in seconds.
rms
property
¶Calculate RMS (Root Mean Square) value for each channel.
Returns:
| Type | Description |
|---|---|
NDArrayReal
|
Array of RMS values, one per channel. |
Examples:
>>> cf = ChannelFrame.read_wav("audio.wav")
>>> rms_values = cf.rms
>>> print(f"RMS values: {rms_values}")
>>> # Select channels with RMS > threshold
>>> active_channels = cf[cf.rms > 0.5]
__init__(data, sampling_rate, label=None, metadata=None, operation_history=None, channel_metadata=None, previous=None)
¶Initialize a ChannelFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
Dask array containing channel data. |
required |
sampling_rate
|
float
|
The sampling rate of the data in Hz. |
required |
label
|
Optional[str]
|
A label for the frame. |
None
|
metadata
|
Optional[dict[str, Any]]
|
Optional metadata dictionary. |
None
|
operation_history
|
Optional[list[dict[str, Any]]]
|
History of operations applied to the frame. |
None
|
channel_metadata
|
Optional[list[ChannelMetadata]]
|
Metadata for each channel. |
None
|
previous
|
Optional[BaseFrame[Any]]
|
Reference to the previous frame in the processing chain. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If data has more than 2 dimensions. |
Source code in wandas/frames/channel.py
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 | |
add(other, snr=None)
¶Add another signal or value to the current signal.
If SNR is specified, performs addition with consideration for signal-to-noise ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Union[ChannelFrame, int, float, NDArrayReal]
|
Signal or value to add. |
required |
snr
|
Optional[float]
|
Signal-to-noise ratio (dB). If specified, adjusts the scale of the other signal based on this SNR. self is treated as the signal, and other as the noise. |
None
|
Returns:
| Type | Description |
|---|---|
ChannelFrame
|
A new channel frame containing the addition result (lazy execution). |
Source code in wandas/frames/channel.py
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 | |
plot(plot_type='waveform', ax=None, **kwargs)
¶Plot the frame data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plot_type
|
str
|
Type of plot. Default is "waveform". |
'waveform'
|
ax
|
Optional[Axes]
|
Optional matplotlib axes for plotting. |
None
|
**kwargs
|
Any
|
Additional arguments passed to the plot function. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[Axes, Iterator[Axes]]
|
Single Axes object or iterator of Axes objects. |
Source code in wandas/frames/channel.py
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 | |
rms_plot(ax=None, title=None, overlay=True, Aw=False, **kwargs)
¶Generate an RMS plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Optional[Axes]
|
Optional matplotlib axes for plotting. |
None
|
title
|
Optional[str]
|
Title for the plot. |
None
|
overlay
|
bool
|
Whether to overlay the plot on the existing axis. |
True
|
Aw
|
bool
|
Apply A-weighting. |
False
|
**kwargs
|
Any
|
Additional arguments passed to the plot function. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[Axes, Iterator[Axes]]
|
Single Axes object or iterator of Axes objects. |
Source code in wandas/frames/channel.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
describe(normalize=True, is_close=True, *, fmin=0, fmax=None, cmap='jet', vmin=None, vmax=None, xlim=None, ylim=None, Aw=False, waveform=None, spectral=None, **kwargs)
¶Display visual and audio representation of the frame.
This method creates a comprehensive visualization with three plots: 1. Time-domain waveform (top) 2. Spectrogram (bottom-left) 3. Frequency spectrum via Welch method (bottom-right)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalize
|
bool
|
Whether to normalize the audio data for playback. Default: True |
True
|
is_close
|
bool
|
Whether to close the figure after displaying. Default: True |
True
|
fmin
|
float
|
Minimum frequency to display in the spectrogram (Hz). Default: 0 |
0
|
fmax
|
Optional[float]
|
Maximum frequency to display in the spectrogram (Hz). Default: Nyquist frequency (sampling_rate / 2) |
None
|
cmap
|
str
|
Colormap for the spectrogram. Default: 'jet' |
'jet'
|
vmin
|
Optional[float]
|
Minimum value for spectrogram color scale (dB). Auto-calculated if None. |
None
|
vmax
|
Optional[float]
|
Maximum value for spectrogram color scale (dB). Auto-calculated if None. |
None
|
xlim
|
Optional[tuple[float, float]]
|
Time axis limits (seconds) for all time-based plots. Format: (start_time, end_time) |
None
|
ylim
|
Optional[tuple[float, float]]
|
Frequency axis limits (Hz) for frequency-based plots. Format: (min_freq, max_freq) |
None
|
Aw
|
bool
|
Apply A-weighting to the frequency analysis. Default: False |
False
|
waveform
|
Optional[dict[str, Any]]
|
Additional configuration dict for waveform subplot. Can include 'xlabel', 'ylabel', 'xlim', 'ylim'. |
None
|
spectral
|
Optional[dict[str, Any]]
|
Additional configuration dict for spectral subplot. Can include 'xlabel', 'ylabel', 'xlim', 'ylim'. |
None
|
**kwargs
|
Any
|
Deprecated parameters for backward compatibility: - axis_config: Old configuration format - cbar_config: Old colorbar configuration |
{}
|
Examples:
>>> cf = ChannelFrame.read_wav("audio.wav")
>>> # Basic usage
>>> cf.describe()
>>>
>>> # Custom frequency range
>>> cf.describe(fmin=100, fmax=5000)
>>>
>>> # Custom color scale
>>> cf.describe(vmin=-80, vmax=-20, cmap="viridis")
>>>
>>> # A-weighted analysis
>>> cf.describe(Aw=True)
>>>
>>> # Custom time range
>>> cf.describe(xlim=(0, 5)) # Show first 5 seconds
>>>
>>> # Custom waveform subplot settings
>>> cf.describe(waveform={"ylabel": "Custom Label"})
Source code in wandas/frames/channel.py
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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 | |
from_numpy(data, sampling_rate, label=None, metadata=None, ch_labels=None, ch_units=None)
classmethod
¶Create a ChannelFrame from a NumPy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
NDArrayReal
|
NumPy array containing channel data. |
required |
sampling_rate
|
float
|
The sampling rate in Hz. |
required |
label
|
Optional[str]
|
A label for the frame. |
None
|
metadata
|
Optional[dict[str, Any]]
|
Optional metadata dictionary. |
None
|
ch_labels
|
Optional[list[str]]
|
Labels for each channel. |
None
|
ch_units
|
Optional[Union[list[str], str]]
|
Units for each channel. |
None
|
Returns:
| Type | Description |
|---|---|
ChannelFrame
|
A new ChannelFrame containing the NumPy data. |
Source code in wandas/frames/channel.py
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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | |
from_ndarray(array, sampling_rate, labels=None, unit=None, frame_label=None, metadata=None)
classmethod
¶Create a ChannelFrame from a NumPy array.
This method is deprecated. Use from_numpy instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArrayReal
|
Signal data. Each row corresponds to a channel. |
required |
sampling_rate
|
float
|
Sampling rate (Hz). |
required |
labels
|
Optional[list[str]]
|
Labels for each channel. |
None
|
unit
|
Optional[Union[list[str], str]]
|
Unit of the signal. |
None
|
frame_label
|
Optional[str]
|
Label for the frame. |
None
|
metadata
|
Optional[dict[str, Any]]
|
Optional metadata dictionary. |
None
|
Returns:
| Type | Description |
|---|---|
ChannelFrame
|
A new ChannelFrame containing the data. |
Source code in wandas/frames/channel.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 592 | |
from_file(path, channel=None, start=None, end=None, chunk_size=None, ch_labels=None, **kwargs)
classmethod
¶Create a ChannelFrame from an audio file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to the audio file. |
required |
channel
|
Optional[Union[int, list[int]]]
|
Channel(s) to load. |
None
|
start
|
Optional[float]
|
Start time in seconds. |
None
|
end
|
Optional[float]
|
End time in seconds. |
None
|
chunk_size
|
Optional[int]
|
Chunk size for processing. |
None
|
ch_labels
|
Optional[list[str]]
|
Labels for each channel. |
None
|
**kwargs
|
Any
|
Additional arguments passed to the file reader. |
{}
|
Returns:
| Type | Description |
|---|---|
ChannelFrame
|
A new ChannelFrame containing the loaded audio data. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If channel specification is invalid. |
TypeError
|
If channel parameter type is invalid. |
FileNotFoundError
|
If the file doesn't exist. |
Source code in wandas/frames/channel.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | |
read_wav(filename, labels=None)
classmethod
¶Utility method to read a WAV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the WAV file. |
required |
labels
|
Optional[list[str]]
|
Labels to set for each channel. |
None
|
Returns:
| Type | Description |
|---|---|
ChannelFrame
|
A new ChannelFrame containing the data (lazy loading). |
Source code in wandas/frames/channel.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | |
read_csv(filename, time_column=0, labels=None, delimiter=',', header=0)
classmethod
¶Utility method to read a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the CSV file. |
required |
time_column
|
Union[int, str]
|
Index or name of the time column. |
0
|
labels
|
Optional[list[str]]
|
Labels to set for each channel. |
None
|
delimiter
|
str
|
Delimiter character. |
','
|
header
|
Optional[int]
|
Row number to use as header. |
0
|
Returns:
| Type | Description |
|---|---|
ChannelFrame
|
A new ChannelFrame containing the data (lazy loading). |
Source code in wandas/frames/channel.py
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 | |
to_wav(path, format=None)
¶Save the audio data to a WAV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to save the file. |
required |
format
|
Optional[str]
|
File format. If None, determined from file extension. |
None
|
Source code in wandas/frames/channel.py
779 780 781 782 783 784 785 786 787 788 | |
save(path, *, format='hdf5', compress='gzip', overwrite=False, dtype=None)
¶Save the ChannelFrame to a WDF (Wandas Data File) format.
This saves the complete frame including all channel data and metadata in a format that can be loaded back with full fidelity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[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
|
Optional[str]
|
Compression method ('gzip' by default, None for no compression) |
'gzip'
|
overwrite
|
bool
|
Whether to overwrite existing file |
False
|
dtype
|
Optional[Union[str, dtype[Any]]]
|
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. |
Example
cf = ChannelFrame.read_wav("audio.wav") cf.save("audio_analysis.wdf")
Source code in wandas/frames/channel.py
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 | |
load(path, *, format='hdf5')
classmethod
¶Load a ChannelFrame from a WDF (Wandas Data File) file.
This loads data saved with the save() method, preserving all channel data, metadata, labels, and units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to the WDF file |
required |
format
|
str
|
Format of the file (currently only 'hdf5' is supported) |
'hdf5'
|
Returns:
| Type | Description |
|---|---|
ChannelFrame
|
A new ChannelFrame with all data and metadata loaded |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file doesn't exist |
NotImplementedError
|
For unsupported formats |
Example
cf = ChannelFrame.load("audio_analysis.wdf")
Source code in wandas/frames/channel.py
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |
add_channel(data, label=None, align='strict', suffix_on_dup=None, inplace=False, **kwargs)
¶Source code in wandas/frames/channel.py
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 | |
remove_channel(key, inplace=False)
¶Source code in wandas/frames/channel.py
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | |
Functions¶
mixins
¶
Channel frame mixins module.
Attributes¶
__all__ = ['ChannelProcessingMixin', 'ChannelTransformMixin']
module-attribute
¶
Classes¶
ChannelProcessingMixin
¶
Mixin that provides methods related to signal processing.
This mixin provides processing methods applied to audio signals and other time-series data, such as signal processing filters and transformation operations.
Source code in wandas/frames/mixins/channel_processing_mixin.py
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 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 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 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 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
high_pass_filter(cutoff, order=4)
¶Apply a high-pass filter to the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff
|
float
|
Filter cutoff frequency (Hz) |
required |
order
|
int
|
Filter order. Default is 4. |
4
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame after filter application |
Source code in wandas/frames/mixins/channel_processing_mixin.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
low_pass_filter(cutoff, order=4)
¶Apply a low-pass filter to the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff
|
float
|
Filter cutoff frequency (Hz) |
required |
order
|
int
|
Filter order. Default is 4. |
4
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame after filter application |
Source code in wandas/frames/mixins/channel_processing_mixin.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
band_pass_filter(low_cutoff, high_cutoff, order=4)
¶Apply a band-pass filter to the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
low_cutoff
|
float
|
Lower cutoff frequency (Hz) |
required |
high_cutoff
|
float
|
Higher cutoff frequency (Hz) |
required |
order
|
int
|
Filter order. Default is 4. |
4
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame after filter application |
Source code in wandas/frames/mixins/channel_processing_mixin.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
normalize(target_level=-20, channel_wise=True)
¶Normalize signal levels.
This method adjusts the signal amplitude to reach the target RMS level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_level
|
float
|
Target RMS level (dB). Default is -20. |
-20
|
channel_wise
|
bool
|
If True, normalize each channel individually. If False, apply the same scaling to all channels. |
True
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the normalized signal |
Source code in wandas/frames/mixins/channel_processing_mixin.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
a_weighting()
¶Apply A-weighting filter to the signal.
A-weighting adjusts the frequency response to approximate human auditory perception, according to the IEC 61672-1:2013 standard.
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the A-weighted signal |
Source code in wandas/frames/mixins/channel_processing_mixin.py
113 114 115 116 117 118 119 120 121 122 123 | |
abs()
¶Compute the absolute value of the signal.
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the absolute values |
Source code in wandas/frames/mixins/channel_processing_mixin.py
125 126 127 128 129 130 131 132 | |
power(exponent=2.0)
¶Compute the power of the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exponent
|
float
|
Exponent to raise the signal to. Default is 2.0. |
2.0
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the powered signal |
Source code in wandas/frames/mixins/channel_processing_mixin.py
134 135 136 137 138 139 140 141 142 143 144 | |
sum()
¶Sum all channels.
Returns:
| Type | Description |
|---|---|
T_Processing
|
A new ChannelFrame with summed signal. |
Source code in wandas/frames/mixins/channel_processing_mixin.py
184 185 186 187 188 189 190 | |
mean()
¶Average all channels.
Returns:
| Type | Description |
|---|---|
T_Processing
|
A new ChannelFrame with averaged signal. |
Source code in wandas/frames/mixins/channel_processing_mixin.py
192 193 194 195 196 197 198 | |
trim(start=0, end=None)
¶Trim the signal to the specified time range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
float
|
Start time (seconds) |
0
|
end
|
Optional[float]
|
End time (seconds) |
None
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the trimmed signal |
Raises:
| Type | Description |
|---|---|
ValueError
|
If end time is earlier than start time |
Source code in wandas/frames/mixins/channel_processing_mixin.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
fix_length(length=None, duration=None)
¶Adjust the signal to the specified length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
Optional[float]
|
Signal length in seconds |
None
|
length
|
Optional[int]
|
Signal length in samples |
None
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the adjusted signal |
Source code in wandas/frames/mixins/channel_processing_mixin.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
rms_trend(frame_length=2048, hop_length=512, dB=False, Aw=False)
¶Compute the RMS trend of the signal.
This method calculates the root mean square value over a sliding window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_length
|
int
|
Size of the sliding window in samples. Default is 2048. |
2048
|
hop_length
|
int
|
Hop length between windows in samples. Default is 512. |
512
|
dB
|
bool
|
Whether to return RMS values in decibels. Default is False. |
False
|
Aw
|
bool
|
Whether to apply A-weighting. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the RMS trend |
Source code in wandas/frames/mixins/channel_processing_mixin.py
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 | |
channel_difference(other_channel=0)
¶Compute the difference between channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other_channel
|
Union[int, str]
|
Index or label of the reference channel. Default is 0. |
0
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the channel difference |
Source code in wandas/frames/mixins/channel_processing_mixin.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
resampling(target_sr, **kwargs)
¶Resample audio data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_sr
|
float
|
Target sampling rate (Hz) |
required |
**kwargs
|
Any
|
Additional resampling parameters |
{}
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
Resampled ChannelFrame |
Source code in wandas/frames/mixins/channel_processing_mixin.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
hpss_harmonic(kernel_size=31, power=2, margin=1, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant')
¶Extract harmonic components using HPSS (Harmonic-Percussive Source Separation).
This method separates the harmonic (tonal) components from the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
Union[_IntLike_co, tuple[_IntLike_co, _IntLike_co], list[_IntLike_co]]
|
Median filter size for HPSS. |
31
|
power
|
float
|
Exponent for the Weiner filter used in HPSS. |
2
|
margin
|
Union[_FloatLike_co, tuple[_FloatLike_co, _FloatLike_co], list[_FloatLike_co]]
|
Margin size for the separation. |
1
|
n_fft
|
int
|
Size of FFT window. |
2048
|
hop_length
|
Optional[int]
|
Hop length for STFT. |
None
|
win_length
|
Optional[int]
|
Window length for STFT. |
None
|
window
|
_WindowSpec
|
Window type for STFT. |
'hann'
|
center
|
bool
|
If True, center the frames. |
True
|
pad_mode
|
_PadModeSTFT
|
Padding mode for STFT. |
'constant'
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
A new ChannelFrame containing the harmonic components. |
Source code in wandas/frames/mixins/channel_processing_mixin.py
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 | |
hpss_percussive(kernel_size=31, power=2, margin=1, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant')
¶Extract percussive components using HPSS (Harmonic-Percussive Source Separation).
This method separates the percussive (tonal) components from the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
Union[_IntLike_co, tuple[_IntLike_co, _IntLike_co], list[_IntLike_co]]
|
Median filter size for HPSS. |
31
|
power
|
float
|
Exponent for the Weiner filter used in HPSS. |
2
|
margin
|
Union[_FloatLike_co, tuple[_FloatLike_co, _FloatLike_co], list[_FloatLike_co]]
|
Margin size for the separation. |
1
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
A new ChannelFrame containing the harmonic components. |
Source code in wandas/frames/mixins/channel_processing_mixin.py
380 381 382 383 384 385 386 387 388 389 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 415 416 417 418 419 420 421 422 423 424 | |
ChannelTransformMixin
¶
Mixin providing methods related to frequency transformations.
This mixin provides operations related to frequency analysis and transformations such as FFT, STFT, and Welch method.
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 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 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 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 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 | |
fft(n_fft=None, window='hann')
¶Calculate Fast Fourier Transform (FFT).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
Optional[int]
|
Number of FFT points. Default is the next power of 2 of the data length. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing FFT results |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 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 | |
welch(n_fft=None, hop_length=None, win_length=2048, window='hann', average='mean')
¶Calculate power spectral density using Welch's method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
Optional[int]
|
Number of FFT points. Default is 2048. |
None
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
int
|
Window length. Default is n_fft. |
2048
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
average
|
str
|
Method for averaging segments. Default is "mean". |
'mean'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing power spectral density |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 | |
noct_spectrum(fmin, fmax, n=3, G=10, fr=1000)
¶Calculate N-octave band spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmin
|
float
|
Minimum center frequency (Hz). Default is 20 Hz. |
required |
fmax
|
float
|
Maximum center frequency (Hz). Default is 20000 Hz. |
required |
n
|
int
|
Band division (1: octave, 3: 1/3 octave). Default is 3. |
3
|
G
|
int
|
Reference gain (dB). Default is 10 dB. |
10
|
fr
|
int
|
Reference frequency (Hz). Default is 1000 Hz. |
1000
|
Returns:
| Type | Description |
|---|---|
NOctFrame
|
NOctFrame containing N-octave band spectrum |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 | |
stft(n_fft=2048, hop_length=None, win_length=None, window='hann')
¶Calculate Short-Time Fourier Transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
int
|
Number of FFT points. Default is 2048. |
2048
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
Optional[int]
|
Window length. Default is n_fft. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
Returns:
| Type | Description |
|---|---|
SpectrogramFrame
|
SpectrogramFrame containing STFT results |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 | |
coherence(n_fft=2048, hop_length=None, win_length=None, window='hann', detrend='constant')
¶Calculate magnitude squared coherence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
int
|
Number of FFT points. Default is 2048. |
2048
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
Optional[int]
|
Window length. Default is n_fft. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
detrend
|
str
|
Detrend method. Options: "constant", "linear", None. |
'constant'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing magnitude squared coherence |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 | |
csd(n_fft=2048, hop_length=None, win_length=None, window='hann', detrend='constant', scaling='spectrum', average='mean')
¶Calculate cross-spectral density matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
int
|
Number of FFT points. Default is 2048. |
2048
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
Optional[int]
|
Window length. Default is n_fft. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
detrend
|
str
|
Detrend method. Options: "constant", "linear", None. |
'constant'
|
scaling
|
str
|
Scaling method. Options: "spectrum", "density". |
'spectrum'
|
average
|
str
|
Method for averaging segments. Default is "mean". |
'mean'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing cross-spectral density matrix |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
transfer_function(n_fft=2048, hop_length=None, win_length=None, window='hann', detrend='constant', scaling='spectrum', average='mean')
¶Calculate transfer function matrix.
The transfer function represents the signal transfer characteristics between channels in the frequency domain and represents the input-output relationship of the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
int
|
Number of FFT points. Default is 2048. |
2048
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
Optional[int]
|
Window length. Default is n_fft. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
detrend
|
str
|
Detrend method. Options: "constant", "linear", None. |
'constant'
|
scaling
|
str
|
Scaling method. Options: "spectrum", "density". |
'spectrum'
|
average
|
str
|
Method for averaging segments. Default is "mean". |
'mean'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing transfer function matrix |
Source code in wandas/frames/mixins/channel_transform_mixin.py
436 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 | |
Modules¶
channel_collection_mixin
¶
ChannelCollectionMixin: Common functionality for adding/removing channels in ChannelFrame
T = TypeVar('T', bound='ChannelCollectionMixin')
module-attribute
¶ ChannelCollectionMixin
¶Source code in wandas/frames/mixins/channel_collection_mixin.py
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 53 54 55 56 57 | |
add_channel(data, label=None, align='strict', suffix_on_dup=None, inplace=False, **kwargs)
¶Add a channel Args: data: Channel to add (1ch ndarray/dask/ChannelFrame) label: Label for the added channel align: Behavior when lengths don't match suffix_on_dup: Suffix when label is duplicated inplace: True for self-modification Returns: New Frame or self Raises: ValueError, TypeError
Source code in wandas/frames/mixins/channel_collection_mixin.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
remove_channel(key, inplace=False)
¶Remove a channel Args: key: Target to remove (index or label) inplace: True for self-modification Returns: New Frame or self Raises: ValueError, KeyError, IndexError
Source code in wandas/frames/mixins/channel_collection_mixin.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
channel_processing_mixin
¶
Module providing mixins related to signal processing.
logger = logging.getLogger(__name__)
module-attribute
¶ ChannelProcessingMixin
¶Mixin that provides methods related to signal processing.
This mixin provides processing methods applied to audio signals and other time-series data, such as signal processing filters and transformation operations.
Source code in wandas/frames/mixins/channel_processing_mixin.py
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 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 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 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 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
high_pass_filter(cutoff, order=4)
¶Apply a high-pass filter to the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff
|
float
|
Filter cutoff frequency (Hz) |
required |
order
|
int
|
Filter order. Default is 4. |
4
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame after filter application |
Source code in wandas/frames/mixins/channel_processing_mixin.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
low_pass_filter(cutoff, order=4)
¶Apply a low-pass filter to the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff
|
float
|
Filter cutoff frequency (Hz) |
required |
order
|
int
|
Filter order. Default is 4. |
4
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame after filter application |
Source code in wandas/frames/mixins/channel_processing_mixin.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
band_pass_filter(low_cutoff, high_cutoff, order=4)
¶Apply a band-pass filter to the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
low_cutoff
|
float
|
Lower cutoff frequency (Hz) |
required |
high_cutoff
|
float
|
Higher cutoff frequency (Hz) |
required |
order
|
int
|
Filter order. Default is 4. |
4
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame after filter application |
Source code in wandas/frames/mixins/channel_processing_mixin.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
normalize(target_level=-20, channel_wise=True)
¶Normalize signal levels.
This method adjusts the signal amplitude to reach the target RMS level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_level
|
float
|
Target RMS level (dB). Default is -20. |
-20
|
channel_wise
|
bool
|
If True, normalize each channel individually. If False, apply the same scaling to all channels. |
True
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the normalized signal |
Source code in wandas/frames/mixins/channel_processing_mixin.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
a_weighting()
¶Apply A-weighting filter to the signal.
A-weighting adjusts the frequency response to approximate human auditory perception, according to the IEC 61672-1:2013 standard.
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the A-weighted signal |
Source code in wandas/frames/mixins/channel_processing_mixin.py
113 114 115 116 117 118 119 120 121 122 123 | |
abs()
¶Compute the absolute value of the signal.
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the absolute values |
Source code in wandas/frames/mixins/channel_processing_mixin.py
125 126 127 128 129 130 131 132 | |
power(exponent=2.0)
¶Compute the power of the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exponent
|
float
|
Exponent to raise the signal to. Default is 2.0. |
2.0
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the powered signal |
Source code in wandas/frames/mixins/channel_processing_mixin.py
134 135 136 137 138 139 140 141 142 143 144 | |
sum()
¶Sum all channels.
Returns:
| Type | Description |
|---|---|
T_Processing
|
A new ChannelFrame with summed signal. |
Source code in wandas/frames/mixins/channel_processing_mixin.py
184 185 186 187 188 189 190 | |
mean()
¶Average all channels.
Returns:
| Type | Description |
|---|---|
T_Processing
|
A new ChannelFrame with averaged signal. |
Source code in wandas/frames/mixins/channel_processing_mixin.py
192 193 194 195 196 197 198 | |
trim(start=0, end=None)
¶Trim the signal to the specified time range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
float
|
Start time (seconds) |
0
|
end
|
Optional[float]
|
End time (seconds) |
None
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the trimmed signal |
Raises:
| Type | Description |
|---|---|
ValueError
|
If end time is earlier than start time |
Source code in wandas/frames/mixins/channel_processing_mixin.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
fix_length(length=None, duration=None)
¶Adjust the signal to the specified length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
Optional[float]
|
Signal length in seconds |
None
|
length
|
Optional[int]
|
Signal length in samples |
None
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the adjusted signal |
Source code in wandas/frames/mixins/channel_processing_mixin.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
rms_trend(frame_length=2048, hop_length=512, dB=False, Aw=False)
¶Compute the RMS trend of the signal.
This method calculates the root mean square value over a sliding window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_length
|
int
|
Size of the sliding window in samples. Default is 2048. |
2048
|
hop_length
|
int
|
Hop length between windows in samples. Default is 512. |
512
|
dB
|
bool
|
Whether to return RMS values in decibels. Default is False. |
False
|
Aw
|
bool
|
Whether to apply A-weighting. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the RMS trend |
Source code in wandas/frames/mixins/channel_processing_mixin.py
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 | |
channel_difference(other_channel=0)
¶Compute the difference between channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other_channel
|
Union[int, str]
|
Index or label of the reference channel. Default is 0. |
0
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
New ChannelFrame containing the channel difference |
Source code in wandas/frames/mixins/channel_processing_mixin.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
resampling(target_sr, **kwargs)
¶Resample audio data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_sr
|
float
|
Target sampling rate (Hz) |
required |
**kwargs
|
Any
|
Additional resampling parameters |
{}
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
Resampled ChannelFrame |
Source code in wandas/frames/mixins/channel_processing_mixin.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
hpss_harmonic(kernel_size=31, power=2, margin=1, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant')
¶Extract harmonic components using HPSS (Harmonic-Percussive Source Separation).
This method separates the harmonic (tonal) components from the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
Union[_IntLike_co, tuple[_IntLike_co, _IntLike_co], list[_IntLike_co]]
|
Median filter size for HPSS. |
31
|
power
|
float
|
Exponent for the Weiner filter used in HPSS. |
2
|
margin
|
Union[_FloatLike_co, tuple[_FloatLike_co, _FloatLike_co], list[_FloatLike_co]]
|
Margin size for the separation. |
1
|
n_fft
|
int
|
Size of FFT window. |
2048
|
hop_length
|
Optional[int]
|
Hop length for STFT. |
None
|
win_length
|
Optional[int]
|
Window length for STFT. |
None
|
window
|
_WindowSpec
|
Window type for STFT. |
'hann'
|
center
|
bool
|
If True, center the frames. |
True
|
pad_mode
|
_PadModeSTFT
|
Padding mode for STFT. |
'constant'
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
A new ChannelFrame containing the harmonic components. |
Source code in wandas/frames/mixins/channel_processing_mixin.py
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 | |
hpss_percussive(kernel_size=31, power=2, margin=1, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant')
¶Extract percussive components using HPSS (Harmonic-Percussive Source Separation).
This method separates the percussive (tonal) components from the signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
Union[_IntLike_co, tuple[_IntLike_co, _IntLike_co], list[_IntLike_co]]
|
Median filter size for HPSS. |
31
|
power
|
float
|
Exponent for the Weiner filter used in HPSS. |
2
|
margin
|
Union[_FloatLike_co, tuple[_FloatLike_co, _FloatLike_co], list[_FloatLike_co]]
|
Margin size for the separation. |
1
|
Returns:
| Type | Description |
|---|---|
T_Processing
|
A new ChannelFrame containing the harmonic components. |
Source code in wandas/frames/mixins/channel_processing_mixin.py
380 381 382 383 384 385 386 387 388 389 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 415 416 417 418 419 420 421 422 423 424 | |
channel_transform_mixin
¶
Module providing mixins related to frequency transformations and transform operations.
logger = logging.getLogger(__name__)
module-attribute
¶ ChannelTransformMixin
¶Mixin providing methods related to frequency transformations.
This mixin provides operations related to frequency analysis and transformations such as FFT, STFT, and Welch method.
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 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 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 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 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 | |
fft(n_fft=None, window='hann')
¶Calculate Fast Fourier Transform (FFT).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
Optional[int]
|
Number of FFT points. Default is the next power of 2 of the data length. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing FFT results |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 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 | |
welch(n_fft=None, hop_length=None, win_length=2048, window='hann', average='mean')
¶Calculate power spectral density using Welch's method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
Optional[int]
|
Number of FFT points. Default is 2048. |
None
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
int
|
Window length. Default is n_fft. |
2048
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
average
|
str
|
Method for averaging segments. Default is "mean". |
'mean'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing power spectral density |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 | |
noct_spectrum(fmin, fmax, n=3, G=10, fr=1000)
¶Calculate N-octave band spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmin
|
float
|
Minimum center frequency (Hz). Default is 20 Hz. |
required |
fmax
|
float
|
Maximum center frequency (Hz). Default is 20000 Hz. |
required |
n
|
int
|
Band division (1: octave, 3: 1/3 octave). Default is 3. |
3
|
G
|
int
|
Reference gain (dB). Default is 10 dB. |
10
|
fr
|
int
|
Reference frequency (Hz). Default is 1000 Hz. |
1000
|
Returns:
| Type | Description |
|---|---|
NOctFrame
|
NOctFrame containing N-octave band spectrum |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 | |
stft(n_fft=2048, hop_length=None, win_length=None, window='hann')
¶Calculate Short-Time Fourier Transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
int
|
Number of FFT points. Default is 2048. |
2048
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
Optional[int]
|
Window length. Default is n_fft. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
Returns:
| Type | Description |
|---|---|
SpectrogramFrame
|
SpectrogramFrame containing STFT results |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 | |
coherence(n_fft=2048, hop_length=None, win_length=None, window='hann', detrend='constant')
¶Calculate magnitude squared coherence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
int
|
Number of FFT points. Default is 2048. |
2048
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
Optional[int]
|
Window length. Default is n_fft. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
detrend
|
str
|
Detrend method. Options: "constant", "linear", None. |
'constant'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing magnitude squared coherence |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 | |
csd(n_fft=2048, hop_length=None, win_length=None, window='hann', detrend='constant', scaling='spectrum', average='mean')
¶Calculate cross-spectral density matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
int
|
Number of FFT points. Default is 2048. |
2048
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
Optional[int]
|
Window length. Default is n_fft. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
detrend
|
str
|
Detrend method. Options: "constant", "linear", None. |
'constant'
|
scaling
|
str
|
Scaling method. Options: "spectrum", "density". |
'spectrum'
|
average
|
str
|
Method for averaging segments. Default is "mean". |
'mean'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing cross-spectral density matrix |
Source code in wandas/frames/mixins/channel_transform_mixin.py
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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
transfer_function(n_fft=2048, hop_length=None, win_length=None, window='hann', detrend='constant', scaling='spectrum', average='mean')
¶Calculate transfer function matrix.
The transfer function represents the signal transfer characteristics between channels in the frequency domain and represents the input-output relationship of the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_fft
|
int
|
Number of FFT points. Default is 2048. |
2048
|
hop_length
|
Optional[int]
|
Number of samples between frames. Default is n_fft//4. |
None
|
win_length
|
Optional[int]
|
Window length. Default is n_fft. |
None
|
window
|
str
|
Window type. Default is "hann". |
'hann'
|
detrend
|
str
|
Detrend method. Options: "constant", "linear", None. |
'constant'
|
scaling
|
str
|
Scaling method. Options: "spectrum", "density". |
'spectrum'
|
average
|
str
|
Method for averaging segments. Default is "mean". |
'mean'
|
Returns:
| Type | Description |
|---|---|
SpectralFrame
|
SpectralFrame containing transfer function matrix |
Source code in wandas/frames/mixins/channel_transform_mixin.py
436 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 | |
protocols
¶
Common protocol definition module.
This module contains common protocols used by mixin classes.
logger = logging.getLogger(__name__)
module-attribute
¶ T_Base = TypeVar('T_Base', bound='BaseFrameProtocol')
module-attribute
¶ T_Processing = TypeVar('T_Processing', bound=ProcessingFrameProtocol)
module-attribute
¶ T_Transform = TypeVar('T_Transform', bound=TransformFrameProtocol)
module-attribute
¶ __all__ = ['BaseFrameProtocol', 'ProcessingFrameProtocol', 'TransformFrameProtocol', 'T_Processing']
module-attribute
¶ BaseFrameProtocol
¶
Bases: Protocol
Protocol that defines basic frame operations.
Defines the basic methods and properties provided by all frame classes.
Source code in wandas/frames/mixins/protocols.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
sampling_rate
instance-attribute
¶ metadata
instance-attribute
¶ operation_history
instance-attribute
¶ label
instance-attribute
¶ duration
property
¶Returns the duration in seconds.
label2index(label)
¶Get the index from a channel label.
Source code in wandas/frames/mixins/protocols.py
38 39 40 41 42 | |
apply_operation(operation_name, **params)
¶Apply a named operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation_name
|
str
|
Name of the operation to apply |
required |
**params
|
Any
|
Parameters to pass to the operation |
{}
|
Returns:
| Type | Description |
|---|---|
BaseFrameProtocol
|
A new frame instance with the operation applied |
Source code in wandas/frames/mixins/protocols.py
44 45 46 47 48 49 50 51 52 53 54 55 56 | |
ProcessingFrameProtocol
¶
Bases: BaseFrameProtocol, Protocol
Protocol that defines operations related to signal processing.
Defines methods that provide frame operations related to signal processing.
Source code in wandas/frames/mixins/protocols.py
71 72 73 74 75 76 77 78 | |
TransformFrameProtocol
¶
Bases: BaseFrameProtocol, Protocol
Protocol related to transform operations.
Defines methods that provide operations such as frequency analysis and spectral transformation.
Source code in wandas/frames/mixins/protocols.py
81 82 83 84 85 86 87 88 89 | |
noct
¶
Attributes¶
dask_delayed = dask.delayed
module-attribute
¶
da_from_delayed = da.from_delayed
module-attribute
¶
da_from_array = da.from_array
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
S = TypeVar('S', bound='BaseFrame[Any]')
module-attribute
¶
Classes¶
NOctFrame
¶
Bases: BaseFrame[NDArrayReal]
Class for handling N-octave band analysis data.
This class represents frequency data analyzed in fractional octave bands, typically used in acoustic and vibration analysis. It handles real-valued data representing energy or power in each frequency band, following standard acoustical band definitions.
Parameters¶
data : DaArray The N-octave band data. Must be a dask array with shape: - (channels, frequency_bins) for multi-channel data - (frequency_bins,) for single-channel data, which will be reshaped to (1, frequency_bins) sampling_rate : float The sampling rate of the original time-domain signal in Hz. fmin : float, default=0 Lower frequency bound in Hz. fmax : float, default=0 Upper frequency bound in Hz. n : int, default=3 Number of bands per octave (e.g., 3 for third-octave bands). G : int, default=10 Reference band number according to IEC 61260-1:2014. fr : int, default=1000 Reference frequency in Hz, typically 1000 Hz for acoustic analysis. label : str, optional A label for the frame. metadata : dict, optional Additional metadata for the frame. operation_history : list[dict], optional History of operations performed on this frame. channel_metadata : list[ChannelMetadata], optional Metadata for each channel in the frame. previous : BaseFrame, optional The frame that this frame was derived from.
Attributes¶
freqs : NDArrayReal The center frequencies of each band in Hz, calculated according to the standard fractional octave band definitions. dB : NDArrayReal The spectrum in decibels relative to channel reference values. dBA : NDArrayReal The A-weighted spectrum in decibels, applying frequency weighting for better correlation with perceived loudness. fmin : float Lower frequency bound in Hz. fmax : float Upper frequency bound in Hz. n : int Number of bands per octave. G : int Reference band number. fr : int Reference frequency in Hz.
Examples¶
Create an N-octave band spectrum from a time-domain signal:
signal = ChannelFrame.from_wav("audio.wav") spectrum = signal.noct_spectrum(fmin=20, fmax=20000, n=3)
Plot the N-octave band spectrum:
spectrum.plot()
Plot with A-weighting applied:
spectrum.plot(Aw=True)
Notes¶
- Binary operations (addition, multiplication, etc.) are not currently supported for N-octave band data.
- The actual frequency bands are determined by the parameters n, G, and fr according to IEC 61260-1:2014 standard for fractional octave band filters.
- The class follows acoustic standards for band definitions and analysis, making it suitable for noise measurements and sound level analysis.
- A-weighting is available for better correlation with human hearing perception, following IEC 61672-1:2013.
Source code in wandas/frames/noct.py
32 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 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 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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
n = n
instance-attribute
¶ G = G
instance-attribute
¶ fr = fr
instance-attribute
¶ fmin = fmin
instance-attribute
¶ fmax = fmax
instance-attribute
¶ dB
property
¶Get the spectrum in decibels relative to each channel's reference value.
The reference value for each channel is specified in its metadata. A minimum value of -120 dB is enforced to avoid numerical issues.
Returns¶
NDArrayReal The spectrum in decibels. Shape matches the input data shape: (channels, frequency_bins).
dBA
property
¶Get the A-weighted spectrum in decibels.
A-weighting applies a frequency-dependent weighting filter that approximates the human ear's response to different frequencies. This is particularly useful for analyzing noise and acoustic measurements as it provides a better correlation with perceived loudness.
The weighting is applied according to IEC 61672-1:2013 standard.
Returns¶
NDArrayReal The A-weighted spectrum in decibels. Shape matches the input data shape: (channels, frequency_bins).
freqs
property
¶Get the center frequencies of each band in Hz.
These frequencies are calculated based on the N-octave band parameters (n, G, fr) and the frequency bounds (fmin, fmax) according to IEC 61260-1:2014 standard for fractional octave band filters.
Returns¶
NDArrayReal Array of center frequencies for each frequency band.
Raises¶
ValueError If the center frequencies cannot be calculated or the result is not a numpy array.
__init__(data, sampling_rate, fmin=0, fmax=0, n=3, G=10, fr=1000, label=None, metadata=None, operation_history=None, channel_metadata=None, previous=None)
¶Initialize a NOctFrame instance.
Sets up N-octave band analysis parameters and prepares the frame for storing band-filtered data. Data shape is validated to ensure compatibility with N-octave band analysis.
See class docstring for parameter descriptions.
Source code in wandas/frames/noct.py
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 | |
plot(plot_type='noct', ax=None, **kwargs)
¶Plot the N-octave band data using various visualization strategies.
Supports standard plotting configurations for acoustic analysis, including decibel scales and A-weighting.
Parameters¶
plot_type : str, default="noct" Type of plot to create. The default "noct" type creates a bar plot suitable for displaying N-octave band data. ax : matplotlib.axes.Axes, optional Axes to plot on. If None, creates new axes. **kwargs : dict Additional keyword arguments passed to the plot strategy. Common options include: - dB: Whether to plot in decibels - Aw: Whether to apply A-weighting - title: Plot title - xlabel, ylabel: Axis labels - xscale: Set to "log" for logarithmic frequency axis - grid: Whether to show grid lines
Returns¶
Union[Axes, Iterator[Axes]] The matplotlib axes containing the plot, or an iterator of axes for multi-plot outputs.
Source code in wandas/frames/noct.py
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 | |
spectral
¶
Attributes¶
dask_delayed = dask.delayed
module-attribute
¶
da_from_delayed = da.from_delayed
module-attribute
¶
da_from_array = da.from_array
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
S = TypeVar('S', bound='BaseFrame[Any]')
module-attribute
¶
Classes¶
SpectralFrame
¶
Bases: BaseFrame[NDArrayComplex]
Class for handling frequency-domain signal data.
This class represents spectral data, providing methods for spectral analysis, manipulation, and visualization. It handles complex-valued frequency domain data obtained through operations like FFT.
Parameters¶
data : DaArray The spectral data. Must be a dask array with shape: - (channels, frequency_bins) for multi-channel data - (frequency_bins,) for single-channel data, which will be reshaped to (1, frequency_bins) sampling_rate : float The sampling rate of the original time-domain signal in Hz. n_fft : int The FFT size used to generate this spectral data. window : str, default="hann" The window function used in the FFT. label : str, optional A label for the frame. metadata : dict, optional Additional metadata for the frame. operation_history : list[dict], optional History of operations performed on this frame. channel_metadata : list[ChannelMetadata], optional Metadata for each channel in the frame. previous : BaseFrame, optional The frame that this frame was derived from.
Attributes¶
magnitude : NDArrayReal The magnitude spectrum of the data. phase : NDArrayReal The phase spectrum in radians. power : NDArrayReal The power spectrum (magnitude squared). dB : NDArrayReal The spectrum in decibels relative to channel reference values. dBA : NDArrayReal The A-weighted spectrum in decibels. freqs : NDArrayReal The frequency axis values in Hz.
Examples¶
Create a SpectralFrame from FFT:
signal = ChannelFrame.from_numpy(data, sampling_rate=44100) spectrum = signal.fft(n_fft=2048)
Plot the magnitude spectrum:
spectrum.plot()
Perform binary operations:
scaled = spectrum * 2.0 summed = spectrum1 + spectrum2 # Must have matching sampling rates
Convert back to time domain:
time_signal = spectrum.ifft()
Notes¶
- All operations are performed lazily using dask arrays for efficient memory usage.
- Binary operations (+, -, *, /) can be performed between SpectralFrames or with scalar values.
- The class maintains the processing history and metadata through all operations.
Source code in wandas/frames/spectral.py
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 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 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 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 | |
n_fft = n_fft
instance-attribute
¶ window = window
instance-attribute
¶ magnitude
property
¶ phase
property
¶ dB
property
¶Get the spectrum in decibels.
The reference values are taken from channel metadata. If no reference is specified, uses 1.0.
Returns¶
NDArrayReal The spectrum in dB relative to channel references.
dBA
property
¶Get the A-weighted spectrum in decibels.
Applies A-weighting filter to the spectrum for better correlation with perceived loudness.
Returns¶
NDArrayReal The A-weighted spectrum in dB.
freqs
property
¶Get the frequency axis values in Hz.
Returns¶
NDArrayReal Array of frequency values corresponding to each frequency bin.
__init__(data, sampling_rate, n_fft, window='hann', label=None, metadata=None, operation_history=None, channel_metadata=None, previous=None)
¶Source code in wandas/frames/spectral.py
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 | |
plot(plot_type='frequency', ax=None, **kwargs)
¶Plot the spectral data using various visualization strategies.
Parameters¶
plot_type : str, default="frequency" Type of plot to create. Options include: - "frequency": Standard frequency plot - "matrix": Matrix plot for comparing channels - Other types as defined by available plot strategies ax : matplotlib.axes.Axes, optional Axes to plot on. If None, creates new axes. **kwargs : dict Additional keyword arguments passed to the plot strategy. Common options include: - title: Plot title - xlabel, ylabel: Axis labels - vmin, vmax: Value limits for plots - cmap: Colormap name - dB: Whether to plot in decibels - Aw: Whether to apply A-weighting
Returns¶
Union[Axes, Iterator[Axes]] The matplotlib axes containing the plot, or an iterator of axes for multi-plot outputs.
Source code in wandas/frames/spectral.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
ifft()
¶Compute the Inverse Fast Fourier Transform (IFFT) to return to time domain.
This method transforms the frequency-domain data back to the time domain using the inverse FFT operation. The window function used in the forward FFT is taken into account to ensure proper reconstruction.
Returns¶
ChannelFrame A new ChannelFrame containing the time-domain signal.
Source code in wandas/frames/spectral.py
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 | |
noct_synthesis(fmin, fmax, n=3, G=10, fr=1000)
¶Synthesize N-octave band spectrum.
This method combines frequency components into N-octave bands according to standard acoustical band definitions. This is commonly used in noise and vibration analysis.
Parameters¶
fmin : float Lower frequency bound in Hz. fmax : float Upper frequency bound in Hz. n : int, default=3 Number of bands per octave (e.g., 3 for third-octave bands). G : int, default=10 Reference band number. fr : int, default=1000 Reference frequency in Hz.
Returns¶
NOctFrame A new NOctFrame containing the N-octave band spectrum.
Raises¶
ValueError If the sampling rate is not 48000 Hz, which is required for this operation.
Source code in wandas/frames/spectral.py
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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
plot_matrix(plot_type='matrix', **kwargs)
¶Plot channel relationships in matrix format.
This method creates a matrix plot showing relationships between channels, such as coherence, transfer functions, or cross-spectral density.
Parameters¶
plot_type : str, default="matrix" Type of matrix plot to create. **kwargs : dict Additional plot parameters: - vmin, vmax: Color scale limits - cmap: Colormap name - title: Plot title
Returns¶
Union[Axes, Iterator[Axes]] The matplotlib axes containing the plot.
Source code in wandas/frames/spectral.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 | |
spectrogram
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
S = TypeVar('S', bound='BaseFrame[Any]')
module-attribute
¶
Classes¶
SpectrogramFrame
¶
Bases: BaseFrame[NDArrayComplex]
Class for handling time-frequency domain data (spectrograms).
This class represents spectrogram data obtained through Short-Time Fourier Transform (STFT) or similar time-frequency analysis methods. It provides methods for visualization, manipulation, and conversion back to time domain.
Parameters¶
data : DaArray The spectrogram data. Must be a dask array with shape: - (channels, frequency_bins, time_frames) for multi-channel data - (frequency_bins, time_frames) for single-channel data, which will be reshaped to (1, frequency_bins, time_frames) sampling_rate : float The sampling rate of the original time-domain signal in Hz. n_fft : int The FFT size used to generate this spectrogram. hop_length : int Number of samples between successive frames. win_length : int, optional The window length in samples. If None, defaults to n_fft. window : str, default="hann" The window function to use (e.g., "hann", "hamming", "blackman"). label : str, optional A label for the frame. metadata : dict, optional Additional metadata for the frame. operation_history : list[dict], optional History of operations performed on this frame. channel_metadata : list[ChannelMetadata], optional Metadata for each channel in the frame. previous : BaseFrame, optional The frame that this frame was derived from.
Attributes¶
magnitude : NDArrayReal The magnitude spectrogram. phase : NDArrayReal The phase spectrogram in radians. power : NDArrayReal The power spectrogram. dB : NDArrayReal The spectrogram in decibels relative to channel reference values. dBA : NDArrayReal The A-weighted spectrogram in decibels. n_frames : int Number of time frames. n_freq_bins : int Number of frequency bins. freqs : NDArrayReal The frequency axis values in Hz. times : NDArrayReal The time axis values in seconds.
Examples¶
Create a spectrogram from a time-domain signal:
signal = ChannelFrame.from_wav("audio.wav") spectrogram = signal.stft(n_fft=2048, hop_length=512)
Extract a specific time frame:
frame_at_1s = spectrogram.get_frame_at(int(1.0 * sampling_rate / hop_length))
Convert back to time domain:
reconstructed = spectrogram.to_channel_frame()
Plot the spectrogram:
spectrogram.plot()
Source code in wandas/frames/spectrogram.py
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 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 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 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 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | |
n_fft = n_fft
instance-attribute
¶ hop_length = hop_length
instance-attribute
¶ win_length = win_length if win_length is not None else n_fft
instance-attribute
¶ window = window
instance-attribute
¶ magnitude
property
¶ phase
property
¶Get the phase spectrogram.
Returns¶
NDArrayReal The phase angles of the complex spectrogram in radians.
power
property
¶ dB
property
¶Get the spectrogram in decibels relative to each channel's reference value.
The reference value for each channel is specified in its metadata. A minimum value of -120 dB is enforced to avoid numerical issues.
Returns¶
NDArrayReal The spectrogram in decibels.
dBA
property
¶Get the A-weighted spectrogram in decibels.
A-weighting applies a frequency-dependent weighting filter that approximates the human ear's response. This is particularly useful for analyzing noise and acoustic measurements.
Returns¶
NDArrayReal The A-weighted spectrogram in decibels.
n_frames
property
¶ n_freq_bins
property
¶ freqs
property
¶Get the frequency axis values in Hz.
Returns¶
NDArrayReal Array of frequency values corresponding to each frequency bin.
times
property
¶Get the time axis values in seconds.
Returns¶
NDArrayReal Array of time values corresponding to each time frame.
__init__(data, sampling_rate, n_fft, hop_length, win_length=None, window='hann', label=None, metadata=None, operation_history=None, channel_metadata=None, previous=None)
¶Source code in wandas/frames/spectrogram.py
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 | |
plot(plot_type='spectrogram', ax=None, **kwargs)
¶Plot the spectrogram using various visualization strategies.
Parameters¶
plot_type : str, default="spectrogram" Type of plot to create. ax : matplotlib.axes.Axes, optional Axes to plot on. If None, creates new axes. **kwargs : dict Additional keyword arguments passed to the plot strategy. Common options include: - vmin, vmax: Colormap scaling - cmap: Colormap name - dB: Whether to plot in decibels - Aw: Whether to apply A-weighting
Returns¶
Union[Axes, Iterator[Axes]] The matplotlib axes containing the plot, or an iterator of axes for multi-plot outputs.
Source code in wandas/frames/spectrogram.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 | |
plot_Aw(plot_type='spectrogram', ax=None, **kwargs)
¶Plot the A-weighted spectrogram.
A convenience method that calls plot() with Aw=True, applying A-weighting to the spectrogram before plotting.
Parameters¶
plot_type : str, default="spectrogram" Type of plot to create. ax : matplotlib.axes.Axes, optional Axes to plot on. If None, creates new axes. **kwargs : dict Additional keyword arguments passed to plot().
Returns¶
Union[Axes, Iterator[Axes]] The matplotlib axes containing the plot.
Source code in wandas/frames/spectrogram.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
abs()
¶Compute the absolute value (magnitude) of the complex spectrogram.
This method calculates the magnitude of each complex value in the spectrogram, converting the complex-valued data to real-valued magnitude data. The result is stored in a new SpectrogramFrame with complex dtype to maintain compatibility with other spectrogram operations.
Returns¶
SpectrogramFrame A new SpectrogramFrame containing the magnitude values as complex numbers (with zero imaginary parts).
Examples¶
signal = ChannelFrame.from_wav("audio.wav") spectrogram = signal.stft(n_fft=2048, hop_length=512) magnitude_spectrogram = spectrogram.abs()
The magnitude can be accessed via the magnitude property or data¶
print(magnitude_spectrogram.magnitude.shape)
Source code in wandas/frames/spectrogram.py
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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
get_frame_at(time_idx)
¶Extract spectral data at a specific time frame.
Parameters¶
time_idx : int Index of the time frame to extract.
Returns¶
SpectralFrame A new SpectralFrame containing the spectral data at the specified time.
Raises¶
IndexError If time_idx is out of range.
Source code in wandas/frames/spectrogram.py
553 554 555 556 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 | |
to_channel_frame()
¶Convert the spectrogram back to time domain using inverse STFT.
This method performs an inverse Short-Time Fourier Transform (ISTFT) to reconstruct the time-domain signal from the spectrogram.
Returns¶
ChannelFrame A new ChannelFrame containing the reconstructed time-domain signal.
See Also¶
istft : Alias for this method with more intuitive naming.
Source code in wandas/frames/spectrogram.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
istft()
¶Convert the spectrogram back to time domain using inverse STFT.
This is an alias for to_channel_frame() with a more intuitive name.
It performs an inverse Short-Time Fourier Transform (ISTFT) to
reconstruct the time-domain signal from the spectrogram.
Returns¶
ChannelFrame A new ChannelFrame containing the reconstructed time-domain signal.
See Also¶
to_channel_frame : The underlying implementation.
Examples¶
signal = ChannelFrame.from_wav("audio.wav") spectrogram = signal.stft(n_fft=2048, hop_length=512) reconstructed = spectrogram.istft()
Source code in wandas/frames/spectrogram.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
Processing Module¶
The processing module provides various processing functions for audio data.
wandas.processing
¶
Audio time series processing operations.
This module provides audio processing operations for time series data.
Attributes¶
__all__ = ['AudioOperation', '_OPERATION_REGISTRY', 'create_operation', 'get_operation', 'register_operation', 'AWeighting', 'HighPassFilter', 'LowPassFilter', 'CSD', 'Coherence', 'FFT', 'IFFT', 'ISTFT', 'NOctSpectrum', 'NOctSynthesis', 'STFT', 'TransferFunction', 'Welch', 'ReSampling', 'RmsTrend', 'Trim', 'AddWithSNR', 'HpssHarmonic', 'HpssPercussive', 'ABS', 'ChannelDifference', 'Mean', 'Power', 'Sum']
module-attribute
¶
Classes¶
AudioOperation
¶
Bases: Generic[InputArrayType, OutputArrayType]
Abstract base class for audio processing operations.
Source code in wandas/processing/base.py
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 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 | |
Attributes¶
name
class-attribute
¶
sampling_rate = sampling_rate
instance-attribute
¶
params = params
instance-attribute
¶
Functions¶
__init__(sampling_rate, **params)
¶
Initialize AudioOperation.
Parameters¶
sampling_rate : float Sampling rate (Hz) **params : Any Operation-specific parameters
Source code in wandas/processing/base.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
validate_params()
¶
Validate parameters (raises exception if invalid)
Source code in wandas/processing/base.py
50 51 52 | |
process_array(x)
¶
Processing function wrapped with @dask.delayed
Source code in wandas/processing/base.py
63 64 65 66 67 68 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation (implemented by subclasses)
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/base.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
process(data)
¶
Execute operation and return result data shape is (channels, samples)
Source code in wandas/processing/base.py
86 87 88 89 90 91 92 93 94 95 96 | |
AddWithSNR
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Addition operation considering SNR
Source code in wandas/processing/effects.py
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 | |
Attributes¶
name = 'add_with_snr'
class-attribute
instance-attribute
¶
other = other
instance-attribute
¶
snr = snr
instance-attribute
¶
Functions¶
__init__(sampling_rate, other, snr=1.0)
¶
Initialize addition operation considering SNR
Parameters¶
sampling_rate : float Sampling rate (Hz) other : DaArray Noise signal to add (channel-frame format) snr : float Signal-to-noise ratio (dB)
Source code in wandas/processing/effects.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape (same as input)
Source code in wandas/processing/effects.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
HpssHarmonic
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
HPSS Harmonic operation
Source code in wandas/processing/effects.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 | |
Attributes¶
name = 'hpss_harmonic'
class-attribute
instance-attribute
¶
kwargs = kwargs
instance-attribute
¶
Functions¶
__init__(sampling_rate, **kwargs)
¶
Initialize HPSS Harmonic
Parameters¶
sampling_rate : float Sampling rate (Hz)
Source code in wandas/processing/effects.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
calculate_output_shape(input_shape)
¶
Source code in wandas/processing/effects.py
35 36 | |
HpssPercussive
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
HPSS Percussive operation
Source code in wandas/processing/effects.py
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 | |
Attributes¶
name = 'hpss_percussive'
class-attribute
instance-attribute
¶
kwargs = kwargs
instance-attribute
¶
Functions¶
__init__(sampling_rate, **kwargs)
¶
Initialize HPSS Percussive
Parameters¶
sampling_rate : float Sampling rate (Hz)
Source code in wandas/processing/effects.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
calculate_output_shape(input_shape)
¶
Source code in wandas/processing/effects.py
69 70 | |
AWeighting
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
A-weighting filter operation
Source code in wandas/processing/filters.py
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 | |
Attributes¶
name = 'a_weighting'
class-attribute
instance-attribute
¶
Functions¶
__init__(sampling_rate)
¶
Initialize A-weighting filter
Parameters¶
sampling_rate : float Sampling rate (Hz)
Source code in wandas/processing/filters.py
194 195 196 197 198 199 200 201 202 203 | |
calculate_output_shape(input_shape)
¶
Source code in wandas/processing/filters.py
205 206 | |
HighPassFilter
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
High-pass filter operation
Source code in wandas/processing/filters.py
13 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 53 54 55 56 57 58 59 | |
Attributes¶
name = 'highpass_filter'
class-attribute
instance-attribute
¶
cutoff = cutoff
instance-attribute
¶
order = order
instance-attribute
¶
Functions¶
__init__(sampling_rate, cutoff, order=4)
¶
Initialize high-pass filter
Parameters¶
sampling_rate : float Sampling rate (Hz) cutoff : float Cutoff frequency (Hz) order : int, optional Filter order, default is 4
Source code in wandas/processing/filters.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
validate_params()
¶
Validate parameters
Source code in wandas/processing/filters.py
35 36 37 38 39 | |
calculate_output_shape(input_shape)
¶
Source code in wandas/processing/filters.py
51 52 | |
LowPassFilter
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Low-pass filter operation
Source code in wandas/processing/filters.py
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 | |
Attributes¶
name = 'lowpass_filter'
class-attribute
instance-attribute
¶
a
instance-attribute
¶
b
instance-attribute
¶
cutoff = cutoff
instance-attribute
¶
order = order
instance-attribute
¶
Functions¶
__init__(sampling_rate, cutoff, order=4)
¶
Initialize low-pass filter
Parameters¶
sampling_rate : float Sampling rate (Hz) cutoff : float Cutoff frequency (Hz) order : int, optional Filter order, default is 4
Source code in wandas/processing/filters.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
validate_params()
¶
Validate parameters
Source code in wandas/processing/filters.py
86 87 88 89 90 91 | |
calculate_output_shape(input_shape)
¶
Source code in wandas/processing/filters.py
102 103 | |
CSD
¶
Bases: AudioOperation[NDArrayReal, NDArrayComplex]
Cross-spectral density estimation operation
Source code in wandas/processing/spectral.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
Attributes¶
name = 'csd'
class-attribute
instance-attribute
¶
n_fft = n_fft
instance-attribute
¶
win_length = win_length if win_length is not None else n_fft
instance-attribute
¶
hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶
window = window
instance-attribute
¶
detrend = detrend
instance-attribute
¶
scaling = scaling
instance-attribute
¶
average = average
instance-attribute
¶
Functions¶
__init__(sampling_rate, n_fft, hop_length, win_length, window, detrend, scaling, average)
¶
Initialize cross-spectral density estimation operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int FFT size hop_length : int Hop length win_length : int Window length window : str Window function detrend : str Type of detrend scaling : str Type of scaling average : str Method of averaging
Source code in wandas/processing/spectral.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels * channels, freqs)
Source code in wandas/processing/spectral.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
FFT
¶
Bases: AudioOperation[NDArrayReal, NDArrayComplex]
FFT (Fast Fourier Transform) operation
Source code in wandas/processing/spectral.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
Attributes¶
name = 'fft'
class-attribute
instance-attribute
¶
n_fft = n_fft
instance-attribute
¶
window = window
instance-attribute
¶
Functions¶
__init__(sampling_rate, n_fft=None, window='hann')
¶
Initialize FFT operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int, optional FFT size, default is None (determined by input size) window : str, optional Window function type, default is 'hann'
Source code in wandas/processing/spectral.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
calculate_output_shape(input_shape)
¶
操作後の出力データの形状を計算します
Parameters¶
input_shape : tuple 入力データの形状 (channels, samples)
Returns¶
tuple 出力データの形状 (channels, freqs)
Source code in wandas/processing/spectral.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
IFFT
¶
Bases: AudioOperation[NDArrayComplex, NDArrayReal]
IFFT (Inverse Fast Fourier Transform) operation
Source code in wandas/processing/spectral.py
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 | |
Attributes¶
name = 'ifft'
class-attribute
instance-attribute
¶
n_fft = n_fft
instance-attribute
¶
window = window
instance-attribute
¶
Functions¶
__init__(sampling_rate, n_fft=None, window='hann')
¶
Initialize IFFT operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : Optional[int], optional IFFT size, default is None (determined based on input size) window : str, optional Window function type, default is 'hann'
Source code in wandas/processing/spectral.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, freqs)
Returns¶
tuple Output data shape (channels, samples)
Source code in wandas/processing/spectral.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
ISTFT
¶
Bases: AudioOperation[NDArrayComplex, NDArrayReal]
Inverse Short-Time Fourier Transform operation
Source code in wandas/processing/spectral.py
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 | |
Attributes¶
name = 'istft'
class-attribute
instance-attribute
¶
n_fft = n_fft
instance-attribute
¶
win_length = win_length if win_length is not None else n_fft
instance-attribute
¶
hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶
window = window
instance-attribute
¶
length = length
instance-attribute
¶
SFT = ShortTimeFFT(win=get_window(window, self.win_length), hop=self.hop_length, fs=sampling_rate, mfft=self.n_fft, scale_to='magnitude')
instance-attribute
¶
Functions¶
__init__(sampling_rate, n_fft=2048, hop_length=None, win_length=None, window='hann', length=None)
¶
Source code in wandas/processing/spectral.py
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 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, freqs, time_frames)
Returns¶
tuple Output data shape (channels, samples)
Source code in wandas/processing/spectral.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
STFT
¶
Bases: AudioOperation[NDArrayReal, NDArrayComplex]
Short-Time Fourier Transform operation
Source code in wandas/processing/spectral.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 | |
Attributes¶
name = 'stft'
class-attribute
instance-attribute
¶
n_fft = n_fft
instance-attribute
¶
win_length = win_length if win_length is not None else n_fft
instance-attribute
¶
hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶
noverlap = self.win_length - self.hop_length if hop_length is not None else None
instance-attribute
¶
window = window
instance-attribute
¶
SFT = ShortTimeFFT(win=get_window(window, self.win_length), hop=self.hop_length, fs=sampling_rate, mfft=self.n_fft, scale_to='magnitude')
instance-attribute
¶
Functions¶
__init__(sampling_rate, n_fft=2048, hop_length=None, win_length=None, window='hann')
¶
Source code in wandas/processing/spectral.py
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 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/spectral.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
Coherence
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Coherence estimation operation
Source code in wandas/processing/spectral.py
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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 | |
Attributes¶
name = 'coherence'
class-attribute
instance-attribute
¶
n_fft = n_fft
instance-attribute
¶
win_length = win_length if win_length is not None else n_fft
instance-attribute
¶
hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶
window = window
instance-attribute
¶
detrend = detrend
instance-attribute
¶
Functions¶
__init__(sampling_rate, n_fft, hop_length, win_length, window, detrend)
¶
Initialize coherence estimation operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int FFT size hop_length : int Hop length win_length : int Window length window : str Window function detrend : str Type of detrend
Source code in wandas/processing/spectral.py
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 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels * channels, freqs)
Source code in wandas/processing/spectral.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | |
NOctSpectrum
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
N-octave spectrum operation
Source code in wandas/processing/spectral.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 | |
Attributes¶
name = 'noct_spectrum'
class-attribute
instance-attribute
¶
fmin = fmin
instance-attribute
¶
fmax = fmax
instance-attribute
¶
n = n
instance-attribute
¶
G = G
instance-attribute
¶
fr = fr
instance-attribute
¶
Functions¶
__init__(sampling_rate, fmin, fmax, n=3, G=10, fr=1000)
¶
Initialize N-octave spectrum
Parameters¶
sampling_rate : float Sampling rate (Hz) fmin : float Minimum frequency (Hz) fmax : float Maximum frequency (Hz) n : int, optional Number of octave divisions, default is 3 G : int, optional Reference level, default is 10 fr : int, optional Reference frequency, default is 1000
Source code in wandas/processing/spectral.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/spectral.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
NOctSynthesis
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Octave synthesis operation
Source code in wandas/processing/spectral.py
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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
Attributes¶
name = 'noct_synthesis'
class-attribute
instance-attribute
¶
fmin = fmin
instance-attribute
¶
fmax = fmax
instance-attribute
¶
n = n
instance-attribute
¶
G = G
instance-attribute
¶
fr = fr
instance-attribute
¶
Functions¶
__init__(sampling_rate, fmin, fmax, n=3, G=10, fr=1000)
¶
Initialize octave synthesis
Parameters¶
sampling_rate : float Sampling rate (Hz) fmin : float Minimum frequency (Hz) fmax : float Maximum frequency (Hz) n : int, optional Number of octave divisions, default is 3 G : int, optional Reference level, default is 10 fr : int, optional Reference frequency, default is 1000
Source code in wandas/processing/spectral.py
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 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/spectral.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
TransferFunction
¶
Bases: AudioOperation[NDArrayReal, NDArrayComplex]
Transfer function estimation operation
Source code in wandas/processing/spectral.py
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 | |
Attributes¶
name = 'transfer_function'
class-attribute
instance-attribute
¶
n_fft = n_fft
instance-attribute
¶
win_length = win_length if win_length is not None else n_fft
instance-attribute
¶
hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶
window = window
instance-attribute
¶
detrend = detrend
instance-attribute
¶
scaling = scaling
instance-attribute
¶
average = average
instance-attribute
¶
Functions¶
__init__(sampling_rate, n_fft, hop_length, win_length, window, detrend, scaling='spectrum', average='mean')
¶
Initialize transfer function estimation operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int FFT size hop_length : int Hop length win_length : int Window length window : str Window function detrend : str Type of detrend scaling : str Type of scaling average : str Method of averaging
Source code in wandas/processing/spectral.py
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 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels * channels, freqs)
Source code in wandas/processing/spectral.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
Welch
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Welch
Source code in wandas/processing/spectral.py
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 391 | |
Attributes¶
name = 'welch'
class-attribute
instance-attribute
¶
n_fft = n_fft
instance-attribute
¶
window = window
instance-attribute
¶
hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶
win_length = win_length if win_length is not None else n_fft
instance-attribute
¶
average = average
instance-attribute
¶
detrend = detrend
instance-attribute
¶
noverlap = self.win_length - self.hop_length if hop_length is not None else None
instance-attribute
¶
Functions¶
__init__(sampling_rate, n_fft=2048, hop_length=None, win_length=None, window='hann', average='mean', detrend='constant')
¶
Initialize Welch operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int, optional FFT size, default is 2048 window : str, optional Window function type, default is 'hann'
Source code in wandas/processing/spectral.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 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels, freqs)
Source code in wandas/processing/spectral.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
ABS
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Absolute value operation
Source code in wandas/processing/stats.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
Attributes¶
name = 'abs'
class-attribute
instance-attribute
¶
Functions¶
__init__(sampling_rate)
¶
Initialize absolute value operation
Parameters¶
sampling_rate : float Sampling rate (Hz)
Source code in wandas/processing/stats.py
17 18 19 20 21 22 23 24 25 26 | |
process(data)
¶
Source code in wandas/processing/stats.py
28 29 30 | |
ChannelDifference
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Channel difference calculation operation
Source code in wandas/processing/stats.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
Attributes¶
name = 'channel_difference'
class-attribute
instance-attribute
¶
other_channel = other_channel
instance-attribute
¶
Functions¶
__init__(sampling_rate, other_channel=0)
¶
Initialize channel difference calculation
Parameters¶
sampling_rate : float Sampling rate (Hz) other_channel : int Channel to calculate difference with, default is 0
Source code in wandas/processing/stats.py
83 84 85 86 87 88 89 90 91 92 93 94 95 | |
process(data)
¶
Source code in wandas/processing/stats.py
97 98 99 100 | |
Mean
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Mean calculation
Source code in wandas/processing/stats.py
67 68 69 70 71 72 73 74 | |
Power
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Power operation
Source code in wandas/processing/stats.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
Attributes¶
name = 'power'
class-attribute
instance-attribute
¶
exp = exponent
instance-attribute
¶
Functions¶
__init__(sampling_rate, exponent)
¶
Initialize power operation
Parameters¶
sampling_rate : float Sampling rate (Hz) exponent : float Power exponent
Source code in wandas/processing/stats.py
38 39 40 41 42 43 44 45 46 47 48 49 50 | |
process(data)
¶
Source code in wandas/processing/stats.py
52 53 54 | |
Sum
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Sum calculation
Source code in wandas/processing/stats.py
57 58 59 60 61 62 63 64 | |
ReSampling
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Resampling operation
Source code in wandas/processing/temporal.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 53 54 55 56 57 58 59 | |
Attributes¶
name = 'resampling'
class-attribute
instance-attribute
¶
target_sr = target_sr
instance-attribute
¶
Functions¶
__init__(sampling_rate, target_sr)
¶
Initialize resampling operation
Parameters¶
sampling_rate : float Sampling rate (Hz) target_sampling_rate : float Target sampling rate (Hz)
Source code in wandas/processing/temporal.py
19 20 21 22 23 24 25 26 27 28 29 30 31 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/temporal.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
RmsTrend
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
RMS calculation
Source code in wandas/processing/temporal.py
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 | |
Attributes¶
name = 'rms_trend'
class-attribute
instance-attribute
¶
frame_length = frame_length
instance-attribute
¶
hop_length = hop_length
instance-attribute
¶
Aw = Aw
instance-attribute
¶
dB = dB
instance-attribute
¶
ref = np.array(ref if isinstance(ref, list) else [ref])
instance-attribute
¶
Functions¶
__init__(sampling_rate, frame_length=2048, hop_length=512, ref=1.0, dB=False, Aw=False)
¶
Initialize RMS calculation
Parameters¶
sampling_rate : float Sampling rate (Hz) frame_length : int Frame length, default is 2048 hop_length : int Hop length, default is 512 ref : Union[list[float], float] Reference value(s) for dB calculation dB : bool Whether to convert to decibels Aw : bool Whether to apply A-weighting before RMS calculation
Source code in wandas/processing/temporal.py
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 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels, frames)
Source code in wandas/processing/temporal.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
Trim
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Trimming operation
Source code in wandas/processing/temporal.py
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 | |
Attributes¶
name = 'trim'
class-attribute
instance-attribute
¶
start = start
instance-attribute
¶
end = end
instance-attribute
¶
start_sample = int(start * sampling_rate)
instance-attribute
¶
end_sample = int(end * sampling_rate)
instance-attribute
¶
Functions¶
__init__(sampling_rate, start, end)
¶
Initialize trimming operation
Parameters¶
sampling_rate : float Sampling rate (Hz) start : float Start time for trimming (seconds) end : float End time for trimming (seconds)
Source code in wandas/processing/temporal.py
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 | |
calculate_output_shape(input_shape)
¶
Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/temporal.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
Functions¶
create_operation(name, sampling_rate, **params)
¶
Create operation instance from name and parameters
Source code in wandas/processing/base.py
121 122 123 124 125 126 | |
get_operation(name)
¶
Get operation class by name
Source code in wandas/processing/base.py
114 115 116 117 118 | |
register_operation(operation_class)
¶
Register a new operation type
Source code in wandas/processing/base.py
103 104 105 106 107 108 109 110 111 | |
Modules¶
base
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
InputArrayType = TypeVar('InputArrayType', NDArrayReal, NDArrayComplex)
module-attribute
¶
OutputArrayType = TypeVar('OutputArrayType', NDArrayReal, NDArrayComplex)
module-attribute
¶
Classes¶
AudioOperation
¶
Bases: Generic[InputArrayType, OutputArrayType]
Abstract base class for audio processing operations.
Source code in wandas/processing/base.py
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 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 | |
name
class-attribute
¶ sampling_rate = sampling_rate
instance-attribute
¶ params = params
instance-attribute
¶ __init__(sampling_rate, **params)
¶Initialize AudioOperation.
Parameters¶
sampling_rate : float Sampling rate (Hz) **params : Any Operation-specific parameters
Source code in wandas/processing/base.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
validate_params()
¶Validate parameters (raises exception if invalid)
Source code in wandas/processing/base.py
50 51 52 | |
process_array(x)
¶Processing function wrapped with @dask.delayed
Source code in wandas/processing/base.py
63 64 65 66 67 68 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation (implemented by subclasses)
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/base.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
process(data)
¶Execute operation and return result data shape is (channels, samples)
Source code in wandas/processing/base.py
86 87 88 89 90 91 92 93 94 95 96 | |
Functions¶
register_operation(operation_class)
¶
Register a new operation type
Source code in wandas/processing/base.py
103 104 105 106 107 108 109 110 111 | |
get_operation(name)
¶
Get operation class by name
Source code in wandas/processing/base.py
114 115 116 117 118 | |
create_operation(name, sampling_rate, **params)
¶
Create operation instance from name and parameters
Source code in wandas/processing/base.py
121 122 123 124 125 126 | |
effects
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
HpssHarmonic
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
HPSS Harmonic operation
Source code in wandas/processing/effects.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 | |
name = 'hpss_harmonic'
class-attribute
instance-attribute
¶ kwargs = kwargs
instance-attribute
¶ __init__(sampling_rate, **kwargs)
¶Initialize HPSS Harmonic
Parameters¶
sampling_rate : float Sampling rate (Hz)
Source code in wandas/processing/effects.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
calculate_output_shape(input_shape)
¶Source code in wandas/processing/effects.py
35 36 | |
HpssPercussive
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
HPSS Percussive operation
Source code in wandas/processing/effects.py
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 | |
name = 'hpss_percussive'
class-attribute
instance-attribute
¶ kwargs = kwargs
instance-attribute
¶ __init__(sampling_rate, **kwargs)
¶Initialize HPSS Percussive
Parameters¶
sampling_rate : float Sampling rate (Hz)
Source code in wandas/processing/effects.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
calculate_output_shape(input_shape)
¶Source code in wandas/processing/effects.py
69 70 | |
AddWithSNR
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Addition operation considering SNR
Source code in wandas/processing/effects.py
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 | |
name = 'add_with_snr'
class-attribute
instance-attribute
¶ other = other
instance-attribute
¶ snr = snr
instance-attribute
¶ __init__(sampling_rate, other, snr=1.0)
¶Initialize addition operation considering SNR
Parameters¶
sampling_rate : float Sampling rate (Hz) other : DaArray Noise signal to add (channel-frame format) snr : float Signal-to-noise ratio (dB)
Source code in wandas/processing/effects.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape (same as input)
Source code in wandas/processing/effects.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
Functions¶
Modules¶
filters
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
HighPassFilter
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
High-pass filter operation
Source code in wandas/processing/filters.py
13 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 53 54 55 56 57 58 59 | |
name = 'highpass_filter'
class-attribute
instance-attribute
¶ cutoff = cutoff
instance-attribute
¶ order = order
instance-attribute
¶ __init__(sampling_rate, cutoff, order=4)
¶Initialize high-pass filter
Parameters¶
sampling_rate : float Sampling rate (Hz) cutoff : float Cutoff frequency (Hz) order : int, optional Filter order, default is 4
Source code in wandas/processing/filters.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
validate_params()
¶Validate parameters
Source code in wandas/processing/filters.py
35 36 37 38 39 | |
calculate_output_shape(input_shape)
¶Source code in wandas/processing/filters.py
51 52 | |
LowPassFilter
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Low-pass filter operation
Source code in wandas/processing/filters.py
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 | |
name = 'lowpass_filter'
class-attribute
instance-attribute
¶ a
instance-attribute
¶ b
instance-attribute
¶ cutoff = cutoff
instance-attribute
¶ order = order
instance-attribute
¶ __init__(sampling_rate, cutoff, order=4)
¶Initialize low-pass filter
Parameters¶
sampling_rate : float Sampling rate (Hz) cutoff : float Cutoff frequency (Hz) order : int, optional Filter order, default is 4
Source code in wandas/processing/filters.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
validate_params()
¶Validate parameters
Source code in wandas/processing/filters.py
86 87 88 89 90 91 | |
calculate_output_shape(input_shape)
¶Source code in wandas/processing/filters.py
102 103 | |
BandPassFilter
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Band-pass filter operation
Source code in wandas/processing/filters.py
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 | |
name = 'bandpass_filter'
class-attribute
instance-attribute
¶ a
instance-attribute
¶ b
instance-attribute
¶ low_cutoff = low_cutoff
instance-attribute
¶ high_cutoff = high_cutoff
instance-attribute
¶ order = order
instance-attribute
¶ __init__(sampling_rate, low_cutoff, high_cutoff, order=4)
¶Initialize band-pass filter
Parameters¶
sampling_rate : float Sampling rate (Hz) low_cutoff : float Lower cutoff frequency (Hz) high_cutoff : float Higher cutoff frequency (Hz) order : int, optional Filter order, default is 4
Source code in wandas/processing/filters.py
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 | |
validate_params()
¶Validate parameters
Source code in wandas/processing/filters.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
calculate_output_shape(input_shape)
¶Source code in wandas/processing/filters.py
178 179 | |
AWeighting
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
A-weighting filter operation
Source code in wandas/processing/filters.py
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 | |
name = 'a_weighting'
class-attribute
instance-attribute
¶ __init__(sampling_rate)
¶Initialize A-weighting filter
Parameters¶
sampling_rate : float Sampling rate (Hz)
Source code in wandas/processing/filters.py
194 195 196 197 198 199 200 201 202 203 | |
calculate_output_shape(input_shape)
¶Source code in wandas/processing/filters.py
205 206 | |
Functions¶
spectral
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
FFT
¶
Bases: AudioOperation[NDArrayReal, NDArrayComplex]
FFT (Fast Fourier Transform) operation
Source code in wandas/processing/spectral.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
name = 'fft'
class-attribute
instance-attribute
¶ n_fft = n_fft
instance-attribute
¶ window = window
instance-attribute
¶ __init__(sampling_rate, n_fft=None, window='hann')
¶Initialize FFT operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int, optional FFT size, default is None (determined by input size) window : str, optional Window function type, default is 'hann'
Source code in wandas/processing/spectral.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
calculate_output_shape(input_shape)
¶操作後の出力データの形状を計算します
Parameters¶
input_shape : tuple 入力データの形状 (channels, samples)
Returns¶
tuple 出力データの形状 (channels, freqs)
Source code in wandas/processing/spectral.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
IFFT
¶
Bases: AudioOperation[NDArrayComplex, NDArrayReal]
IFFT (Inverse Fast Fourier Transform) operation
Source code in wandas/processing/spectral.py
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 | |
name = 'ifft'
class-attribute
instance-attribute
¶ n_fft = n_fft
instance-attribute
¶ window = window
instance-attribute
¶ __init__(sampling_rate, n_fft=None, window='hann')
¶Initialize IFFT operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : Optional[int], optional IFFT size, default is None (determined based on input size) window : str, optional Window function type, default is 'hann'
Source code in wandas/processing/spectral.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, freqs)
Returns¶
tuple Output data shape (channels, samples)
Source code in wandas/processing/spectral.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
STFT
¶
Bases: AudioOperation[NDArrayReal, NDArrayComplex]
Short-Time Fourier Transform operation
Source code in wandas/processing/spectral.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 | |
name = 'stft'
class-attribute
instance-attribute
¶ n_fft = n_fft
instance-attribute
¶ win_length = win_length if win_length is not None else n_fft
instance-attribute
¶ hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶ noverlap = self.win_length - self.hop_length if hop_length is not None else None
instance-attribute
¶ window = window
instance-attribute
¶ SFT = ShortTimeFFT(win=get_window(window, self.win_length), hop=self.hop_length, fs=sampling_rate, mfft=self.n_fft, scale_to='magnitude')
instance-attribute
¶ __init__(sampling_rate, n_fft=2048, hop_length=None, win_length=None, window='hann')
¶Source code in wandas/processing/spectral.py
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 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/spectral.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
ISTFT
¶
Bases: AudioOperation[NDArrayComplex, NDArrayReal]
Inverse Short-Time Fourier Transform operation
Source code in wandas/processing/spectral.py
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 | |
name = 'istft'
class-attribute
instance-attribute
¶ n_fft = n_fft
instance-attribute
¶ win_length = win_length if win_length is not None else n_fft
instance-attribute
¶ hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶ window = window
instance-attribute
¶ length = length
instance-attribute
¶ SFT = ShortTimeFFT(win=get_window(window, self.win_length), hop=self.hop_length, fs=sampling_rate, mfft=self.n_fft, scale_to='magnitude')
instance-attribute
¶ __init__(sampling_rate, n_fft=2048, hop_length=None, win_length=None, window='hann', length=None)
¶Source code in wandas/processing/spectral.py
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 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, freqs, time_frames)
Returns¶
tuple Output data shape (channels, samples)
Source code in wandas/processing/spectral.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
Welch
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Welch
Source code in wandas/processing/spectral.py
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 391 | |
name = 'welch'
class-attribute
instance-attribute
¶ n_fft = n_fft
instance-attribute
¶ win_length = win_length if win_length is not None else n_fft
instance-attribute
¶ hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶ noverlap = self.win_length - self.hop_length if hop_length is not None else None
instance-attribute
¶ window = window
instance-attribute
¶ average = average
instance-attribute
¶ detrend = detrend
instance-attribute
¶ __init__(sampling_rate, n_fft=2048, hop_length=None, win_length=None, window='hann', average='mean', detrend='constant')
¶Initialize Welch operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int, optional FFT size, default is 2048 window : str, optional Window function type, default is 'hann'
Source code in wandas/processing/spectral.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 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels, freqs)
Source code in wandas/processing/spectral.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
NOctSpectrum
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
N-octave spectrum operation
Source code in wandas/processing/spectral.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 | |
name = 'noct_spectrum'
class-attribute
instance-attribute
¶ fmin = fmin
instance-attribute
¶ fmax = fmax
instance-attribute
¶ n = n
instance-attribute
¶ G = G
instance-attribute
¶ fr = fr
instance-attribute
¶ __init__(sampling_rate, fmin, fmax, n=3, G=10, fr=1000)
¶Initialize N-octave spectrum
Parameters¶
sampling_rate : float Sampling rate (Hz) fmin : float Minimum frequency (Hz) fmax : float Maximum frequency (Hz) n : int, optional Number of octave divisions, default is 3 G : int, optional Reference level, default is 10 fr : int, optional Reference frequency, default is 1000
Source code in wandas/processing/spectral.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/spectral.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
NOctSynthesis
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Octave synthesis operation
Source code in wandas/processing/spectral.py
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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
name = 'noct_synthesis'
class-attribute
instance-attribute
¶ fmin = fmin
instance-attribute
¶ fmax = fmax
instance-attribute
¶ n = n
instance-attribute
¶ G = G
instance-attribute
¶ fr = fr
instance-attribute
¶ __init__(sampling_rate, fmin, fmax, n=3, G=10, fr=1000)
¶Initialize octave synthesis
Parameters¶
sampling_rate : float Sampling rate (Hz) fmin : float Minimum frequency (Hz) fmax : float Maximum frequency (Hz) n : int, optional Number of octave divisions, default is 3 G : int, optional Reference level, default is 10 fr : int, optional Reference frequency, default is 1000
Source code in wandas/processing/spectral.py
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 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/spectral.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
Coherence
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Coherence estimation operation
Source code in wandas/processing/spectral.py
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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 | |
name = 'coherence'
class-attribute
instance-attribute
¶ n_fft = n_fft
instance-attribute
¶ win_length = win_length if win_length is not None else n_fft
instance-attribute
¶ hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶ window = window
instance-attribute
¶ detrend = detrend
instance-attribute
¶ __init__(sampling_rate, n_fft, hop_length, win_length, window, detrend)
¶Initialize coherence estimation operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int FFT size hop_length : int Hop length win_length : int Window length window : str Window function detrend : str Type of detrend
Source code in wandas/processing/spectral.py
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 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels * channels, freqs)
Source code in wandas/processing/spectral.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | |
CSD
¶
Bases: AudioOperation[NDArrayReal, NDArrayComplex]
Cross-spectral density estimation operation
Source code in wandas/processing/spectral.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
name = 'csd'
class-attribute
instance-attribute
¶ n_fft = n_fft
instance-attribute
¶ win_length = win_length if win_length is not None else n_fft
instance-attribute
¶ hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶ window = window
instance-attribute
¶ detrend = detrend
instance-attribute
¶ scaling = scaling
instance-attribute
¶ average = average
instance-attribute
¶ __init__(sampling_rate, n_fft, hop_length, win_length, window, detrend, scaling, average)
¶Initialize cross-spectral density estimation operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int FFT size hop_length : int Hop length win_length : int Window length window : str Window function detrend : str Type of detrend scaling : str Type of scaling average : str Method of averaging
Source code in wandas/processing/spectral.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels * channels, freqs)
Source code in wandas/processing/spectral.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
TransferFunction
¶
Bases: AudioOperation[NDArrayReal, NDArrayComplex]
Transfer function estimation operation
Source code in wandas/processing/spectral.py
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 | |
name = 'transfer_function'
class-attribute
instance-attribute
¶ n_fft = n_fft
instance-attribute
¶ win_length = win_length if win_length is not None else n_fft
instance-attribute
¶ hop_length = hop_length if hop_length is not None else self.win_length // 4
instance-attribute
¶ window = window
instance-attribute
¶ detrend = detrend
instance-attribute
¶ scaling = scaling
instance-attribute
¶ average = average
instance-attribute
¶ __init__(sampling_rate, n_fft, hop_length, win_length, window, detrend, scaling='spectrum', average='mean')
¶Initialize transfer function estimation operation
Parameters¶
sampling_rate : float Sampling rate (Hz) n_fft : int FFT size hop_length : int Hop length win_length : int Window length window : str Window function detrend : str Type of detrend scaling : str Type of scaling average : str Method of averaging
Source code in wandas/processing/spectral.py
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 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels * channels, freqs)
Source code in wandas/processing/spectral.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
Functions¶
stats
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
ABS
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Absolute value operation
Source code in wandas/processing/stats.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
name = 'abs'
class-attribute
instance-attribute
¶ __init__(sampling_rate)
¶Initialize absolute value operation
Parameters¶
sampling_rate : float Sampling rate (Hz)
Source code in wandas/processing/stats.py
17 18 19 20 21 22 23 24 25 26 | |
process(data)
¶Source code in wandas/processing/stats.py
28 29 30 | |
Power
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Power operation
Source code in wandas/processing/stats.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
name = 'power'
class-attribute
instance-attribute
¶ exp = exponent
instance-attribute
¶ __init__(sampling_rate, exponent)
¶Initialize power operation
Parameters¶
sampling_rate : float Sampling rate (Hz) exponent : float Power exponent
Source code in wandas/processing/stats.py
38 39 40 41 42 43 44 45 46 47 48 49 50 | |
process(data)
¶Source code in wandas/processing/stats.py
52 53 54 | |
Sum
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Sum calculation
Source code in wandas/processing/stats.py
57 58 59 60 61 62 63 64 | |
Mean
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Mean calculation
Source code in wandas/processing/stats.py
67 68 69 70 71 72 73 74 | |
ChannelDifference
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Channel difference calculation operation
Source code in wandas/processing/stats.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
name = 'channel_difference'
class-attribute
instance-attribute
¶ other_channel = other_channel
instance-attribute
¶ __init__(sampling_rate, other_channel=0)
¶Initialize channel difference calculation
Parameters¶
sampling_rate : float Sampling rate (Hz) other_channel : int Channel to calculate difference with, default is 0
Source code in wandas/processing/stats.py
83 84 85 86 87 88 89 90 91 92 93 94 95 | |
process(data)
¶Source code in wandas/processing/stats.py
97 98 99 100 | |
Functions¶
temporal
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
ReSampling
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Resampling operation
Source code in wandas/processing/temporal.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 53 54 55 56 57 58 59 | |
name = 'resampling'
class-attribute
instance-attribute
¶ target_sr = target_sr
instance-attribute
¶ __init__(sampling_rate, target_sr)
¶Initialize resampling operation
Parameters¶
sampling_rate : float Sampling rate (Hz) target_sampling_rate : float Target sampling rate (Hz)
Source code in wandas/processing/temporal.py
19 20 21 22 23 24 25 26 27 28 29 30 31 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/temporal.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
Trim
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
Trimming operation
Source code in wandas/processing/temporal.py
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 | |
name = 'trim'
class-attribute
instance-attribute
¶ start = start
instance-attribute
¶ end = end
instance-attribute
¶ start_sample = int(start * sampling_rate)
instance-attribute
¶ end_sample = int(end * sampling_rate)
instance-attribute
¶ __init__(sampling_rate, start, end)
¶Initialize trimming operation
Parameters¶
sampling_rate : float Sampling rate (Hz) start : float Start time for trimming (seconds) end : float End time for trimming (seconds)
Source code in wandas/processing/temporal.py
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 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/temporal.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
FixLength
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
信号の長さを指定された長さに調整する操作
Source code in wandas/processing/temporal.py
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 | |
name = 'fix_length'
class-attribute
instance-attribute
¶ target_length = length
instance-attribute
¶ __init__(sampling_rate, length=None, duration=None)
¶Initialize fix length operation
Parameters¶
sampling_rate : float Sampling rate (Hz) length : Optional[int] Target length for fixing duration : Optional[float] Target length for fixing
Source code in wandas/processing/temporal.py
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 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape
Returns¶
tuple Output data shape
Source code in wandas/processing/temporal.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
RmsTrend
¶
Bases: AudioOperation[NDArrayReal, NDArrayReal]
RMS calculation
Source code in wandas/processing/temporal.py
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 | |
name = 'rms_trend'
class-attribute
instance-attribute
¶ frame_length = frame_length
instance-attribute
¶ hop_length = hop_length
instance-attribute
¶ dB = dB
instance-attribute
¶ Aw = Aw
instance-attribute
¶ ref = np.array(ref if isinstance(ref, list) else [ref])
instance-attribute
¶ __init__(sampling_rate, frame_length=2048, hop_length=512, ref=1.0, dB=False, Aw=False)
¶Initialize RMS calculation
Parameters¶
sampling_rate : float Sampling rate (Hz) frame_length : int Frame length, default is 2048 hop_length : int Hop length, default is 512 ref : Union[list[float], float] Reference value(s) for dB calculation dB : bool Whether to convert to decibels Aw : bool Whether to apply A-weighting before RMS calculation
Source code in wandas/processing/temporal.py
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 | |
calculate_output_shape(input_shape)
¶Calculate output data shape after operation
Parameters¶
input_shape : tuple Input data shape (channels, samples)
Returns¶
tuple Output data shape (channels, frames)
Source code in wandas/processing/temporal.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
Functions¶
IO Module¶
The IO module provides file reading and writing functions.
wandas.io
¶
Attributes¶
__all__ = ['read_wav', 'write_wav', 'load', 'save']
module-attribute
¶
Functions¶
read_wav(filename, labels=None)
¶
Read a WAV file and create a ChannelFrame object.
Parameters¶
filename : str Path to the WAV file or URL to the WAV file. labels : list of str, optional Labels for each channel.
Returns¶
ChannelFrame ChannelFrame object containing the audio data.
Source code in wandas/io/wav_io.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
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
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 | |
load(path, *, format='hdf5')
¶
Load a ChannelFrame object from a WDF (Wandas Data File) file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to the WDF file to load. |
required |
format
|
str
|
Format of the file. Currently only "hdf5" is supported. |
'hdf5'
|
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")
Source code in wandas/io/wdf_io.py
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 | |
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
|
Union[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
|
Optional[str]
|
Compression method ('gzip' by default, None for no compression) |
'gzip'
|
overwrite
|
bool
|
Whether to overwrite existing file |
False
|
dtype
|
Optional[Union[str, dtype[Any]]]
|
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
32 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 142 | |
Modules¶
readers
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
FileReader
¶
Bases: ABC
Base class for audio file readers.
Source code in wandas/io/readers.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 | |
supported_extensions = []
class-attribute
instance-attribute
¶ get_file_info(path, **kwargs)
abstractmethod
classmethod
¶Get basic information about the audio file.
Source code in wandas/io/readers.py
20 21 22 23 24 | |
get_data(path, channels, start_idx, frames, **kwargs)
abstractmethod
classmethod
¶Read audio data from the file.
Source code in wandas/io/readers.py
26 27 28 29 30 31 32 33 34 35 36 37 | |
can_read(path)
classmethod
¶Check if this reader can handle the file based on extension.
Source code in wandas/io/readers.py
39 40 41 42 43 | |
SoundFileReader
¶
Bases: FileReader
Audio file reader using SoundFile library.
Source code in wandas/io/readers.py
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 | |
supported_extensions = ['.wav', '.flac', '.ogg', '.aiff', '.aif', '.snd']
class-attribute
instance-attribute
¶ get_file_info(path, **kwargs)
classmethod
¶Get basic information about the audio file.
Source code in wandas/io/readers.py
52 53 54 55 56 57 58 59 60 61 62 63 | |
get_data(path, channels, start_idx, frames, **kwargs)
classmethod
¶Read audio data from the file.
Source code in wandas/io/readers.py
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 | |
CSVFileReader
¶
Bases: FileReader
CSV file reader for time series data.
Source code in wandas/io/readers.py
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 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 | |
supported_extensions = ['.csv']
class-attribute
instance-attribute
¶ get_file_info(path, **kwargs)
classmethod
¶Source code in wandas/io/readers.py
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 | |
get_data(path, channels, start_idx, frames, **kwargs)
classmethod
¶Read data from the CSV file.
Source code in wandas/io/readers.py
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 | |
Functions¶
get_file_reader(path)
¶
Get an appropriate file reader for the given path.
Source code in wandas/io/readers.py
188 189 190 191 192 193 194 195 196 197 198 199 200 | |
register_file_reader(reader_class)
¶
Register a new file reader.
Source code in wandas/io/readers.py
203 204 205 206 207 | |
wav_io
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions¶
read_wav(filename, labels=None)
¶
Read a WAV file and create a ChannelFrame object.
Parameters¶
filename : str Path to the WAV file or URL to the WAV file. labels : list of str, optional Labels for each channel.
Returns¶
ChannelFrame ChannelFrame object containing the audio data.
Source code in wandas/io/wav_io.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
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
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 | |
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¶
da_from_array = da.from_array
module-attribute
¶
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
|
Union[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
|
Optional[str]
|
Compression method ('gzip' by default, None for no compression) |
'gzip'
|
overwrite
|
bool
|
Whether to overwrite existing file |
False
|
dtype
|
Optional[Union[str, dtype[Any]]]
|
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
32 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 142 | |
load(path, *, format='hdf5')
¶
Load a ChannelFrame object from a WDF (Wandas Data File) file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to the WDF file to load. |
required |
format
|
str
|
Format of the file. Currently only "hdf5" is supported. |
'hdf5'
|
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")
Source code in wandas/io/wdf_io.py
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 | |
Utilities Module¶
The utilities module provides auxiliary functions.
wandas.utils
¶
Attributes¶
__all__ = ['filter_kwargs', 'accepted_kwargs']
module-attribute
¶
Functions¶
accepted_kwargs(func)
¶
Get the set of explicit keyword arguments accepted by a function and whether it accepts **kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The function to inspect. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
A tuple containing: |
bool
|
|
tuple[set[str], bool]
|
|
Source code in wandas/utils/introspection.py
13 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 | |
filter_kwargs(func, kwargs, *, strict_mode=False)
¶
Filter keyword arguments to only those accepted by the function.
This function examines the signature of func and returns a dictionary
containing only the key-value pairs from kwargs that are valid keyword
arguments for func.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The function to filter keyword arguments for. |
required |
kwargs
|
Mapping[str, Any]
|
The keyword arguments to filter. |
required |
strict_mode
|
bool
|
If True, only explicitly defined parameters are passed even when the function accepts kwargs. If False (default), all parameters are passed to functions that accept kwargs, but a warning is issued for parameters not explicitly defined. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing only the key-value pairs that are valid for |
Source code in wandas/utils/introspection.py
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 | |
Modules¶
frame_dataset
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
FrameType = Union[ChannelFrame, SpectrogramFrame]
module-attribute
¶
F = TypeVar('F', bound=FrameType)
module-attribute
¶
F_out = TypeVar('F_out', bound=FrameType)
module-attribute
¶
Classes¶
LazyFrame
dataclass
¶
Bases: Generic[F]
A class that encapsulates a frame and its loading state.
Attributes:
| Name | Type | Description |
|---|---|---|
file_path |
Path
|
File path associated with the frame |
frame |
Optional[F]
|
Loaded frame object (None if not loaded) |
is_loaded |
bool
|
Flag indicating if the frame is loaded |
load_attempted |
bool
|
Flag indicating if loading was attempted (for error detection) |
Source code in wandas/utils/frame_dataset.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
file_path
instance-attribute
¶ frame = None
class-attribute
instance-attribute
¶ is_loaded = False
class-attribute
instance-attribute
¶ load_attempted = False
class-attribute
instance-attribute
¶ __init__(file_path, frame=None, is_loaded=False, load_attempted=False)
¶ ensure_loaded(loader)
¶Ensures the frame is loaded, loading it if necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loader
|
Callable[[Path], Optional[F]]
|
Function to load a frame from a file path |
required |
Returns:
| Type | Description |
|---|---|
Optional[F]
|
The loaded frame, or None if loading failed |
Source code in wandas/utils/frame_dataset.py
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 | |
reset()
¶Reset the frame state.
Source code in wandas/utils/frame_dataset.py
63 64 65 66 67 68 69 | |
FrameDataset
¶
Bases: Generic[F], ABC
Abstract base dataset class for processing files in a folder. Includes lazy loading capability to efficiently handle large datasets. Subclasses handle specific frame types (ChannelFrame, SpectrogramFrame, etc.).
Source code in wandas/utils/frame_dataset.py
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 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 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 | |
folder_path = Path(folder_path)
instance-attribute
¶ sampling_rate = sampling_rate
instance-attribute
¶ signal_length = signal_length
instance-attribute
¶ file_extensions = file_extensions or ['.wav']
instance-attribute
¶ __init__(folder_path, sampling_rate=None, signal_length=None, file_extensions=None, lazy_loading=True, recursive=False, source_dataset=None, transform=None)
¶Source code in wandas/utils/frame_dataset.py
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 | |
__len__()
¶Return the number of files in the dataset.
Source code in wandas/utils/frame_dataset.py
220 221 222 | |
__getitem__(index)
¶Get the frame at the specified index.
Source code in wandas/utils/frame_dataset.py
224 225 226 | |
apply(func)
¶apply(
func: Callable[[F], Optional[F_out]],
) -> FrameDataset[F_out]
apply(
func: Callable[[F], Optional[Any]],
) -> FrameDataset[Any]
Apply a function to the entire dataset to create a new dataset.
Source code in wandas/utils/frame_dataset.py
234 235 236 237 238 239 240 241 242 243 244 245 246 | |
save(output_folder, filename_prefix='')
¶Save processed frames to files.
Source code in wandas/utils/frame_dataset.py
248 249 250 | |
sample(n=None, ratio=None, seed=None)
¶Get a sample from the dataset.
Source code in wandas/utils/frame_dataset.py
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 | |
get_metadata()
¶Get metadata for the dataset.
Source code in wandas/utils/frame_dataset.py
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 | |
ChannelFrameDataset
¶
Bases: FrameDataset[ChannelFrame]
Dataset class for handling audio files as ChannelFrames in a folder.
Source code in wandas/utils/frame_dataset.py
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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 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 592 593 594 595 596 | |
__init__(folder_path, sampling_rate=None, signal_length=None, file_extensions=None, lazy_loading=True, recursive=False, source_dataset=None, transform=None)
¶Source code in wandas/utils/frame_dataset.py
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 | |
resample(target_sr)
¶Resample all frames in the dataset.
Source code in wandas/utils/frame_dataset.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
trim(start, end)
¶Trim all frames in the dataset.
Source code in wandas/utils/frame_dataset.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
normalize(**kwargs)
¶Normalize all frames in the dataset.
Source code in wandas/utils/frame_dataset.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
stft(n_fft=2048, hop_length=None, win_length=None, window='hann')
¶Apply STFT to all frames in the dataset.
Source code in wandas/utils/frame_dataset.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
from_folder(folder_path, sampling_rate=None, file_extensions=None, recursive=False, lazy_loading=True)
classmethod
¶Class method to create a ChannelFrameDataset from a folder.
Source code in wandas/utils/frame_dataset.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
SpectrogramFrameDataset
¶
Bases: FrameDataset[SpectrogramFrame]
Dataset class for handling spectrogram data as SpectrogramFrames. Expected to be generated mainly as a result of ChannelFrameDataset.stft().
Source code in wandas/utils/frame_dataset.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
__init__(folder_path, sampling_rate=None, signal_length=None, file_extensions=None, lazy_loading=True, recursive=False, source_dataset=None, transform=None)
¶Source code in wandas/utils/frame_dataset.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
plot(index, **kwargs)
¶Plot the spectrogram at the specified index.
Source code in wandas/utils/frame_dataset.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
generate_sample
¶
Classes¶
Functions¶
generate_sin(freqs=1000, sampling_rate=16000, duration=1.0, label=None)
¶
Generate sample sine wave signals.
Parameters¶
freqs : float or list of float, default=1000 Frequency of the sine wave(s) in Hz. If multiple frequencies are specified, multiple channels will be created. sampling_rate : int, default=16000 Sampling rate in Hz. duration : float, default=1.0 Duration of the signal in seconds. label : str, optional Label for the entire signal.
Returns¶
ChannelFrame ChannelFrame object containing the sine wave(s).
Source code in wandas/utils/generate_sample.py
11 12 13 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 | |
generate_sin_lazy(freqs=1000, sampling_rate=16000, duration=1.0, label=None)
¶
Generate sample sine wave signals using lazy computation.
Parameters¶
freqs : float or list of float, default=1000 Frequency of the sine wave(s) in Hz. If multiple frequencies are specified, multiple channels will be created. sampling_rate : int, default=16000 Sampling rate in Hz. duration : float, default=1.0 Duration of the signal in seconds. label : str, optional Label for the entire signal.
Returns¶
ChannelFrame Lazy ChannelFrame object containing the sine wave(s).
Source code in wandas/utils/generate_sample.py
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 | |
introspection
¶
Utilities for runtime signature introspection.
Attributes¶
__all__ = ['accepted_kwargs', 'filter_kwargs']
module-attribute
¶
Functions¶
accepted_kwargs(func)
¶
Get the set of explicit keyword arguments accepted by a function and whether it accepts **kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The function to inspect. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
A tuple containing: |
bool
|
|
tuple[set[str], bool]
|
|
Source code in wandas/utils/introspection.py
13 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 | |
filter_kwargs(func, kwargs, *, strict_mode=False)
¶
Filter keyword arguments to only those accepted by the function.
This function examines the signature of func and returns a dictionary
containing only the key-value pairs from kwargs that are valid keyword
arguments for func.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The function to filter keyword arguments for. |
required |
kwargs
|
Mapping[str, Any]
|
The keyword arguments to filter. |
required |
strict_mode
|
bool
|
If True, only explicitly defined parameters are passed even when the function accepts kwargs. If False (default), all parameters are passed to functions that accept kwargs, but a warning is issued for parameters not explicitly defined. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing only the key-value pairs that are valid for |
Source code in wandas/utils/introspection.py
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 | |
types
¶
util
¶
Attributes¶
Functions¶
unit_to_ref(unit)
¶
Convert unit to reference value.
Parameters¶
unit : str Unit string.
Returns¶
float Reference value for the unit. For 'Pa', returns 2e-5 (20 μPa). For other units, returns 1.0.
Source code in wandas/utils/util.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
calculate_rms(wave)
¶
Calculate the root mean square of the wave.
Parameters¶
wave : NDArrayReal Input waveform data. Can be multi-channel (shape: [channels, samples]) or single channel (shape: [samples]).
Returns¶
Union[float, NDArray[np.float64]] RMS value(s). For multi-channel input, returns an array of RMS values, one per channel. For single-channel input, returns a single RMS value.
Source code in wandas/utils/util.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
calculate_desired_noise_rms(clean_rms, snr)
¶
Calculate the desired noise RMS based on clean signal RMS and target SNR.
Parameters¶
clean_rms : "NDArrayReal" RMS value(s) of the clean signal. Can be a single value or an array for multi-channel. snr : float Target Signal-to-Noise Ratio in dB.
Returns¶
"NDArrayReal" Desired noise RMS value(s) to achieve the target SNR.
Source code in wandas/utils/util.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
amplitude_to_db(amplitude, ref)
¶
Convert amplitude to decibel.
Parameters¶
amplitude : NDArrayReal Input amplitude data. ref : float Reference value for conversion.
Returns¶
NDArrayReal Amplitude data converted to decibels.
Source code in wandas/utils/util.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
level_trigger(data, level, offset=0, hold=1)
¶
Find points where the signal crosses the specified level from below.
Parameters¶
data : NDArrayReal Input signal data. level : float Threshold level for triggering. offset : int, default=0 Offset to add to trigger points. hold : int, default=1 Minimum number of samples between successive trigger points.
Returns¶
list of int List of sample indices where the signal crosses the level.
Source code in wandas/utils/util.py
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 | |
cut_sig(data, point_list, cut_len, taper_rate=0, dc_cut=False)
¶
Cut segments from signal at specified points.
Parameters¶
data : NDArrayReal Input signal data. point_list : list of int List of starting points for cutting. cut_len : int Length of each segment to cut. taper_rate : float, default=0 Taper rate for Tukey window applied to segments. A value of 0 means no tapering, 1 means full tapering. dc_cut : bool, default=False Whether to remove DC component (mean) from segments.
Returns¶
NDArrayReal Array containing cut segments with shape (n_segments, cut_len).
Source code in wandas/utils/util.py
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 | |
Visualization Module¶
The visualization module provides data visualization functions.
wandas.visualization
¶
Modules¶
plotting
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
TFrame = TypeVar('TFrame', bound='BaseFrame[Any]')
module-attribute
¶
Classes¶
PlotStrategy
¶
Bases: ABC, Generic[TFrame]
Base class for plotting strategies
Source code in wandas/visualization/plotting.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
name
class-attribute
¶ channel_plot(x, y, ax)
abstractmethod
¶Implementation of channel plotting
Source code in wandas/visualization/plotting.py
43 44 45 46 | |
plot(bf, ax=None, title=None, overlay=False, **kwargs)
abstractmethod
¶Implementation of plotting
Source code in wandas/visualization/plotting.py
48 49 50 51 52 53 54 55 56 57 58 | |
WaveformPlotStrategy
¶
Bases: PlotStrategy['ChannelFrame']
Strategy for waveform plotting
Source code in wandas/visualization/plotting.py
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 196 197 198 199 200 201 202 203 204 205 206 | |
name = 'waveform'
class-attribute
instance-attribute
¶ channel_plot(x, y, ax, **kwargs)
¶Implementation of channel plotting
Source code in wandas/visualization/plotting.py
120 121 122 123 124 125 126 127 128 129 130 131 132 | |
plot(bf, ax=None, title=None, overlay=False, **kwargs)
¶Waveform plotting
Source code in wandas/visualization/plotting.py
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 196 197 198 199 200 201 202 203 204 205 206 | |
FrequencyPlotStrategy
¶
Bases: PlotStrategy['SpectralFrame']
Strategy for frequency domain plotting
Source code in wandas/visualization/plotting.py
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 | |
name = 'frequency'
class-attribute
instance-attribute
¶ channel_plot(x, y, ax, **kwargs)
¶Implementation of channel plotting
Source code in wandas/visualization/plotting.py
214 215 216 217 218 219 220 221 222 223 224 225 | |
plot(bf, ax=None, title=None, overlay=False, **kwargs)
¶Frequency domain plotting
Source code in wandas/visualization/plotting.py
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 | |
NOctPlotStrategy
¶
Bases: PlotStrategy['NOctFrame']
Strategy for N-octave band analysis plotting
Source code in wandas/visualization/plotting.py
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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
name = 'noct'
class-attribute
instance-attribute
¶ channel_plot(x, y, ax, **kwargs)
¶Implementation of channel plotting
Source code in wandas/visualization/plotting.py
317 318 319 320 321 322 323 324 325 326 327 328 | |
plot(bf, ax=None, title=None, overlay=False, **kwargs)
¶N-octave band analysis plotting
Source code in wandas/visualization/plotting.py
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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
SpectrogramPlotStrategy
¶
Bases: PlotStrategy['SpectrogramFrame']
Strategy for spectrogram plotting
Source code in wandas/visualization/plotting.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 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 527 528 529 530 531 532 533 534 535 536 537 538 | |
name = 'spectrogram'
class-attribute
instance-attribute
¶ channel_plot(x, y, ax, **kwargs)
¶Implementation of channel plotting
Source code in wandas/visualization/plotting.py
415 416 417 418 419 420 421 422 423 | |
plot(bf, ax=None, title=None, overlay=False, **kwargs)
¶Spectrogram plotting
Source code in wandas/visualization/plotting.py
425 426 427 428 429 430 431 432 433 434 435 436 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 527 528 529 530 531 532 533 534 535 536 537 538 | |
DescribePlotStrategy
¶
Bases: PlotStrategy['ChannelFrame']
Strategy for visualizing ChannelFrame data with describe plot
Source code in wandas/visualization/plotting.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
name = 'describe'
class-attribute
instance-attribute
¶ channel_plot(x, y, ax, **kwargs)
¶Implementation of channel plotting
Source code in wandas/visualization/plotting.py
546 547 548 | |
plot(bf, ax=None, title=None, overlay=False, **kwargs)
¶Implementation of describe method for visualizing ChannelFrame data
Source code in wandas/visualization/plotting.py
550 551 552 553 554 555 556 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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
MatrixPlotStrategy
¶
Bases: PlotStrategy[Union['SpectralFrame']]
Strategy for displaying relationships between channels in matrix format
Source code in wandas/visualization/plotting.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 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 | |
name = 'matrix'
class-attribute
instance-attribute
¶ channel_plot(x, y, ax, title=None, ylabel='', xlabel='Frequency [Hz]', alpha=0, **kwargs)
¶Source code in wandas/visualization/plotting.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | |
plot(bf, ax=None, title=None, overlay=False, **kwargs)
¶Source code in wandas/visualization/plotting.py
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 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 | |
Functions¶
register_plot_strategy(strategy_cls)
¶
Register a new plot strategy from a class
Source code in wandas/visualization/plotting.py
764 765 766 767 768 769 770 | |
get_plot_strategy(name)
¶
Get plot strategy by name
Source code in wandas/visualization/plotting.py
779 780 781 782 783 | |
create_operation(name, **params)
¶
Create operation instance from operation name and parameters
Source code in wandas/visualization/plotting.py
786 787 788 789 | |
types
¶
Type definitions for visualization parameters.
Classes¶
WaveformConfig
¶
Bases: TypedDict
Configuration for waveform plot in describe view.
This corresponds to the time-domain plot shown at the top of the describe view.
Source code in wandas/visualization/types.py
6 7 8 9 10 11 12 13 14 15 16 | |
SpectralConfig
¶
Bases: TypedDict
Configuration for spectral plot in describe view.
This corresponds to the frequency-domain plot (Welch) shown on the right side.
Source code in wandas/visualization/types.py
19 20 21 22 23 24 25 26 27 28 29 | |
DescribeParams
¶
Bases: TypedDict
Parameters for the describe visualization method.
This visualization creates a comprehensive view with three plots: 1. Time-domain waveform (top) 2. Spectrogram (bottom-left) 3. Frequency spectrum via Welch method (bottom-right)
Attributes:
| Name | Type | Description |
|---|---|---|
fmin |
float
|
Minimum frequency to display in the spectrogram (Hz). Default: 0 |
fmax |
Optional[float]
|
Maximum frequency to display in the spectrogram (Hz). Default: Nyquist frequency |
cmap |
str
|
Colormap for the spectrogram. Default: 'jet' |
vmin |
Optional[float]
|
Minimum value for spectrogram color scale (dB). Auto-calculated if None. |
vmax |
Optional[float]
|
Maximum value for spectrogram color scale (dB). Auto-calculated if None. |
xlim |
Optional[tuple[float, float]]
|
Time axis limits (seconds) for all time-based plots. |
ylim |
Optional[tuple[float, float]]
|
Frequency axis limits (Hz) for frequency-based plots. |
Aw |
bool
|
Apply A-weighting to the frequency analysis. Default: False |
waveform |
WaveformConfig
|
Additional configuration dict for waveform subplot. |
spectral |
SpectralConfig
|
Additional configuration dict for spectral subplot. |
normalize |
bool
|
Normalize audio data for playback. Default: True |
is_close |
bool
|
Close the figure after displaying. Default: True |
Deprecated (for backward compatibility): axis_config: Old configuration format. Use specific parameters instead. cbar_config: Old colorbar configuration. Use vmin/vmax instead.
Examples:
>>> cf = ChannelFrame.read_wav("audio.wav")
>>> # Basic usage
>>> cf.describe()
>>>
>>> # Custom frequency range
>>> cf.describe(fmin=100, fmax=5000)
>>>
>>> # Custom color scale
>>> cf.describe(vmin=-80, vmax=-20, cmap="viridis")
>>>
>>> # A-weighted analysis
>>> cf.describe(Aw=True)
>>>
>>> # Custom time range
>>> cf.describe(xlim=(0, 5)) # Show first 5 seconds
Source code in wandas/visualization/types.py
32 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 | |
fmin
instance-attribute
¶ fmax
instance-attribute
¶ cmap
instance-attribute
¶ vmin
instance-attribute
¶ vmax
instance-attribute
¶ xlim
instance-attribute
¶ ylim
instance-attribute
¶ Aw
instance-attribute
¶ waveform
instance-attribute
¶ spectral
instance-attribute
¶ normalize
instance-attribute
¶ is_close
instance-attribute
¶ axis_config
instance-attribute
¶ cbar_config
instance-attribute
¶Datasets Module¶
The datasets module provides sample data and dataset functions.
wandas.datasets
¶
Modules¶
sample_data
¶
Attributes¶
Functions¶
load_sample_signal(frequency=5.0, sampling_rate=100, duration=1.0)
¶
Generate a sample sine wave signal.
Parameters¶
frequency : float, default=5.0 Frequency of the signal in Hz. sampling_rate : int, default=100 Sampling rate in Hz. duration : float, default=1.0 Duration of the signal in seconds.
Returns¶
NDArrayReal Signal data as a NumPy array.
Source code in wandas/datasets/sample_data.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |