@@ -20,6 +20,25 @@ class TestRecord(unittest.TestCase):
20
20
21
21
"""
22
22
23
+ wrsamp_params = [
24
+ "record_name" ,
25
+ "fs" ,
26
+ "units" ,
27
+ "sig_name" ,
28
+ "p_signal" ,
29
+ "d_signal" ,
30
+ "e_p_signal" ,
31
+ "e_d_signal" ,
32
+ "samps_per_frame" ,
33
+ "fmt" ,
34
+ "adc_gain" ,
35
+ "baseline" ,
36
+ "comments" ,
37
+ "base_time" ,
38
+ "base_date" ,
39
+ "base_datetime" ,
40
+ ]
41
+
23
42
# ----------------------- 1. Basic Tests -----------------------#
24
43
25
44
def test_1a (self ):
@@ -307,6 +326,172 @@ def test_read_write_flac_multifrequency(self):
307
326
)
308
327
assert record == record_write
309
328
329
+ def test_unique_samps_per_frame_e_p_signal (self ):
330
+ """
331
+ Test writing an e_p_signal with wfdb.io.wrsamp where the signals have different samples per frame. All other
332
+ parameters which overlap between a Record object and wfdb.io.wrsamp are also checked.
333
+ """
334
+ # Read in a record with different samples per frame
335
+ record = wfdb .rdrecord (
336
+ "sample-data/mixedsignals" ,
337
+ smooth_frames = False ,
338
+ )
339
+
340
+ # Write the signals
341
+ wfdb .io .wrsamp (
342
+ "mixedsignals" ,
343
+ fs = record .fs ,
344
+ units = record .units ,
345
+ sig_name = record .sig_name ,
346
+ base_date = record .base_date ,
347
+ base_time = record .base_time ,
348
+ comments = record .comments ,
349
+ p_signal = record .p_signal ,
350
+ d_signal = record .d_signal ,
351
+ e_p_signal = record .e_p_signal ,
352
+ e_d_signal = record .e_d_signal ,
353
+ samps_per_frame = record .samps_per_frame ,
354
+ baseline = record .baseline ,
355
+ adc_gain = record .adc_gain ,
356
+ fmt = record .fmt ,
357
+ write_dir = self .temp_path ,
358
+ )
359
+
360
+ # Check that the written record matches the original
361
+ # Read in the original and written records
362
+ record = wfdb .rdrecord ("sample-data/mixedsignals" , smooth_frames = False )
363
+ record_write = wfdb .rdrecord (
364
+ os .path .join (self .temp_path , "mixedsignals" ),
365
+ smooth_frames = False ,
366
+ )
367
+
368
+ # Check that the signals match
369
+ for n , name in enumerate (record .sig_name ):
370
+ np .testing .assert_array_equal (
371
+ record .e_p_signal [n ],
372
+ record_write .e_p_signal [n ],
373
+ f"Mismatch in { name } " ,
374
+ )
375
+
376
+ # Filter out the signal
377
+ record_filtered = {
378
+ k : getattr (record , k )
379
+ for k in self .wrsamp_params
380
+ if not (
381
+ isinstance (getattr (record , k ), np .ndarray )
382
+ or (
383
+ isinstance (getattr (record , k ), list )
384
+ and all (
385
+ isinstance (item , np .ndarray )
386
+ for item in getattr (record , k )
387
+ )
388
+ )
389
+ )
390
+ }
391
+
392
+ record_write_filtered = {
393
+ k : getattr (record_write , k )
394
+ for k in self .wrsamp_params
395
+ if not (
396
+ isinstance (getattr (record_write , k ), np .ndarray )
397
+ or (
398
+ isinstance (getattr (record_write , k ), list )
399
+ and all (
400
+ isinstance (item , np .ndarray )
401
+ for item in getattr (record_write , k )
402
+ )
403
+ )
404
+ )
405
+ }
406
+
407
+ # Check that the arguments beyond the signals also match
408
+ assert record_filtered == record_write_filtered
409
+
410
+ def test_unique_samps_per_frame_e_d_signal (self ):
411
+ """
412
+ Test writing an e_d_signal with wfdb.io.wrsamp where the signals have different samples per frame. All other
413
+ parameters which overlap between a Record object and wfdb.io.wrsamp are also checked.
414
+ """
415
+ # Read in a record with different samples per frame
416
+ record = wfdb .rdrecord (
417
+ "sample-data/mixedsignals" ,
418
+ physical = False ,
419
+ smooth_frames = False ,
420
+ )
421
+
422
+ # Write the signals
423
+ wfdb .io .wrsamp (
424
+ "mixedsignals" ,
425
+ fs = record .fs ,
426
+ units = record .units ,
427
+ sig_name = record .sig_name ,
428
+ base_date = record .base_date ,
429
+ base_time = record .base_time ,
430
+ comments = record .comments ,
431
+ p_signal = record .p_signal ,
432
+ d_signal = record .d_signal ,
433
+ e_p_signal = record .e_p_signal ,
434
+ e_d_signal = record .e_d_signal ,
435
+ samps_per_frame = record .samps_per_frame ,
436
+ baseline = record .baseline ,
437
+ adc_gain = record .adc_gain ,
438
+ fmt = record .fmt ,
439
+ write_dir = self .temp_path ,
440
+ )
441
+
442
+ # Check that the written record matches the original
443
+ # Read in the original and written records
444
+ record = wfdb .rdrecord (
445
+ "sample-data/mixedsignals" , physical = False , smooth_frames = False
446
+ )
447
+ record_write = wfdb .rdrecord (
448
+ os .path .join (self .temp_path , "mixedsignals" ),
449
+ physical = False ,
450
+ smooth_frames = False ,
451
+ )
452
+
453
+ # Check that the signals match
454
+ for n , name in enumerate (record .sig_name ):
455
+ np .testing .assert_array_equal (
456
+ record .e_d_signal [n ],
457
+ record_write .e_d_signal [n ],
458
+ f"Mismatch in { name } " ,
459
+ )
460
+
461
+ # Filter out the signal
462
+ record_filtered = {
463
+ k : getattr (record , k )
464
+ for k in self .wrsamp_params
465
+ if not (
466
+ isinstance (getattr (record , k ), np .ndarray )
467
+ or (
468
+ isinstance (getattr (record , k ), list )
469
+ and all (
470
+ isinstance (item , np .ndarray )
471
+ for item in getattr (record , k )
472
+ )
473
+ )
474
+ )
475
+ }
476
+
477
+ record_write_filtered = {
478
+ k : getattr (record_write , k )
479
+ for k in self .wrsamp_params
480
+ if not (
481
+ isinstance (getattr (record_write , k ), np .ndarray )
482
+ or (
483
+ isinstance (getattr (record_write , k ), list )
484
+ and all (
485
+ isinstance (item , np .ndarray )
486
+ for item in getattr (record_write , k )
487
+ )
488
+ )
489
+ )
490
+ }
491
+
492
+ # Check that the arguments beyond the signals also match
493
+ assert record_filtered == record_write_filtered
494
+
310
495
def test_read_write_flac_many_channels (self ):
311
496
"""
312
497
Check we can read and write to format 516 with more than 8 channels.
0 commit comments