Test annotations in the exported EDF file. All annotations should be preserved and onset corrected.
(tmp_path, tmin)
| 306 | @edfio_mark() |
| 307 | @pytest.mark.parametrize("tmin", (0, 0.005, 0.03, 1)) |
| 308 | def test_export_edf_annotations(tmp_path, tmin): |
| 309 | """Test annotations in the exported EDF file. |
| 310 | |
| 311 | All annotations should be preserved and onset corrected. |
| 312 | """ |
| 313 | raw = _create_raw_for_edf_tests() |
| 314 | annotations = Annotations( |
| 315 | onset=[0.01, 0.05, 0.90, 1.05], |
| 316 | duration=[0, 1, 0, 0], |
| 317 | description=["test1", "test2", "test3", "test4"], |
| 318 | ch_names=[["0"], ["0", "1"], [], ["1"]], |
| 319 | ) |
| 320 | raw.set_annotations(annotations) |
| 321 | raw.crop(tmin) |
| 322 | assert raw.first_time == tmin |
| 323 | |
| 324 | if raw.n_times % raw.info["sfreq"] == 0: |
| 325 | expectation = nullcontext() |
| 326 | else: |
| 327 | expectation = pytest.warns( |
| 328 | RuntimeWarning, match="EDF format requires equal-length data blocks" |
| 329 | ) |
| 330 | |
| 331 | # export |
| 332 | temp_fname = tmp_path / "test.edf" |
| 333 | with expectation: |
| 334 | raw.export(temp_fname) |
| 335 | |
| 336 | # read in the file |
| 337 | raw_read = read_raw_edf(temp_fname, preload=True) |
| 338 | assert raw_read.first_time == 0 # exportation resets first_time |
| 339 | bad_annot = raw_read.annotations.description == "BAD_ACQ_SKIP" |
| 340 | if bad_annot.any(): |
| 341 | raw_read.annotations.delete(bad_annot) |
| 342 | valid_annot = ( |
| 343 | raw.annotations.onset >= tmin |
| 344 | ) # only annotations in the cropped range gets exported |
| 345 | |
| 346 | # compare annotations before and after export |
| 347 | assert_array_almost_equal( |
| 348 | raw.annotations.onset[valid_annot] - raw.first_time, raw_read.annotations.onset |
| 349 | ) |
| 350 | assert_array_equal( |
| 351 | raw.annotations.duration[valid_annot], raw_read.annotations.duration |
| 352 | ) |
| 353 | assert_array_equal( |
| 354 | raw.annotations.description[valid_annot], raw_read.annotations.description |
| 355 | ) |
| 356 | assert_array_equal( |
| 357 | raw.annotations.ch_names[valid_annot], raw_read.annotations.ch_names |
| 358 | ) |
| 359 | |
| 360 | |
| 361 | @edfio_mark() |
nothing calls this directly
no test coverage detected