1717
1818@requires_testing_data
1919@pytest .mark .parametrize (
20- "buffer, match, cause_error, interpolate_gaze, crop" ,
20+ "buffer, description_prefix, match, cause_error, interpolate_gaze, crop" ,
2121 [
22- (0.025 , "BAD_blink" , False , False , False ),
23- (0.025 , "BAD_blink" , False , True , True ),
24- ((0.025 , 0.025 ), ["random_annot" ], False , False , False ),
25- (0.025 , "BAD_blink" , True , False , False ),
22+ (0.025 , "BAD_" , "BAD_blink" , False , False , False ),
23+ (0.025 , "BAD_" , "BAD_blink" , False , True , True ),
24+ (0.025 , "BAD_" , "BAD_blink" , True , False , False ),
25+ ((0.025 , 0.025 ), "BAD_" , ["random_annot" ], False , False , False ),
26+ (0.025 , "" , "blink" , False , False , False ),
27+ (0.025 , "" , "blink" , False , True , True ),
28+ (0.025 , "" , "blink" , True , False , False ),
2629 ],
2730)
28- def test_interpolate_blinks (buffer , match , cause_error , interpolate_gaze , crop ):
31+ def test_interpolate_bad_blinks (
32+ description_prefix , buffer , match , cause_error , interpolate_gaze , crop
33+ ):
2934 """Test interpolating pupil data during blinks."""
3035 raw = read_raw_eyelink (fname , create_annotations = ["blinks" ], find_overlaps = True )
36+
37+ # read_raw_eyelink prefixes any blink description with "BAD_" but we want to
38+ # test interpolate_blinks do not depend on this convention
39+ if description_prefix != "BAD_" :
40+ blink_description = f"{ description_prefix } blink"
41+ raw .annotations .rename ({"BAD_blink" : blink_description })
42+ else :
43+ blink_description = "BAD_blink"
44+
45+ # we add a set of events with a description starting as the blink annotations as
46+ # well in case interpolate_blinks picks them up. If so, the test is expected to
47+ # fail.
48+ blinking_light_description = f"{ description_prefix } blinking_light"
49+ # the light switches on every second for 1/10th second.
50+ blinking_lights_onsets = raw .times [:: int (raw .info ["sfreq" ])]
51+ blinking_lights_durations = np .full_like (
52+ blinking_lights_onsets ,
53+ 0.1 ,
54+ )
55+ raw .annotations .append (
56+ blinking_lights_onsets ,
57+ blinking_lights_durations ,
58+ blinking_light_description ,
59+ [raw .ch_names ] * blinking_lights_onsets .size ,
60+ )
61+
3162 if crop :
3263 raw .crop (tmin = 2 )
3364 assert raw .first_time == 2.0
@@ -39,11 +70,9 @@ def test_interpolate_blinks(buffer, match, cause_error, interpolate_gaze, crop):
3970 raw .add_channels ([stim_raw ], force_update_info = True )
4071
4172 # Get the indices of the first blink
42- blink_starts , blink_ends = _annotations_starts_stops (raw , "BAD_blink" )
73+ blink_starts , blink_ends = _annotations_starts_stops (raw , blink_description )
4374 blink_starts = np .divide (blink_starts , raw .info ["sfreq" ])
4475 blink_ends = np .divide (blink_ends , raw .info ["sfreq" ])
45- first_blink_start = blink_starts [0 ]
46- first_blink_end = blink_ends [0 ]
4776 if match == ["random_annot" ]:
4877 msg = "No annotations matching"
4978 with pytest .warns (RuntimeWarning , match = msg ):
@@ -52,7 +81,7 @@ def test_interpolate_blinks(buffer, match, cause_error, interpolate_gaze, crop):
5281
5382 if cause_error :
5483 # Make an annotation without ch_names info
55- raw .annotations .append (onset = 1 , duration = 1 , description = "BAD_blink" )
84+ raw .annotations .append (onset = 1 , duration = 1 , description = blink_description )
5685 with pytest .raises (ValueError ):
5786 interpolate_blinks (raw , buffer = buffer , match = match )
5887 return
@@ -63,11 +92,12 @@ def test_interpolate_blinks(buffer, match, cause_error, interpolate_gaze, crop):
6392
6493 # Now get the data and check that the blinks are interpolated
6594 data , times = raw .get_data (return_times = True )
66- # Get the indices of the first blink
67- blink_ind = np .where ((times >= first_blink_start ) & (times <= first_blink_end ))[0 ]
68- # pupil data during blinks are zero, check that interpolated data are not zeros
69- assert not np .any (data [2 , blink_ind ] == 0 ) # left eye
70- assert not np .any (data [5 , blink_ind ] == 0 ) # right eye
71- if interpolate_gaze :
72- assert not np .isnan (data [0 , blink_ind ]).any () # left eye
73- assert not np .isnan (data [1 , blink_ind ]).any () # right eye
95+ for blink_start , blink_end in zip (blink_starts , blink_ends ):
96+ # Get the indices of the first blink
97+ blink_ind = np .where ((times >= blink_start ) & (times <= blink_end ))[0 ]
98+ # pupil data during blinks are zero, check that interpolated data are not zeros
99+ assert not np .any (data [2 , blink_ind ] == 0 ) # left eye
100+ assert not np .any (data [5 , blink_ind ] == 0 ) # right eye
101+ if interpolate_gaze :
102+ assert not np .isnan (data [0 , blink_ind ]).any () # left eye
103+ assert not np .isnan (data [1 , blink_ind ]).any () # right eye
0 commit comments