@@ -20,6 +20,11 @@ class TestRecord(unittest.TestCase):
20
20
21
21
"""
22
22
23
+
24
+ wrsamp_params = ['record_name' , 'fs' , 'units' , 'sig_name' , 'p_signal' , 'd_signal' , 'e_p_signal' , 'e_d_signal' ,
25
+ 'samps_per_frame' , 'fmt' , 'adc_gain' , 'baseline' , 'comments' , 'base_time' , 'base_date' ,
26
+ 'base_datetime' ]
27
+
23
28
# ----------------------- 1. Basic Tests -----------------------#
24
29
25
30
def test_1a (self ):
@@ -286,6 +291,112 @@ def test_read_write_flac_multifrequency(self):
286
291
)
287
292
assert record == record_write
288
293
294
+ def test_unique_samps_per_frame_e_p_signal (self ):
295
+ """
296
+ Test writing an e_p_signal with wfdb.io.wrsamp where the signals have different samples per frame. All other
297
+ parameters which overlap between a Record object and wfdb.io.wrsamp are also checked.
298
+ """
299
+ # Read in a record with different samples per frame
300
+ record = wfdb .rdrecord (
301
+ "sample-data/mixedsignals" ,
302
+ smooth_frames = False ,
303
+ )
304
+
305
+ # Write the signals
306
+ wfdb .io .wrsamp ('mixedsignals' , fs = record .fs , units = record .units , sig_name = record .sig_name ,
307
+ base_date = record .base_date , base_time = record .base_time , comments = record .comments ,
308
+ p_signal = record .p_signal , d_signal = record .d_signal , e_p_signal = record .e_p_signal ,
309
+ e_d_signal = record .e_d_signal , samps_per_frame = record .samps_per_frame , baseline = record .baseline ,
310
+ adc_gain = record .adc_gain , fmt = record .fmt , write_dir = self .temp_path )
311
+
312
+ # Check that the written record matches the original
313
+ # Read in the original and written records
314
+ record = wfdb .rdrecord ("sample-data/mixedsignals" , smooth_frames = False )
315
+ record_write = wfdb .rdrecord (
316
+ os .path .join (self .temp_path , "mixedsignals" ),
317
+ smooth_frames = False ,
318
+ )
319
+
320
+ # Check that the signals match
321
+ for n , name in enumerate (record .sig_name ):
322
+ np .testing .assert_array_equal (
323
+ record .e_p_signal [n ], record_write .e_p_signal [n ], f"Mismatch in { name } "
324
+ )
325
+
326
+ # Filter out the signal
327
+ record_filtered = {
328
+ k : getattr (record , k )
329
+ for k in self .wrsamp_params
330
+ if not (isinstance (getattr (record , k ), np .ndarray ) or
331
+ (isinstance (getattr (record , k ), list ) and all (
332
+ isinstance (item , np .ndarray ) for item in getattr (record , k ))))
333
+ }
334
+
335
+ record_write_filtered = {
336
+ k : getattr (record_write , k )
337
+ for k in self .wrsamp_params
338
+ if not (isinstance (getattr (record_write , k ), np .ndarray ) or
339
+ (isinstance (getattr (record_write , k ), list ) and all (
340
+ isinstance (item , np .ndarray ) for item in getattr (record_write , k ))))
341
+ }
342
+
343
+ # Check that the arguments beyond the signals also match
344
+ assert record_filtered == record_write_filtered
345
+
346
+ def test_unique_samps_per_frame_e_d_signal (self ):
347
+ """
348
+ Test writing an e_d_signal with wfdb.io.wrsamp where the signals have different samples per frame. All other
349
+ parameters which overlap between a Record object and wfdb.io.wrsamp are also checked.
350
+ """
351
+ # Read in a record with different samples per frame
352
+ record = wfdb .rdrecord (
353
+ "sample-data/mixedsignals" ,
354
+ physical = False ,
355
+ smooth_frames = False ,
356
+ )
357
+
358
+ # Write the signals
359
+ wfdb .io .wrsamp ('mixedsignals' , fs = record .fs , units = record .units , sig_name = record .sig_name ,
360
+ base_date = record .base_date , base_time = record .base_time , comments = record .comments ,
361
+ p_signal = record .p_signal , d_signal = record .d_signal , e_p_signal = record .e_p_signal ,
362
+ e_d_signal = record .e_d_signal , samps_per_frame = record .samps_per_frame , baseline = record .baseline ,
363
+ adc_gain = record .adc_gain , fmt = record .fmt , write_dir = self .temp_path )
364
+
365
+ # Check that the written record matches the original
366
+ # Read in the original and written records
367
+ record = wfdb .rdrecord ("sample-data/mixedsignals" , physical = False , smooth_frames = False )
368
+ record_write = wfdb .rdrecord (
369
+ os .path .join (self .temp_path , "mixedsignals" ),
370
+ physical = False ,
371
+ smooth_frames = False ,
372
+ )
373
+
374
+ # Check that the signals match
375
+ for n , name in enumerate (record .sig_name ):
376
+ np .testing .assert_array_equal (
377
+ record .e_d_signal [n ], record_write .e_d_signal [n ], f"Mismatch in { name } "
378
+ )
379
+
380
+ # Filter out the signal
381
+ record_filtered = {
382
+ k : getattr (record , k )
383
+ for k in self .wrsamp_params
384
+ if not (isinstance (getattr (record , k ), np .ndarray ) or
385
+ (isinstance (getattr (record , k ), list ) and all (
386
+ isinstance (item , np .ndarray ) for item in getattr (record , k ))))
387
+ }
388
+
389
+ record_write_filtered = {
390
+ k : getattr (record_write , k )
391
+ for k in self .wrsamp_params
392
+ if not (isinstance (getattr (record_write , k ), np .ndarray ) or
393
+ (isinstance (getattr (record_write , k ), list ) and all (
394
+ isinstance (item , np .ndarray ) for item in getattr (record_write , k ))))
395
+ }
396
+
397
+ # Check that the arguments beyond the signals also match
398
+ assert record_filtered == record_write_filtered
399
+
289
400
def test_read_write_flac_many_channels (self ):
290
401
"""
291
402
Check we can read and write to format 516 with more than 8 channels.
0 commit comments