Event detection
Turning processed gaze samples into fixations, saccades and blinks.
Pyxations ships the Engbert–Kliegl implementation and a REMoDNaV adapter, and can also reuse the events reported by EyeLink's own parser. Selecting a detector does not change the canonical BIDS storage layer, so results from different algorithms are stored side by side and can be compared directly.
eye_movement_detection
The abstract base class. Implement it to add support for another algorithm.
EyeMovementDetection
Bases: ABC
Base class for eye-movement detection adapters.
Subclasses wrap one detection algorithm and turn processed gaze samples
into fixation, saccade and blink tables. Pyxations ships
:class:~pyxations.EngbertDetection and
:class:~pyxations.RemodnavDetection; EyeLink recordings can instead reuse
the events reported by the vendor parser.
Implement :meth:detect_eye_movements to add support for another
algorithm. The canonical BIDS storage layer does not change, so a new
detector becomes usable across the whole analysis hierarchy without
touching the conversion or export code.
Source code in pyxations/methods/eyemovement/eye_movement_detection.py
detect_eye_movements(*args, **kwargs)
abstractmethod
Return detected eye-movement events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
object
|
Positional detector-specific configuration values. |
()
|
**kwargs
|
object
|
Keyword detector-specific configuration values. |
{}
|
Source code in pyxations/methods/eyemovement/eye_movement_detection.py
Engbert–Kliegl
Velocity-threshold detection following Engbert and Mergenthaler.
Polars-native Engbert–Kliegl eye-movement detection adapter.
EngbertDetection
Bases: EyeMovementDetection
Detect saccades and inter-saccadic fixations with Engbert–Kliegl.
Source code in pyxations/methods/eyemovement/engbert.py
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 | |
detect_eye_movements(vfac=5.0, mindur_ms=6.0, smoothlevel=1, globalthresh=True, degperpixel=None, screen_size_cm=38.0, screen_width_px=1920, screen_distance_cm=60.0, sample_rate_fallback=None)
Detect fixations and saccades, returning times in milliseconds.
The returned dataframe type matches self.samples. Gaze samples may
contain left/right columns (LX, LY, RX, RY) or generic
columns (X, Y). Pupil measurements are summarized when a
corresponding pupil column is available; otherwise pupilAvg is NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vfac
|
float
|
Multiplier applied to the robust velocity threshold. |
5.0
|
mindur_ms
|
float
|
Minimum saccade duration in milliseconds. |
6.0
|
smoothlevel
|
int
|
Smoothing-kernel level used before calculating velocity. |
1
|
globalthresh
|
bool
|
If true, estimate one threshold per eye across all chunks; otherwise estimate thresholds separately for each chunk. |
True
|
degperpixel
|
float
|
Degrees of visual angle per pixel. When omitted, calculate it from the screen geometry. |
None
|
screen_size_cm
|
float
|
Physical screen width in centimetres. |
38.0
|
screen_width_px
|
int
|
Screen width in pixels. |
1920
|
screen_distance_cm
|
float
|
Viewing distance in centimetres. |
60.0
|
sample_rate_fallback
|
float
|
Sampling rate used only when it cannot be measured from timestamps
and is not present in |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fixations |
DataFrame - like
|
Detected fixation events, using the same dataframe library as the input samples. |
saccades |
DataFrame - like
|
Detected saccade events, using the same dataframe library as the input samples. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a numeric configuration value is invalid or the sample rate cannot be determined. |
Source code in pyxations/methods/eyemovement/engbert.py
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 | |
microsacc_plugin(pos_xy, vel_xy, vfac, mindur_samples, sdx, sdy)
Return detected saccades using the Engbert velocity criterion.
Columns are onset, offset, duration in samples, average velocity, peak velocity, travelled distance, angle, amplitude, direction, epoch, x0, y0, x1, and y1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_xy
|
ndarray
|
Gaze coordinates with shape |
required |
vel_xy
|
ndarray
|
Gaze velocities with shape |
required |
vfac
|
float
|
Multiplier applied to the robust velocity thresholds. |
required |
mindur_samples
|
int
|
Minimum number of consecutive samples required for a saccade. |
required |
sdx
|
float
|
Robust horizontal velocity scale. |
required |
sdy
|
float
|
Robust vertical velocity scale. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
One row per detected saccade and fourteen event columns. An empty
|
Source code in pyxations/methods/eyemovement/engbert.py
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 | |
vecvel(gaze_xy, fs, smoothlevel=1)
Calculate two-dimensional gaze velocity in pixels per second.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gaze_xy
|
ndarray
|
Gaze coordinates with shape |
required |
fs
|
float
|
Sampling rate in hertz. |
required |
smoothlevel
|
int
|
Smoothing-kernel level. Zero disables smoothing; levels one and two use progressively wider kernels. |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Horizontal and vertical velocities with the same shape as
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the coordinates do not have two columns or |
Source code in pyxations/methods/eyemovement/engbert.py
velthresh(vxy)
Return robust horizontal and vertical velocity thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vxy
|
ndarray
|
Horizontal and vertical velocities with shape |
required |
Returns:
| Type | Description |
|---|---|
tuple of float
|
Robust standard deviations for the horizontal and vertical velocity components. |
Source code in pyxations/methods/eyemovement/engbert.py
REMoDNaV
Adapter for REMoDNaV. Requires the optional remodnav extra, installed with
pip install 'pyxations[remodnav]'.
Polars-native REMoDNaV eye-movement detection adapter.
RemodnavDetection
Bases: EyeMovementDetection
Detect fixations and saccades with REMoDNaV.
Source code in pyxations/methods/eyemovement/remodnav_detector.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 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 | |
detect_eye_movements(min_pursuit_dur=10.0, max_pso_dur=0.0, min_fix_dur=0.05, sac_max_vel=1000.0, fix_max_amp=1.5, sac_time_thresh=0.002, drop_fix_from_blink=True, screen_size=38.0, screen_width=1920, screen_distance=60.0, savgol_length=0.195, lowpass_cutoff_freq=None)
Detect eye movements in all continuous chunks and recorded eyes.
Input timestamps are expected in milliseconds. The returned dataframe
type matches self.samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_pursuit_dur
|
float
|
Minimum pursuit duration in seconds. |
10.0
|
max_pso_dur
|
float
|
Maximum post-saccadic oscillation duration in seconds. |
0.0
|
min_fix_dur
|
float
|
Minimum fixation duration in seconds. |
0.05
|
sac_max_vel
|
float
|
Maximum retained saccade peak velocity in degrees per second. |
1000.0
|
fix_max_amp
|
float
|
Maximum retained fixation amplitude in degrees. |
1.5
|
sac_time_thresh
|
float
|
Temporal tolerance in seconds when associating fixations with preceding saccades. |
0.002
|
drop_fix_from_blink
|
bool
|
Whether to retain only fixations adjacent to a detected saccade. |
True
|
screen_size
|
float
|
Physical screen width in centimetres. |
38.0
|
screen_width
|
int
|
Screen width in pixels. |
1920
|
screen_distance
|
float
|
Viewing distance in centimetres. |
60.0
|
savgol_length
|
float
|
Savitzky-Golay filter window length in seconds. |
0.195
|
lowpass_cutoff_freq
|
float
|
Low-pass cutoff in hertz. By default, use the smaller of 4 Hz and 40 percent of the measured sample rate. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fixations |
DataFrame - like
|
Detected fixation events, using the input dataframe library. |
saccades |
DataFrame - like
|
Detected saccade events, using the input dataframe library. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If timestamps and rates differ in length, or a recorded rate is non-finite or non-positive. |
Source code in pyxations/methods/eyemovement/remodnav_detector.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 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 | |
detect_on_chunk(indices, min_pursuit_dur=10.0, max_pso_dur=0.0, min_fix_dur=0.05, sac_max_vel=1000.0, fix_max_amp=1.5, sac_time_thresh=0.002, drop_fix_from_blink=True, screen_size=38.0, screen_width=1920, screen_distance=60.0, savgol_length=0.19, lowpass_cutoff_freq=None)
Detect events for a continuous set of sample row indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
ndarray
|
Row indices defining one continuous sample chunk. |
required |
min_pursuit_dur
|
float
|
Minimum pursuit duration in seconds. |
10.0
|
max_pso_dur
|
float
|
Maximum post-saccadic oscillation duration in seconds. |
0.0
|
min_fix_dur
|
float
|
Minimum fixation duration in seconds. |
0.05
|
sac_max_vel
|
float
|
Maximum retained saccade peak velocity in degrees per second. |
1000.0
|
fix_max_amp
|
float
|
Maximum retained fixation amplitude in degrees. |
1.5
|
sac_time_thresh
|
float
|
Temporal tolerance in seconds for fixation-saccade adjacency. |
0.002
|
drop_fix_from_blink
|
bool
|
Whether to retain only fixations adjacent to a detected saccade. |
True
|
screen_size
|
float
|
Physical screen width in centimetres. |
38.0
|
screen_width
|
int
|
Screen width in pixels. |
1920
|
screen_distance
|
float
|
Viewing distance in centimetres. |
60.0
|
savgol_length
|
float
|
Savitzky-Golay filter window length in seconds. |
0.19
|
lowpass_cutoff_freq
|
float
|
Low-pass cutoff in hertz. By default, choose a Nyquist-safe value. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fixations |
DataFrame - like
|
Detected fixation events for the chunk. |
saccades |
DataFrame - like
|
Detected saccade events for the chunk. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the chunk metadata are not constant or no supported gaze coordinate columns are available. |
Source code in pyxations/methods/eyemovement/remodnav_detector.py
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 | |
run_eye_movement(gazex_data, gazey_data, sample_rate, min_pursuit_dur=10.0, max_pso_dur=0.0, min_fix_dur=0.05, min_saccade_duration=0.04, sac_max_vel=1000.0, fix_max_amp=1.5, sac_time_thresh=0.002, drop_fix_from_blink=True, screen_size=38.0, screen_width=1920, screen_distance=60.0, calib_index=0, savgol_length=0.19, eyes_recorded=None, starting_time=None, times=None, pupil_data=None, eye=None, lowpass_cutoff_freq=None)
Run REMoDNaV for one eye stream and return event tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gazex_data
|
array - like
|
Horizontal gaze coordinates. |
required |
gazey_data
|
array - like
|
Vertical gaze coordinates. |
required |
sample_rate
|
float
|
Sampling rate in hertz. |
required |
min_pursuit_dur
|
float
|
Minimum pursuit duration in seconds. |
10.0
|
max_pso_dur
|
float
|
Maximum post-saccadic oscillation duration in seconds. |
0.0
|
min_fix_dur
|
float
|
Minimum fixation duration in seconds. |
0.05
|
min_saccade_duration
|
float
|
Minimum saccade duration in seconds. |
0.04
|
sac_max_vel
|
float
|
Maximum retained saccade peak velocity in degrees per second. |
1000.0
|
fix_max_amp
|
float
|
Maximum retained fixation amplitude in degrees. |
1.5
|
sac_time_thresh
|
float
|
Temporal tolerance in seconds for fixation-saccade adjacency. |
0.002
|
drop_fix_from_blink
|
bool
|
Whether to retain only fixations adjacent to a detected saccade. |
True
|
screen_size
|
float
|
Physical screen width in centimetres. |
38.0
|
screen_width
|
int
|
Screen width in pixels. |
1920
|
screen_distance
|
float
|
Viewing distance in centimetres. |
60.0
|
calib_index
|
object
|
Calibration-block identifier copied to event rows. |
0
|
savgol_length
|
float
|
Savitzky-Golay filter window length in seconds. |
0.19
|
eyes_recorded
|
object
|
Source eye-recording label copied to event rows. |
None
|
starting_time
|
float
|
Recording-time offset in milliseconds. |
None
|
times
|
array - like
|
Per-sample times in seconds relative to |
None
|
pupil_data
|
array - like
|
Pupil measurements aligned with the gaze arrays. |
None
|
eye
|
object
|
Eye label copied to event rows. |
None
|
lowpass_cutoff_freq
|
float
|
Low-pass cutoff in hertz. It must be below Nyquist. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fixations |
DataFrame - like
|
Detected fixation events, using the input dataframe library. |
saccades |
DataFrame - like
|
Detected saccade events, using the input dataframe library. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If configuration values are invalid or the sample arrays have inconsistent lengths. |
Source code in pyxations/methods/eyemovement/remodnav_detector.py
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 | |
run_eye_movement_from_samples(sample_rate, x_label='X', y_label='Y', config=None, **kwargs)
Run REMoDNaV on two columns in self.samples.
Missing pupil measurements remain missing (NaN); they are no longer represented by synthetic zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_rate
|
float
|
Sampling rate in hertz. |
required |
x_label
|
str
|
Name of the horizontal gaze-coordinate column. |
"X"
|
y_label
|
str
|
Name of the vertical gaze-coordinate column. |
"Y"
|
config
|
mapping
|
Detector options forwarded to :meth: |
None
|
**kwargs
|
object
|
Additional detector options forwarded to
:meth: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
fixations |
DataFrame - like
|
Detected fixation events, using the input dataframe library. |
saccades |
DataFrame - like
|
Detected saccade events, using the input dataframe library. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the rate is not positive or the gaze and timestamp columns differ in length. |