pychronux
dpsschk(tapers, N, Fs)
Check and generate DPSS tapers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tapers | Union[ndarray, Tuple[float, int]] | Input can be either an array representing [NW, K] or a tuple with the number of tapers and the maximum number of tapers. | required |
N | int | Number of points for FFT. | required |
Fs | float | Sampling frequency. | required |
Returns:
Name | Type | Description |
---|---|---|
tapers | ndarray | Tapers matrix, shape [tapers, eigenvalues]. |
Notes
The function computes DPSS (Discrete Prolate Spheroidal Sequences) tapers and scales them by the square root of the sampling frequency.
Source code in neuro_py/process/pychronux.py
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 |
|
get_tapers(N, bandwidth, *, fs=1.0, min_lambda=0.95, n_tapers=None)
Compute tapers and associated energy concentrations for the Thomson multitaper method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N | int | Length of taper. | required |
bandwidth | float | Bandwidth of taper, in Hz. | required |
fs | float | Sampling rate, in Hz. Default is 1 Hz. | 1.0 |
min_lambda | float | Minimum energy concentration that each taper must satisfy. Default is 0.95. | 0.95 |
n_tapers | Optional[int] | Number of tapers to compute. Default is to use all tapers that satisfy 'min_lambda'. | None |
Returns:
Name | Type | Description |
---|---|---|
tapers | ndarray | Array of tapers with shape (n_tapers, N). |
lambdas | ndarray | Energy concentrations for each taper with shape (n_tapers,). |
Raises:
Type | Description |
---|---|
ValueError | If not enough tapers are available or if none of the tapers satisfy the minimum energy concentration criteria. |
Source code in neuro_py/process/pychronux.py
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 |
|
getfgrid(Fs, nfft, fpass)
Get frequency grid for evaluation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Fs | int | Sampling frequency. | required |
nfft | int | Number of points for FFT. | required |
fpass | List[float] | Frequency range to evaluate (as [fmin, fmax]). | required |
Returns:
Name | Type | Description |
---|---|---|
f | ndarray | Frequency vector within the specified range. |
findx | ndarray | Boolean array indicating the indices of the frequency vector that fall within the specified range. |
Notes
The frequency vector is computed based on the sampling frequency and the number of FFT points. Only frequencies within the range defined by fpass
are returned.
Source code in neuro_py/process/pychronux.py
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 |
|
mtcoherencept(data1, data2, Fs, fpass, NW=2.5, n_tapers=4, time_support=None, tapers=None, tapers_ts=None, nfft=None)
Multitaper coherence for point processes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data1 | ndarray | Array of spike times for the first signal (in seconds). | required |
data2 | ndarray | Array of spike times for the second signal (in seconds). | required |
Fs | int | Sampling frequency. | required |
fpass | list | Frequency range to evaluate as [min_freq, max_freq]. | required |
NW | Union[int, float] | Time-bandwidth product, by default 2.5. | 2.5 |
n_tapers | int | Number of tapers, by default 4. | 4 |
time_support | Union[list, None] | Time range to evaluate, by default None. | None |
tapers | Union[ndarray, None] | Precomputed tapers, given as [NW, K] or [tapers, eigenvalues], by default None. | None |
tapers_ts | Union[ndarray, None] | Taper time series, by default None. | None |
nfft | Optional[int] | Number of points for FFT, by default None. | None |
Returns:
Type | Description |
---|---|
DataFrame | Coherence between the two point processes. |
Source code in neuro_py/process/pychronux.py
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 |
|
mtcsdpt(data1, data2, Fs, fpass, NW=2.5, n_tapers=4, time_support=None, tapers=None, tapers_ts=None, nfft=None)
Multitaper cross-spectral density (CSD) for point processes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data1 | ndarray | Array of spike times for the first signal (in seconds). | required |
data2 | ndarray | Array of spike times for the second signal (in seconds). | required |
Fs | int | Sampling frequency. | required |
fpass | list | Frequency range to evaluate as [min_freq, max_freq]. | required |
NW | Union[int, float] | Time-bandwidth product, by default 2.5. | 2.5 |
n_tapers | int | Number of tapers, by default 4. | 4 |
time_support | Union[list, None] | Time range to evaluate, by default None. | None |
tapers | Union[ndarray, None] | Precomputed tapers, given as [NW, K] or [tapers, eigenvalues], by default None. | None |
tapers_ts | Union[ndarray, None] | Taper time series, by default None. | None |
nfft | Optional[int] | Number of points for FFT, by default None. | None |
Returns:
Type | Description |
---|---|
DataFrame | Cross-spectral density between the two point processes. |
Source code in neuro_py/process/pychronux.py
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 |
|
mtfftc(data, tapers, nfft, Fs)
Multi-taper Fourier Transform - Continuous Data (Single Signal)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | ndarray | 1D array of data (samples). | required |
tapers | ndarray | Precomputed DPSS tapers with shape (samples, tapers). | required |
nfft | int | Length of padded data for FFT. | required |
Fs | int | Sampling frequency. | required |
Returns:
Name | Type | Description |
---|---|---|
J | ndarray | FFT in the form (nfft, K), where K is the number of tapers. |
Source code in neuro_py/process/pychronux.py
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 |
|
mtfftpt(data, tapers, nfft, t, f, findx)
Multitaper FFT for point process times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | ndarray | 1D array of spike times (in seconds). | required |
tapers | ndarray | Tapers from the DPSS method. | required |
nfft | int | Number of points for FFT. | required |
t | ndarray | Time vector. | required |
f | ndarray | Frequency vector. | required |
findx | list of bool | Frequency index. | required |
Returns:
Name | Type | Description |
---|---|---|
J | ndarray | FFT of the data. |
Msp | float | Mean spikes per time. |
Nsp | float | Total number of spikes in data. |
Notes
The function computes the multitaper FFT of spike times using the specified tapers and returns the FFT result, mean spikes, and total spike count.
Source code in neuro_py/process/pychronux.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 |
|
mtspectrumc(data, Fs, fpass, tapers)
Compute the multitaper power spectrum for continuous data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | ndarray | 1D array of continuous data (e.g., LFP). | required |
Fs | int | Sampling frequency in Hz. | required |
fpass | list | Frequency range to evaluate as [min_freq, max_freq]. | required |
tapers | ndarray | Tapers array with shape [NW, K] or [tapers, eigenvalues]. | required |
Returns:
Name | Type | Description |
---|---|---|
S | Series | Power spectrum with frequencies as the index. |
Notes
This function utilizes the multitaper method for spectral estimation and returns the power spectrum as a pandas Series.
Source code in neuro_py/process/pychronux.py
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 |
|
mtspectrumpt(data, Fs, fpass, NW=2.5, n_tapers=4, time_support=None, tapers=None, tapers_ts=None, nfft=None)
Multitaper power spectrum estimation for point process data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | ndarray | Array of spike times (in seconds). | required |
Fs | int | Sampling frequency. | required |
fpass | list of float | Frequency range to evaluate. | required |
NW | Union[int, float] | Time-bandwidth product (default is 2.5). | 2.5 |
n_tapers | int | Number of tapers (default is 4). | 4 |
time_support | Union[list, None] | Time range to evaluate (default is None). | None |
tapers | Union[ndarray, None] | Precomputed tapers, given as [NW, K] or [tapers, eigenvalues] (default is None). | None |
tapers_ts | Union[ndarray, None] | Taper time series (default is None). | None |
nfft | Optional[int] | Number of points for FFT (default is None). | None |
Returns:
Type | Description |
---|---|
DataFrame | DataFrame containing the power spectrum. |
Examples:
>>> spec = pychronux.mtspectrumpt(
>>> st.data,
>>> 100,
>>> [1, 20],
>>> NW=3,
>>> n_tapers=5,
>>> time_support=[st.support.start, st.support.stop],
>>> nfft=500,
>>> )
Source code in neuro_py/process/pychronux.py
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 |
|
point_spectra(times, Fs=1250, freq_range=[1, 20], tapers0=[3, 5], pad=0, nfft=None)
Compute multitaper power spectrum for point processes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
times | ndarray | Array of spike times (in seconds). | required |
Fs | int | Sampling frequency (default is 1250 Hz). | 1250 |
freq_range | List[float] | Frequency range to evaluate (default is [1, 20] Hz). | [1, 20] |
tapers0 | List[int] | Time-bandwidth product and number of tapers (default is [3, 5]). The time-bandwidth product is used to compute the tapers. | [3, 5] |
pad | int | Padding for the FFT (default is 0). | 0 |
nfft | Optional[int] | Number of points for FFT (default is None). | None |
Returns:
Name | Type | Description |
---|---|---|
spectra | ndarray | Power spectrum. |
f | ndarray | Frequency vector. |
Notes
Alternative function to mtspectrumpt
for computing the power spectrum
Source code in neuro_py/process/pychronux.py
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 |
|