-
Notifications
You must be signed in to change notification settings - Fork 17
/
parsing_test.py
859 lines (805 loc) · 29 KB
/
parsing_test.py
1
2
3
4
5
6
7
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
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
# Copyright (c) 2024 The pymovements Project Authors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Copyright (c) 2023-2024 The pymovements Project Authors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# git
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Tests pymovements asc to csv processing."""
import datetime
from pathlib import Path
import numpy as np
import polars as pl
import pytest
from polars.testing import assert_frame_equal
import pymovements as pm
ASC_TEXT = r"""
** DATE: Wed Mar 8 09:25:20 2023
** TYPE: EDF_FILE BINARY EVENT SAMPLE TAGGED
** VERSION: EYELINK II 1
** SOURCE: EYELINK CL
** EYELINK II CL v6.12 Feb 1 2018 (EyeLink Portable Duo)
** CAMERA: EyeLink USBCAM Version 1.01
** SERIAL NUMBER: CLU-DAB50
** CAMERA_CONFIG: DAB50200.SCD
** RECORDED BY pymovements
** SREB2.2.299 WIN32 LID:20A87A96 Mod:2023.03.08 11:03 MEZ
**
some
lines
MSG 2154555 RECCFG CR 1000 2 1 L
MSG 2154555 ELCLCFG BTABLER
MSG 2095865 DISPLAY_COORDS 0 0 1279 1023
PRESCALER 1
VPRESCALER 1
PUPIL AREA
EVENTS GAZE LEFT RATE 1000.00 TRACKING CR FILTER 2
SAMPLES GAZE LEFT RATE 1000.00 TRACKING CR FILTER 2 INPUT
the next line has all additional trial columns set to None
START 10000000 RIGHT SAMPLES EVENTS
10000000 850.7 717.5 714.0 0.0 ...
END 10000001 SAMPLES EVENTS RES 38.54 31.12
MSG 10000001 START_A
START 10000002 RIGHT SAMPLES EVENTS
the next line now should have the task column set to A
10000002 850.7 717.5 714.0 0.0 ...
END 10000002 SAMPLES EVENTS RES 38.54 31.12
MSG 10000003 STOP_A
the task should be set to None again
START 10000004 RIGHT SAMPLES EVENTS
10000004 850.7 717.5 714.0 0.0 ...
END 10000005 SAMPLES EVENTS RES 38.54 31.12
MSG 10000013.5 RECCFG CR 2000 1 1 R
MSG 10000005 METADATA_1 123
MSG 10000005 START_B
the next line now should have the task column set to B
START 10000006 RIGHT SAMPLES EVENTS
10000006 850.7 717.5 714.0 0.0 ...
END 10000007 SAMPLES EVENTS RES 38.54 31.12
MSG 10000007 START_TRIAL_1
the next line now should have the trial column set to 1
START 10000008 RIGHT SAMPLES EVENTS
10000008 850.7 717.5 714.0 0.0 ...
END 10000009 SAMPLES EVENTS RES 38.54 31.12
MSG 10000009 STOP_TRIAL_1
MSG 10000010 START_TRIAL_2
the next line now should have the trial column set to 2
START 10000011 RIGHT SAMPLES EVENTS
10000011 850.7 717.5 714.0 0.0 ...
END 10000012 SAMPLES EVENTS RES 38.54 31.12
MSG 10000012 STOP_TRIAL_2
MSG 10000013 START_TRIAL_3
the next line now should have the trial column set to 3
START 10000014 RIGHT SAMPLES EVENTS
MSG 10000014 METADATA_2 abc
MSG 10000014 METADATA_1 456
10000014 850.7 717.5 714.0 0.0 ...
END 10000015 SAMPLES EVENTS RES 38.54 31.12
MSG 10000015 STOP_TRIAL_3
MSG 10000016 STOP_B
task and trial should be set to None again
MSG 10000017 METADATA_3
START 10000017 RIGHT SAMPLES EVENTS
10000017 850.7 717.5 . 0.0 ...
SBLINK R 10000018
10000019 . . 0.0 0.0 ...
10000020 . . 0.0 0.0 ...
EBLINK R 10000018 10000020 2
10000021 . . 0.0 0.0 ...
END 10000022 SAMPLES EVENTS RES 38.54 31.12
"""
PATTERNS = [
{
'pattern': 'START_A',
'column': 'task',
'value': 'A',
},
{
'pattern': 'START_B',
'column': 'task',
'value': 'B',
},
{
'pattern': ('STOP_A', 'STOP_B'),
'column': 'task',
'value': None,
},
r'START_TRIAL_(?P<trial_id>\d+)',
{
'pattern': r'STOP_TRIAL',
'column': 'trial_id',
'value': None,
},
]
METADATA_PATTERNS = [
r'METADATA_1 (?P<metadata_1>\d+)',
{'pattern': r'METADATA_2 (?P<metadata_2>\w+)'},
{'pattern': r'METADATA_3', 'key': 'metadata_3', 'value': True},
{'pattern': r'METADATA_4', 'key': 'metadata_4', 'value': True},
]
EXPECTED_DF = pl.from_dict(
{
'time': [
10000000.0, 10000002.0, 10000004.0, 10000006.0, 10000008.0, 10000011.0, 10000014.0,
10000017.0, 10000019.0, 10000020.0, 10000021.0,
],
'x_pix': [850.7, 850.7, 850.7, 850.7, 850.7, 850.7, 850.7, 850.7, np.nan, np.nan, np.nan],
'y_pix': [717.5, 717.5, 717.5, 717.5, 717.5, 717.5, 717.5, 717.5, np.nan, np.nan, np.nan],
'pupil': [714.0, 714.0, 714.0, 714.0, 714.0, 714.0, 714.0, np.nan, 0.0, 0.0, 0.0],
'task': [None, 'A', None, 'B', 'B', 'B', 'B', None, None, None, None],
'trial_id': [None, None, None, None, '1', '2', '3', None, None, None, None],
},
)
EXPECTED_METADATA = {
'weekday': 'Wed',
'month': 'Mar',
'day': 8,
'time': '09:25:20',
'year': 2023,
'version_1': 'EYELINK II 1',
'version_2': 'EYELINK II CL v6.12 Feb 1 2018 (EyeLink Portable Duo)',
'model': 'EyeLink Portable Duo',
'version_number': '6.12',
'pupil_data_type': 'AREA',
'calibrations': [],
'validations': [],
'resolution': (1280, 1024),
'data_loss_ratio_blinks': 0.18181818181818182,
'data_loss_ratio': 0.2727272727272727,
'total_recording_duration_ms': 11,
'datetime': datetime.datetime(2023, 3, 8, 9, 25, 20),
'blinks': [{
'duration_ms': 2,
'num_samples': 2,
'start_timestamp': 10000018,
'stop_timestamp': 10000020,
}],
'mount_configuration': {
'mount_type': 'Desktop',
'head_stabilization': 'stabilized',
'eyes_recorded': 'binocular / monocular',
'short_name': 'BTABLER',
},
'metadata_1': '123',
'metadata_2': 'abc',
'metadata_3': True,
'metadata_4': None,
'recording_config': [
{
'sampling_rate': '1000', # MSG 2154555 RECCFG CR 1000 2 1 L
'file_sample_filter': '2',
'link_sample_filter': '1',
'timestamp': '2154555',
'tracked_eye': 'L',
'tracking_mode': 'CR',
},
{
'sampling_rate': '2000', # MSG 10000013.5 RECCFG CR 2000 1 1 R
'file_sample_filter': '1',
'link_sample_filter': '1',
'timestamp': '10000013.5',
'tracked_eye': 'R',
'tracking_mode': 'CR',
},
],
}
def test_parse_eyelink(tmp_path):
filepath = tmp_path / 'sub.asc'
filepath.write_text(ASC_TEXT)
df, metadata = pm.utils.parsing.parse_eyelink(
filepath,
patterns=PATTERNS,
metadata_patterns=METADATA_PATTERNS,
)
assert_frame_equal(df, EXPECTED_DF, check_column_order=False)
assert metadata == EXPECTED_METADATA
@pytest.mark.parametrize(
'patterns',
[
[1],
[{'pattern': 1}],
],
)
def test_parse_eyelink_raises_value_error(tmp_path, patterns):
filepath = tmp_path / 'sub.asc'
filepath.write_text(ASC_TEXT)
with pytest.raises(ValueError) as excinfo:
pm.utils.parsing.parse_eyelink(
filepath,
patterns=patterns,
)
msg, = excinfo.value.args
expected_substrings = ['invalid pattern', '1']
for substring in expected_substrings:
assert substring in msg
@pytest.mark.parametrize(
('metadata', 'expected_version', 'expected_model'),
[
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'** VERSION: EYELINK II 1\n'
'** EYELINK II CL v6.12 Feb 1 2018 (EyeLink Portable Duo)',
'6.12',
'EyeLink Portable Duo',
id='eye_link_portable_duo',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'** VERSION: EYELINK II 1\n'
'** EYELINK II CL v5.12 Feb 1 2018\n',
'5.12',
'EyeLink 1000 Plus',
id='eye_link_1000_plus',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'** VERSION: EYELINK II 1\n'
'** EYELINK II CL v4.12 Feb 1 2018',
'4.12',
'EyeLink 1000',
id='eye_link_1000_1',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'** VERSION: EYELINK II 1\n'
'** EYELINK II CL v3.12 Feb 1 2018',
'3.12',
'EyeLink 1000',
id='eye_link_1000_2',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'** VERSION: EYELINK II 1\n'
'** EYELINK II CL v2.12 Feb 1 2018',
'2.12',
'EyeLink II',
id='eye_link_II',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'** VERSION: EYELINK REVISION 2.00 (Aug 12 1997)',
'2.00',
'EyeLink I',
id='eye_link_I',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'** VERSION: nothing\n',
'unknown',
'unknown',
id='unknown_version_1',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'** VERSION: EYELINK II 1\n'
'** EYELINK II CL Feb 1 2018 (EyeLink Portable Duo)',
'unknown',
'unknown',
id='unknown_version_2',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'** TYPE: EDF_FILE BINARY EVENT SAMPLE TAGGED',
'unknown',
'unknown',
id='unknown_version_3',
),
],
)
def test_parse_eyelink_version(tmp_path, metadata, expected_version, expected_model):
filepath = tmp_path / 'sub.asc'
filepath.write_text(metadata)
_, metadata = pm.utils.parsing.parse_eyelink(
filepath,
)
assert metadata['version_number'] == expected_version
assert metadata['model'] == expected_model
@pytest.mark.parametrize(
('metadata', 'expected_msg'),
[
pytest.param(
'',
'No metadata found. Please check the file for errors.',
id='eye_link_no_metadata',
),
],
)
def test_no_metadata_warning(tmp_path, metadata, expected_msg):
filepath = tmp_path / 'sub.asc'
filepath.write_text(metadata)
with pytest.raises(Warning) as info:
_, metadata = pm.utils.parsing.parse_eyelink(
filepath,
)
msg = info.value.args[0]
assert msg == expected_msg
@pytest.mark.parametrize(
('metadata', 'expected_validation', 'expected_calibration'),
[
pytest.param(
'MSG 2095865 DISPLAY_COORDS 0 0 1279 1023\n'
'MSG 7045618 !CAL \n'
'>>>>>>> CALIBRATION (HV9,P-CR) FOR LEFT: <<<<<<<<<\n'
'MSG 7045618 !CAL Calibration points: \n'
'MSG 1076158 !CAL VALIDATION HV9 R RIGHT POOR ERROR 2.40 avg. 6.03 max '
'OFFSET 0.19 deg. 4.2,6.3 pix.\n',
[{
'error': 'POOR ERROR',
'tracked_eye': 'RIGHT',
'num_points': '9',
'timestamp': '1076158',
'validation_score_avg': '2.40',
'validation_score_max': '6.03',
}],
[{
'num_points': '9',
'timestamp': '7045618',
'tracked_eye': 'LEFT',
'type': 'P-CR',
}],
id='cal_timestamp_with_space',
),
pytest.param(
'** DATE: Wed Feb 1 04:38:54 2017\n'
'MSG 7045618 !CAL\n'
'>>>>>>> CALIBRATION (HV9,P-CR) FOR LEFT: <<<<<<<<<\n',
[],
[{
'num_points': '9',
'timestamp': '7045618',
'tracked_eye': 'LEFT',
'type': 'P-CR',
}],
id='cal_timestamp_no_space_no_val',
),
pytest.param(
'** DATE: Wed Feb 1 04:38:54 2017\n'
'MSG 7045618 !CAL\n'
'MSG 7045618 !CAL\n',
[],
[{'timestamp': '7045618'}],
id='cal_timestamp_no_cal_no_val',
),
],
)
def test_val_cal_eyelink(tmp_path, metadata, expected_validation, expected_calibration):
filepath = tmp_path / 'sub.asc'
filepath.write_text(metadata)
_, parsed_metadata = pm.utils.parsing.parse_eyelink(filepath)
assert parsed_metadata['calibrations'] == expected_calibration
assert parsed_metadata['validations'] == expected_validation
def test_parse_val_cal_eyelink_monocular_file():
example_asc_monocular_path = Path(__file__).parent.parent.parent / \
'files/eyelink_monocular_example.asc'
_, metadata = pm.utils.parsing.parse_eyelink(example_asc_monocular_path)
expected_validation = [{
'error': 'GOOD ERROR',
'tracked_eye': 'LEFT',
'num_points': '9',
'timestamp': '2148587',
'validation_score_avg': '0.27',
'validation_score_max': '0.83',
}]
expected_calibration = [{
'num_points': '9', 'type': 'P-CR', 'tracked_eye': 'LEFT', 'timestamp': '2135819',
}]
assert metadata['calibrations'] == expected_calibration
assert metadata['validations'] == expected_validation
@pytest.mark.parametrize(
('metadata', 'expected_blinks'),
[
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'** DATE: Wed Mar 8 09:25:20 2023\n'
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'EVENTS GAZE LEFT RATE 1000.00 TRACKING CR FILTER 2\n'
'SBLINK R 10000018\n'
'10000019 . . 0.0 0.0 ...\n'
'10000020 . . 0.0 0.0 ...\n'
'EBLINK R 10000018 10000020 2\n',
[{
'duration_ms': 2,
'num_samples': 2,
'start_timestamp': 10000018,
'stop_timestamp': 10000020,
}],
id='blink',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'EVENTS GAZE LEFT RATE 1000.00 TRACKING CR FILTER 2\n'
'SBLINK R 10000018\n'
'10000019 . . 0.0 0.0 ...\n'
'10000020 . . 0.0 0.0 ...\n'
'EBLINK R 10000018 10000020 2\n'
'SBLINK R 10000021\n'
'10000021 . . 0.0 0.0 ...\n'
'10000022 . . 0.0 0.0 ...\n'
'10000023 . . 0.0 0.0 ...\n'
'10000024 . . 0.0 0.0 ...\n'
'EBLINK R 10000021 10000024 4\n',
[
{
'duration_ms': 2,
'num_samples': 2,
'start_timestamp': 10000018,
'stop_timestamp': 10000020,
},
{
'duration_ms': 4,
'num_samples': 4,
'start_timestamp': 10000021,
'stop_timestamp': 10000024,
},
],
id='multiple_blinks',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'SBLINK R 10000018\n'
'10000019 . . 0.0 0.0 ...\n'
'10000020 . . 0.0 0.0 ...\n'
'EBLINK R 10000018 10000020 2\n',
[{
'duration_ms': 2,
'num_samples': 2,
'start_timestamp': 10000018,
'stop_timestamp': 10000020,
}],
id='blinks_no_sampling_rate',
),
],
)
def test_parse_eyelink_blinks(tmp_path, metadata, expected_blinks):
filepath = tmp_path / 'sub.asc'
filepath.write_text(metadata)
_, parsed_metadata = pm.utils.parsing.parse_eyelink(filepath)
assert parsed_metadata['blinks'] == expected_blinks
@pytest.mark.parametrize(
('metadata', 'expected_blink_ratio', 'expected_overall_ratio'),
[
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'START 10000018 RIGHT SAMPLES EVENTS\n'
'SBLINK R 10000018\n'
'10000019 . . 0.0 0.0 ...\n'
'10000020 . . 0.0 0.0 ...\n'
'EBLINK R 10000018 10000020 2\n'
'END 10000020 SAMPLES EVENTS RES 38.54 31.12\n',
# asc snipped which gets processed by the function
1, # expected_blink_ratio
1, # expected_overall_ratio
id='only_blinks',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'START 10000018 RIGHT SAMPLES EVENTS\n'
'SBLINK R 10000018\n'
'10000019 . . 0.0 0.0 ...\n'
'10000020 . . 0.0 0.0 ...\n'
'EBLINK R 10000018 10000020 2\n'
'END 10000020 SAMPLES EVENTS RES 38.54 31.12\n',
'unknown',
'unknown',
id='unknown_sampling_rate_only_blinks',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'START 10000018 RIGHT SAMPLES EVENTS\n'
'10000019 . . 0.0 0.0 ...\n'
'END 10000019 SAMPLES EVENTS RES 38.54 31.12\n',
0,
1,
id='lost_samples_no_blinks',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'START 10000018 RIGHT SAMPLES EVENTS\n'
'SBLINK R 10000018\n'
'10000019 . . 0.0 0.0 ...\n'
'EBLINK R 10000018 10000019 1\n'
'10000020 . . 0.0 0.0 ...\n'
'END 10000020 SAMPLES EVENTS RES 38.54 31.12\n',
0.5,
1.0,
id='blinks_and_lost_samples',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'START 10000021 RIGHT SAMPLES EVENTS\n'
'10000021 . . 0.0 0.0 ...\n'
'10000022 . . 0.0 0.0 ...\n'
'END 10000022 SAMPLES EVENTS RES 38.54 31.12\n',
'unknown',
'unknown',
id='lost_samples_no_sampling_rate',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'START 10000018 RIGHT SAMPLES EVENTS\n'
'10000019 850.7 717.5 714.0 0.0 ...\n'
'10000020 850.7 717.5 714.0 0.0 ...\n'
'10000022 850.7 717.5 714.0 0.0 ...\n'
'END 10000022 SAMPLES EVENTS RES 38.54 31.12\n',
0,
0.25,
id='missing_timestamps',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'START 10000018 RIGHT SAMPLES EVENTS\n'
'10000019 850.7 717.5 714.0 0.0 ...\n'
'10000020 850.7 717.5 714.0 0.0 ...\n'
'10000022 . . 0.0 0.0 ...\n'
'END 10000022 SAMPLES EVENTS RES 38.54 31.12\n',
0,
0.5,
id='missing_timestamps_lost_samples',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'START 10000020 RIGHT SAMPLES EVENTS\n'
'10000020 850.7 717.5 714.0 0.0 ...\n'
'10000022 . . 0.0 0.0 ...\n'
'SBLINK R 10000023\n'
'10000024 . . 0.0 0.0 ...\n'
'EBLINK R 10000023 10000024 1\n'
'END 10000024 SAMPLES EVENTS RES 38.54 31.12\n',
0.25,
0.75,
id='missing_timestamps_lost_samples4',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'SBLINK R 10000018\n'
'10000019 . . 0.0 0.0 ...\n'
'10000020 . . 0.0 0.0 ...\n'
'EBLINK R 10000018 10000020 2\n'
'10000021 . . 0.0 0.0 ...\n'
'10000022 . . 0.0 0.0 ...\n',
'unknown',
'unknown',
id='blinks_and_lost_samples_no_start_end',
),
pytest.param(
'** DATE: Wed Mar 8 09:25:20 2023\n'
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'START 10000020 RIGHT SAMPLES EVENTS\n'
'END 10000021 SAMPLES EVENTS RES 38.54 31.12\n',
0,
1,
id='missing_timestamps_lost_samples12',
),
],
)
def test_parse_eyelink_data_loss_ratio(
tmp_path, metadata, expected_blink_ratio, expected_overall_ratio,
):
filepath = tmp_path / 'sub.asc'
filepath.write_text(metadata)
_, parsed_metadata = pm.utils.parsing.parse_eyelink(filepath)
assert parsed_metadata['data_loss_ratio_blinks'] == expected_blink_ratio
assert parsed_metadata['data_loss_ratio'] == expected_overall_ratio
def test_parse_eyelink_datetime(tmp_path):
metadata = '** DATE: Wed Mar 8 09:25:20 2023\n'
expected_datetime = datetime.datetime(2023, 3, 8, 9, 25, 20)
filepath = tmp_path / 'sub.asc'
filepath.write_text(metadata)
_, parsed_metadata = pm.utils.parsing.parse_eyelink(filepath)
assert parsed_metadata['datetime'] == expected_datetime
@pytest.mark.parametrize(
('metadata', 'expected_mount_config'),
[
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG BTABLER\n',
{
'mount_type': 'Desktop',
'head_stabilization': 'stabilized',
'eyes_recorded': 'binocular / monocular',
'short_name': 'BTABLER',
},
id='desktop_stabilized_binocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG MTABLER\n',
{
'mount_type': 'Desktop',
'head_stabilization': 'stabilized',
'eyes_recorded': 'monocular',
'short_name': 'MTABLER',
},
id='desktop_stabilized_monocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG RTABLER\n',
{
'mount_type': 'Desktop',
'head_stabilization': 'remote',
'eyes_recorded': 'monocular',
'short_name': 'RTABLER',
},
id='desktop_remote_monocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG RBTABLER\n',
{
'mount_type': 'Desktop',
'head_stabilization': 'remote',
'eyes_recorded': 'binocular / monocular',
'short_name': 'RBTABLER',
},
id='desktop_remote_binocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG AMTABLER\n',
{
'mount_type': 'Arm Mount',
'head_stabilization': 'stabilized',
'eyes_recorded': 'monocular',
'short_name': 'AMTABLER',
},
id='arm_stabilized_monocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG ABTABLER\n',
{
'mount_type': 'Arm Mount',
'head_stabilization': 'stabilized',
'eyes_recorded': 'binocular / monocular',
'short_name': 'ABTABLER',
},
id='arm_stabilized_binocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG ARTABLER\n',
{
'mount_type': 'Arm Mount',
'head_stabilization': 'remote',
'eyes_recorded': 'monocular',
'short_name': 'ARTABLER',
},
id='arm_remote_monocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG ABRTABLE\n',
{
'mount_type': 'Arm Mount',
'head_stabilization': 'remote',
'eyes_recorded': 'binocular / monocular',
'short_name': 'ABRTABLE',
},
id='arm_remote_binocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG BTOWER\n',
{
'mount_type': 'Binocular Tower Mount',
'head_stabilization': 'stabilized',
'eyes_recorded': 'binocular / monocular',
'short_name': 'BTOWER',
},
id='binocular_tower_stabilized_binocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG TOWER\n',
{
'mount_type': 'Tower Mount',
'head_stabilization': 'stabilized',
'eyes_recorded': 'monocular',
'short_name': 'TOWER',
},
id='tower_stabilized_monocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG MPRIM\n',
{
'mount_type': 'Primate Mount',
'head_stabilization': 'stabilized',
'eyes_recorded': 'monocular',
'short_name': 'MPRIM',
},
id='primate_stabilized_binocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG BPRIM\n',
{
'mount_type': 'Primate Mount',
'head_stabilization': 'stabilized',
'eyes_recorded': 'binocular / monocular',
'short_name': 'BPRIM',
},
id='primate_stabilized_monocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG MLRR\n',
{
'mount_type': 'Long-Range Mount',
'head_stabilization': 'stabilized',
'eyes_recorded': 'monocular',
'camera_position': 'level',
'short_name': 'MLRR',
},
id='long_range_level_monocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG BLRR\n',
{
'mount_type': 'Long-Range Mount',
'head_stabilization': 'stabilized',
'eyes_recorded': 'binocular / monocular',
'camera_position': 'angled',
'short_name': 'BLRR',
},
id='long_range_angled_binocular',
),
pytest.param(
'MSG 2154555 RECCFG CR 1000 2 1 L\n'
'MSG 2154555 ELCLCFG XXXXX\n',
{
'mount_type': 'unknown',
'head_stabilization': 'unknown',
'eyes_recorded': 'unknown',
'camera_position': 'unknown',
'short_name': 'XXXXX',
},
id='unknown_mount_config',
),
],
)
def test_parse_eyelink_mount_config(tmp_path, metadata, expected_mount_config):
filepath = tmp_path / 'sub.asc'
filepath.write_text(metadata)
_, parsed_metadata = pm.utils.parsing.parse_eyelink(filepath)
assert parsed_metadata['mount_configuration'] == expected_mount_config